mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
🎨 桌面端快捷方式支持 --port 启动参数 https://github.com/siyuan-note/siyuan/issues/7092
This commit is contained in:
parent
67743b50ba
commit
0ac545e867
1 changed files with 39 additions and 21 deletions
|
|
@ -364,7 +364,7 @@ const showWindow = (wnd) => {
|
||||||
wnd.focus()
|
wnd.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
const initKernel = (workspace, lang) => {
|
const initKernel = (workspace, port, lang) => {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
bootWindow = new BrowserWindow({
|
bootWindow = new BrowserWindow({
|
||||||
width: screen.getPrimaryDisplay().size.width / 2,
|
width: screen.getPrimaryDisplay().size.width / 2,
|
||||||
|
|
@ -390,6 +390,9 @@ const initKernel = (workspace, lang) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isDevEnv || workspaces.length > 0) {
|
if (!isDevEnv || workspaces.length > 0) {
|
||||||
|
if (port && "" !== port) {
|
||||||
|
kernelPort = port
|
||||||
|
} else {
|
||||||
const getAvailablePort = () => {
|
const getAvailablePort = () => {
|
||||||
// https://gist.github.com/mikeal/1840641
|
// https://gist.github.com/mikeal/1840641
|
||||||
return new Promise((portResolve, portReject) => {
|
return new Promise((portResolve, portReject) => {
|
||||||
|
|
@ -407,6 +410,7 @@ const initKernel = (workspace, lang) => {
|
||||||
}
|
}
|
||||||
await getAvailablePort()
|
await getAvailablePort()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
writeLog('got kernel port [' + kernelPort + ']')
|
writeLog('got kernel port [' + kernelPort + ']')
|
||||||
if (!kernelPort) {
|
if (!kernelPort) {
|
||||||
bootWindow.destroy()
|
bootWindow.destroy()
|
||||||
|
|
@ -417,10 +421,13 @@ const initKernel = (workspace, lang) => {
|
||||||
if (isDevEnv && workspaces.length === 0) {
|
if (isDevEnv && workspaces.length === 0) {
|
||||||
cmds.push('--mode', 'dev')
|
cmds.push('--mode', 'dev')
|
||||||
}
|
}
|
||||||
if (workspace) {
|
if (workspace && "" !== workspace) {
|
||||||
cmds.push('--workspace', workspace)
|
cmds.push('--workspace', workspace)
|
||||||
}
|
}
|
||||||
if (lang) {
|
if (port && "" !== port) {
|
||||||
|
cmds.push('--port', port)
|
||||||
|
}
|
||||||
|
if (lang && "" !== lang) {
|
||||||
cmds.push('--lang', lang)
|
cmds.push('--lang', lang)
|
||||||
}
|
}
|
||||||
let cmd = `ui version [${appVer}], booting kernel [${kernelPath} ${cmds.join(
|
let cmd = `ui version [${appVer}], booting kernel [${kernelPath} ${cmds.join(
|
||||||
|
|
@ -728,7 +735,7 @@ app.whenReady().then(() => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (!foundWorkspace) {
|
if (!foundWorkspace) {
|
||||||
initKernel(data.workspace, data.lang).then((isSucc) => {
|
initKernel(data.workspace, "", data.lang).then((isSucc) => {
|
||||||
if (isSucc) {
|
if (isSucc) {
|
||||||
boot()
|
boot()
|
||||||
}
|
}
|
||||||
|
|
@ -835,7 +842,7 @@ app.whenReady().then(() => {
|
||||||
firstOpenWindow.show()
|
firstOpenWindow.show()
|
||||||
// 初始化启动
|
// 初始化启动
|
||||||
ipcMain.on('siyuan-first-init', (event, data) => {
|
ipcMain.on('siyuan-first-init', (event, data) => {
|
||||||
initKernel(data.workspace, data.lang).then((isSucc) => {
|
initKernel(data.workspace, "", data.lang).then((isSucc) => {
|
||||||
if (isSucc) {
|
if (isSucc) {
|
||||||
boot()
|
boot()
|
||||||
}
|
}
|
||||||
|
|
@ -855,7 +862,11 @@ app.whenReady().then(() => {
|
||||||
if (workspace) {
|
if (workspace) {
|
||||||
writeLog('got arg [--workspace=' + workspace + ']')
|
writeLog('got arg [--workspace=' + workspace + ']')
|
||||||
}
|
}
|
||||||
initKernel(workspace).then((isSucc) => {
|
const port = getArg('--port')
|
||||||
|
if (port) {
|
||||||
|
writeLog('got arg [--port=' + port + ']')
|
||||||
|
}
|
||||||
|
initKernel(workspace, port, "").then((isSucc) => {
|
||||||
if (isSucc) {
|
if (isSucc) {
|
||||||
boot()
|
boot()
|
||||||
}
|
}
|
||||||
|
|
@ -880,6 +891,13 @@ app.on('second-instance', (event, argv) => {
|
||||||
workspace = workspace.split('=')[1]
|
workspace = workspace.split('=')[1]
|
||||||
writeLog('got second-instance arg [--workspace=' + workspace + ']')
|
writeLog('got second-instance arg [--workspace=' + workspace + ']')
|
||||||
}
|
}
|
||||||
|
let port = argv.find((arg) => arg.startsWith('--port='))
|
||||||
|
if (port) {
|
||||||
|
port = port.split('=')[1]
|
||||||
|
writeLog('got second-instance arg [--port=' + port + ']')
|
||||||
|
} else {
|
||||||
|
port = 0
|
||||||
|
}
|
||||||
const foundWorkspace = workspaces.find(item => {
|
const foundWorkspace = workspaces.find(item => {
|
||||||
if (item.browserWindow && !item.browserWindow.isDestroyed()) {
|
if (item.browserWindow && !item.browserWindow.isDestroyed()) {
|
||||||
if (workspace && workspace === item.workspaceDir) {
|
if (workspace && workspace === item.workspaceDir) {
|
||||||
|
|
@ -892,7 +910,7 @@ app.on('second-instance', (event, argv) => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (workspace) {
|
if (workspace) {
|
||||||
initKernel(workspace).then((isSucc) => {
|
initKernel(workspace, port, "").then((isSucc) => {
|
||||||
if (isSucc) {
|
if (isSucc) {
|
||||||
boot()
|
boot()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue