mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-30 04:42:45 +08:00
报错处理
This commit is contained in:
parent
05999db5d2
commit
ebd2ebddae
@ -221,22 +221,22 @@ if (process.platform !== 'linux') quickcommand.runInTerminal = function(cmdline,
|
|||||||
}
|
}
|
||||||
|
|
||||||
let getCommandToLaunchTerminal = (cmdline, dir) => {
|
let getCommandToLaunchTerminal = (cmdline, dir) => {
|
||||||
let cd = ''
|
let cd = ''
|
||||||
if (utools.isWindows()) {
|
if (utools.isWindows()) {
|
||||||
let appPath = path.join(utools.getPath('home'), '/AppData/Local/Microsoft/WindowsApps/')
|
let appPath = path.join(utools.getPath('home'), '/AppData/Local/Microsoft/WindowsApps/')
|
||||||
// 直接 existsSync wt.exe 无效
|
// 直接 existsSync wt.exe 无效
|
||||||
if (fs.existsSync(appPath) && fs.readdirSync(appPath).includes('wt.exe')) {
|
if (fs.existsSync(appPath) && fs.readdirSync(appPath).includes('wt.exe')) {
|
||||||
cmdline = cmdline.replace(/"/g, `\\"`)
|
|
||||||
if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"`
|
|
||||||
command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"`
|
|
||||||
} else {
|
|
||||||
cmdline = cmdline.replace(/"/g, `^"`)
|
|
||||||
if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&`
|
|
||||||
command = `${cd} start "" cmd /k "${cmdline}"`
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cmdline = cmdline.replace(/"/g, `\\"`)
|
cmdline = cmdline.replace(/"/g, `\\"`)
|
||||||
if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&`
|
if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"`
|
||||||
|
command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"`
|
||||||
|
} else {
|
||||||
|
cmdline = cmdline.replace(/"/g, `^"`)
|
||||||
|
if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&`
|
||||||
|
command = `${cd} start "" cmd /k "${cmdline}"`
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmdline = cmdline.replace(/"/g, `\\"`)
|
||||||
|
if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&`
|
||||||
if (fs.existsSync('/Applications/iTerm.app')) {
|
if (fs.existsSync('/Applications/iTerm.app')) {
|
||||||
command = `osascript -e 'tell application "iTerm"
|
command = `osascript -e 'tell application "iTerm"
|
||||||
create window with default profile
|
create window with default profile
|
||||||
@ -527,7 +527,7 @@ window.runCodeInVm = (cmd, callback, userVars = {}) => {
|
|||||||
|
|
||||||
let liteErr = e => {
|
let liteErr = e => {
|
||||||
if (!e) return
|
if (!e) return
|
||||||
return e.stack.replace(/([ ] +at.+)|(.+\.js:\d+)/g, '').trim()
|
return e.error ? e.error.stack.replace(/([ ] +at.+)|(.+\.js:\d+)/g, '').trim() : e.message
|
||||||
}
|
}
|
||||||
|
|
||||||
// 错误处理
|
// 错误处理
|
||||||
@ -541,7 +541,7 @@ window.runCodeInVm = (cmd, callback, userVars = {}) => {
|
|||||||
let cbUnhandledError = e => {
|
let cbUnhandledError = e => {
|
||||||
removeAllListener()
|
removeAllListener()
|
||||||
console.log('UnhandledError: ', e)
|
console.log('UnhandledError: ', e)
|
||||||
callback(null, liteErr(e.error))
|
callback(null, liteErr(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
let cbUnhandledRejection = e => {
|
let cbUnhandledRejection = e => {
|
||||||
@ -662,6 +662,9 @@ window.quickcommandHttpServer = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
httpServer.listen(port, 'localhost');
|
httpServer.listen(port, 'localhost');
|
||||||
|
httpServer.on('error', err => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
let stop = () => {
|
let stop = () => {
|
||||||
httpServer.close()
|
httpServer.close()
|
||||||
|
28
src/App.vue
28
src/App.vue
@ -33,18 +33,7 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 如果配置了后台服务则开启监听
|
this.startUp();
|
||||||
if (this.$profile.quickFeatures.apiServer.serverStatus) {
|
|
||||||
window
|
|
||||||
.quickcommandHttpServer()
|
|
||||||
.run(
|
|
||||||
this.$profile.quickFeatures.apiServer.cmd,
|
|
||||||
this.$profile.quickFeatures.apiServer.port
|
|
||||||
);
|
|
||||||
console.log("Server Start...");
|
|
||||||
}
|
|
||||||
// 默认主题色
|
|
||||||
this.setCssVar("primary", this.$profile.primaryColor);
|
|
||||||
// 进入插件
|
// 进入插件
|
||||||
utools.onPluginEnter((enter) => {
|
utools.onPluginEnter((enter) => {
|
||||||
// 暗黑模式
|
// 暗黑模式
|
||||||
@ -76,6 +65,21 @@ export default defineComponent({
|
|||||||
this.$utools.DBPRE.CFG + "preferences"
|
this.$utools.DBPRE.CFG + "preferences"
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
// 随插件启动执行
|
||||||
|
startUp() {
|
||||||
|
// 如果配置了后台服务则开启监听
|
||||||
|
if (this.$profile.quickFeatures.apiServer.serverStatus) {
|
||||||
|
window
|
||||||
|
.quickcommandHttpServer()
|
||||||
|
.run(
|
||||||
|
this.$profile.quickFeatures.apiServer.cmd,
|
||||||
|
this.$profile.quickFeatures.apiServer.port
|
||||||
|
);
|
||||||
|
console.log("Server Start...");
|
||||||
|
}
|
||||||
|
// 默认主题色
|
||||||
|
this.setCssVar("primary", this.$profile.primaryColor);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user