mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🐛 多个桌面端快捷方式指定不同的 --workspace 参数后无法启动多个工作空间 https://github.com/siyuan-note/siyuan/issues/7059
This commit is contained in:
parent
f674f249a3
commit
dc34967e88
1 changed files with 59 additions and 33 deletions
|
|
@ -52,10 +52,8 @@ try {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
require('electron').
|
require('electron').dialog.showErrorBox('创建配置目录失败 Failed to create config directory',
|
||||||
dialog.
|
'思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。\n\nSiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.')
|
||||||
showErrorBox('创建配置目录失败 Failed to create config directory',
|
|
||||||
'思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。\n\nSiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.')
|
|
||||||
app.exit()
|
app.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -352,6 +350,20 @@ const boot = () => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const showWindow = (wnd) => {
|
||||||
|
if (!wnd || wnd.isDestroyed()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wnd.isMinimized()) {
|
||||||
|
wnd.restore()
|
||||||
|
}
|
||||||
|
if (!wnd.isVisible()) {
|
||||||
|
wnd.show()
|
||||||
|
}
|
||||||
|
wnd.focus()
|
||||||
|
}
|
||||||
|
|
||||||
const initKernel = (workspace, lang) => {
|
const initKernel = (workspace, lang) => {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
bootWindow = new BrowserWindow({
|
bootWindow = new BrowserWindow({
|
||||||
|
|
@ -428,8 +440,7 @@ const initKernel = (workspace, lang) => {
|
||||||
kernelPort + ']')
|
kernelPort + ']')
|
||||||
|
|
||||||
kernelProcess.on('close', (code) => {
|
kernelProcess.on('close', (code) => {
|
||||||
writeLog(
|
writeLog(`kernel [pid=${kernelProcessPid}] exited with code [${code}]`)
|
||||||
`kernel [pid=${kernelProcessPid}] exited with code [${code}]`)
|
|
||||||
if (0 !== code) {
|
if (0 !== code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 20:
|
case 20:
|
||||||
|
|
@ -454,7 +465,12 @@ const initKernel = (workspace, lang) => {
|
||||||
'⚠️ 无法读写块树文件 Failed to access blocktree file',
|
'⚠️ 无法读写块树文件 Failed to access blocktree file',
|
||||||
`<div>块树文件正在被其他程序锁定或者已经损坏,请删除 工作空间/temp/ 文件夹后重启</div><div>The block tree file is being locked by another program or is corrupted, please delete the workspace/temp/ folder and restart.</div>`)
|
`<div>块树文件正在被其他程序锁定或者已经损坏,请删除 工作空间/temp/ 文件夹后重启</div><div>The block tree file is being locked by another program or is corrupted, please delete the workspace/temp/ folder and restart.</div>`)
|
||||||
break
|
break
|
||||||
case 24:
|
case 24: // 工作空间已被锁定,尝试切换到第一个打开的工作空间
|
||||||
|
if (workspaces && 0 < workspaces.length) {
|
||||||
|
showWindow(workspaces[0].browserWindow)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
showErrorWindow(
|
showErrorWindow(
|
||||||
'⚠️ 工作空间已被锁定 The workspace is locked',
|
'⚠️ 工作空间已被锁定 The workspace is locked',
|
||||||
`<div>该工作空间正在被使用。</div><div>The workspace is in use.</div>`)
|
`<div>该工作空间正在被使用。</div><div>The workspace is in use.</div>`)
|
||||||
|
|
@ -567,7 +583,7 @@ app.whenReady().then(() => {
|
||||||
? lang.hideWindow
|
? lang.hideWindow
|
||||||
: lang.showWindow,
|
: lang.showWindow,
|
||||||
click: () => {
|
click: () => {
|
||||||
showHideWnd(tray, lang, mainWindow)
|
showHideWindow(tray, lang, mainWindow)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -617,7 +633,8 @@ app.whenReady().then(() => {
|
||||||
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
||||||
tray.setContextMenu(contextMenu)
|
tray.setContextMenu(contextMenu)
|
||||||
}
|
}
|
||||||
const showHideWnd = (tray, lang, mainWindow) => {
|
|
||||||
|
const showHideWindow = (tray, lang, mainWindow) => {
|
||||||
if (!mainWindow.isVisible()) {
|
if (!mainWindow.isVisible()) {
|
||||||
if (mainWindow.isMinimized()) {
|
if (mainWindow.isMinimized()) {
|
||||||
mainWindow.restore()
|
mainWindow.restore()
|
||||||
|
|
@ -634,14 +651,7 @@ app.whenReady().then(() => {
|
||||||
app.exit()
|
app.exit()
|
||||||
})
|
})
|
||||||
ipcMain.on('siyuan-show', (event, id) => {
|
ipcMain.on('siyuan-show', (event, id) => {
|
||||||
const mainWindow = BrowserWindow.fromId(id)
|
showWindow(BrowserWindow.fromId(id))
|
||||||
if (mainWindow.isMinimized()) {
|
|
||||||
mainWindow.restore()
|
|
||||||
}
|
|
||||||
if (!mainWindow.isVisible()) {
|
|
||||||
mainWindow.show()
|
|
||||||
}
|
|
||||||
mainWindow.focus()
|
|
||||||
})
|
})
|
||||||
ipcMain.on('siyuan-config-tray', (event, data) => {
|
ipcMain.on('siyuan-config-tray', (event, data) => {
|
||||||
workspaces.find(item => {
|
workspaces.find(item => {
|
||||||
|
|
@ -712,20 +722,13 @@ app.whenReady().then(() => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
ipcMain.on('siyuan-open-workspace', (event, data) => {
|
ipcMain.on('siyuan-open-workspace', (event, data) => {
|
||||||
const exitWorkspace = workspaces.find((item, index) => {
|
const foundWorkspace = workspaces.find((item, index) => {
|
||||||
if (item.workspaceDir === data.workspace) {
|
if (item.workspaceDir === data.workspace) {
|
||||||
const mainWindow = item.browserWindow
|
showWindow(item.browserWindow)
|
||||||
if (mainWindow.isMinimized()) {
|
|
||||||
mainWindow.restore()
|
|
||||||
}
|
|
||||||
if (!mainWindow.isVisible()) {
|
|
||||||
mainWindow.show()
|
|
||||||
}
|
|
||||||
mainWindow.focus()
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (!exitWorkspace) {
|
if (!foundWorkspace) {
|
||||||
initKernel(data.workspace, data.lang).then((isSucc) => {
|
initKernel(data.workspace, data.lang).then((isSucc) => {
|
||||||
if (isSucc) {
|
if (isSucc) {
|
||||||
boot()
|
boot()
|
||||||
|
|
@ -750,7 +753,7 @@ app.whenReady().then(() => {
|
||||||
const mainWindow = BrowserWindow.fromId(data.id)
|
const mainWindow = BrowserWindow.fromId(data.id)
|
||||||
resetTrayMenu(tray, data.languages, mainWindow)
|
resetTrayMenu(tray, data.languages, mainWindow)
|
||||||
tray.on('click', () => {
|
tray.on('click', () => {
|
||||||
showHideWnd(tray, data.languages, mainWindow)
|
showHideWindow(tray, data.languages, mainWindow)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
workspaces.find(item => {
|
workspaces.find(item => {
|
||||||
|
|
@ -843,8 +846,8 @@ app.whenReady().then(() => {
|
||||||
} else {
|
} else {
|
||||||
const getArg = (name) => {
|
const getArg = (name) => {
|
||||||
for (let i = 0; i < process.argv.length; i++) {
|
for (let i = 0; i < process.argv.length; i++) {
|
||||||
if (process.argv[i] === name) {
|
if (process.argv[i].startsWith(name)) {
|
||||||
return process.argv[i + 1]
|
return process.argv[i].split('=')[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -871,13 +874,36 @@ app.on('open-url', (event, url) => { // for macOS
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('second-instance', (event, commandLine) => {
|
app.on('second-instance', (event, argv) => {
|
||||||
|
writeLog('second-instance [' + argv + ']')
|
||||||
|
const siyuanURL = argv.find((arg) => arg.startsWith('siyuan://'))
|
||||||
|
let workspace = argv.find((arg) => arg.startsWith('--workspace='))
|
||||||
|
if (workspace) {
|
||||||
|
workspace = workspace.split('=')[1]
|
||||||
|
writeLog('got second-instance arg [--workspace=' + workspace + ']')
|
||||||
|
}
|
||||||
|
|
||||||
|
let foundWorkspace = false
|
||||||
workspaces.forEach(item => {
|
workspaces.forEach(item => {
|
||||||
if (item.browserWindow && !item.browserWindow.isDestroyed()) {
|
if (item.browserWindow && !item.browserWindow.isDestroyed()) {
|
||||||
item.browserWindow.webContents.send('siyuan-openurl',
|
if (siyuanURL) {
|
||||||
commandLine.find((arg) => arg.startsWith('siyuan://')))
|
item.browserWindow.webContents.send('siyuan-openurl', siyuanURL)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (workspace && workspace === item.workspaceDir) {
|
||||||
|
showWindow(item.browserWindow)
|
||||||
|
foundWorkspace = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if (!foundWorkspace) {
|
||||||
|
initKernel(workspace).then((isSucc) => {
|
||||||
|
if (isSucc) {
|
||||||
|
boot()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue