optimize: 优化 getSystemPlatform 方法
parent
81c1433820
commit
13741d3b15
|
@ -93,20 +93,19 @@ function childExec (composeCmds, options = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSystemShell () {
|
function getSystemShell () {
|
||||||
switch (getSystemPlatform()) {
|
switch (getSystemPlatform(true)) {
|
||||||
case 'mac':
|
case 'mac':
|
||||||
return DarwinSystemShell
|
return DarwinSystemShell
|
||||||
case 'linux':
|
case 'linux':
|
||||||
return LinuxSystemShell
|
return LinuxSystemShell
|
||||||
case 'windows':
|
case 'windows':
|
||||||
return WindowsSystemShell
|
return WindowsSystemShell
|
||||||
case 'unknown os':
|
|
||||||
default:
|
default:
|
||||||
throw new Error(`UNKNOWN OS TYPE ${os.platform()}`)
|
throw new Error(`UNKNOWN OS TYPE ${os.platform()}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSystemPlatform () {
|
function getSystemPlatform (throwIfUnknown = false) {
|
||||||
switch (os.platform()) {
|
switch (os.platform()) {
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return 'mac'
|
return 'mac'
|
||||||
|
@ -116,14 +115,18 @@ function getSystemPlatform () {
|
||||||
return 'windows'
|
return 'windows'
|
||||||
case 'win64':
|
case 'win64':
|
||||||
return 'windows'
|
return 'windows'
|
||||||
case 'unknown os':
|
|
||||||
default:
|
default:
|
||||||
throw new Error(`UNKNOWN OS TYPE ${os.platform()}`)
|
log.error(`UNKNOWN OS TYPE: ${os.platform()}`)
|
||||||
|
if (throwIfUnknown) {
|
||||||
|
throw new Error(`UNKNOWN OS TYPE '${os.platform()}'`)
|
||||||
|
} else {
|
||||||
|
return 'unknown-os'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execute (executor, args) {
|
async function execute (executor, args) {
|
||||||
return executor[getSystemPlatform()](getSystemShell().exec, args)
|
return executor[getSystemPlatform(true)](getSystemShell().exec, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execFile (file, args, options) {
|
async function execFile (file, args, options) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ const getDateTimeStr = function () {
|
||||||
const localApi = {
|
const localApi = {
|
||||||
/**
|
/**
|
||||||
* 返回所有api列表,供vue来ipc调用
|
* 返回所有api列表,供vue来ipc调用
|
||||||
* @returns {[]}
|
* @returns {[]} api列表
|
||||||
*/
|
*/
|
||||||
getApiList () {
|
getApiList () {
|
||||||
const core = lodash.cloneDeep(DevSidecar.api)
|
const core = lodash.cloneDeep(DevSidecar.api)
|
||||||
|
@ -50,8 +50,8 @@ const localApi = {
|
||||||
getConfigDir () {
|
getConfigDir () {
|
||||||
return getDefaultConfigBasePath()
|
return getDefaultConfigBasePath()
|
||||||
},
|
},
|
||||||
getSystemPlatform () {
|
getSystemPlatform (throwIfUnknown = false) {
|
||||||
return DevSidecar.api.shell.getSystemPlatform()
|
return DevSidecar.api.shell.getSystemPlatform(throwIfUnknown)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,9 +26,7 @@ EOF
|
||||||
}
|
}
|
||||||
export default {
|
export default {
|
||||||
install (context) {
|
install (context) {
|
||||||
const { ipcMain, dialog, log, app } = context
|
const { ipcMain, app } = context
|
||||||
|
|
||||||
const ex = app.getPath('exe')
|
|
||||||
|
|
||||||
// 定义事件,渲染进程中直接使用
|
// 定义事件,渲染进程中直接使用
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import os from 'node:os'
|
import os from 'node:os'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
|
import log from './util.log'
|
||||||
|
|
||||||
function getSystemPlatform () {
|
function getSystemPlatform (throwIfUnknown = false) {
|
||||||
switch (os.platform()) {
|
switch (os.platform()) {
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return 'mac'
|
return 'mac'
|
||||||
|
@ -11,11 +12,16 @@ function getSystemPlatform () {
|
||||||
return 'windows'
|
return 'windows'
|
||||||
case 'win64':
|
case 'win64':
|
||||||
return 'windows'
|
return 'windows'
|
||||||
case 'unknown os':
|
|
||||||
default:
|
default:
|
||||||
|
log.error(`UNKNOWN OS TYPE: ${os.platform()}`)
|
||||||
|
if (throwIfUnknown) {
|
||||||
throw new Error(`UNKNOWN OS TYPE ${os.platform()}`)
|
throw new Error(`UNKNOWN OS TYPE ${os.platform()}`)
|
||||||
|
} else {
|
||||||
|
return 'unknown-os'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getAppRootPath (app) {
|
getAppRootPath (app) {
|
||||||
const exePath = app.getPath('exe')
|
const exePath = app.getPath('exe')
|
||||||
|
|
|
@ -30,8 +30,7 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
async created () {
|
async created () {
|
||||||
const platform = await this.$api.info.getSystemPlatform()
|
this.systemPlatform = await this.$api.info.getSystemPlatform()
|
||||||
this.systemPlatform = platform
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async openExternal (url) {
|
async openExternal (url) {
|
||||||
|
|
Loading…
Reference in New Issue