|
|
@@ -101,6 +101,12 @@ else {
|
|
|
|
|
|
function show() {
|
|
|
if (closing || quitting) return
|
|
|
+ if (preferences.value.hostOnly) {
|
|
|
+ if (window && !window.isDestroyed()) { window.show(); window.focus(); return }
|
|
|
+ void dialog.showMessageBox({ type: 'info', title: '夭夭', message: '仅桌面主机模式',
|
|
|
+ detail: '这台 Mac 正在作为远程桌面主机运行,本机 Web 服务未启动。如需使用本机服务,请打开菜单「桌面主机」,取消勾选「仅作为桌面主机运行」。' })
|
|
|
+ return
|
|
|
+ }
|
|
|
if (!window || window.isDestroyed()) createWindow()
|
|
|
window.show(); window.focus()
|
|
|
if (manager) void manager.reconnect().then(() => stateChanged(manager.state)).catch(error => log(error.message))
|
|
|
@@ -260,6 +266,26 @@ else {
|
|
|
const selection=await dialog.showOpenDialog(window,{title:'导入桌面主机配置',properties:['openFile'],filters:[{name:'桌面主机配置',extensions:['json']}]})
|
|
|
if(!selection.canceled&&selection.filePaths[0]&&!closing)await hostAction(()=>hostManager.importFile(selection.filePaths[0]))
|
|
|
}
|
|
|
+ async function toggleHostOnly(item){
|
|
|
+ const enabled=item.checked
|
|
|
+ try{
|
|
|
+ await preferences.setHostOnly(enabled)
|
|
|
+ if(enabled){
|
|
|
+ await environmentHost?.close().catch(error=>log(error.message))
|
|
|
+ await runnerManager?.stop().catch(error=>log(error.message))
|
|
|
+ await manager?.stop().catch(error=>log(error.message))
|
|
|
+ if(window&&!window.isDestroyed())window.hide()
|
|
|
+ await dialog.showMessageBox({type:'info',title:'夭夭',message:'已切换到仅桌面主机模式',detail:'本机 Web 服务已停止,这台 Mac 将只通过「桌面主机」连接远程夭夭服务器。需要本机服务时,请取消勾选。'})
|
|
|
+ }else{
|
|
|
+ await manager?.start().catch(error=>log(error.message))
|
|
|
+ if(!closing)environmentHost?.start()
|
|
|
+ await dialog.showMessageBox({type:'info',title:'夭夭',message:'已恢复本机 Web 服务',detail:'本机夭夭服务正在启动,稍后点按「显示窗口」即可使用。'})
|
|
|
+ }
|
|
|
+ }catch(error){
|
|
|
+ item.checked=preferences.value.hostOnly
|
|
|
+ await dialog.showMessageBox(window,{type:'error',message:'无法切换仅桌面主机模式',detail:error.message})
|
|
|
+ }
|
|
|
+ }
|
|
|
async function importRunner(){
|
|
|
const selection=await dialog.showOpenDialog(window,{title:'导入执行节点配置',properties:['openFile'],filters:[{name:'Runner 配置',extensions:['json']}]})
|
|
|
if(!selection.canceled&&selection.filePaths[0]&&!closing)await runnerAction(()=>runnerManager.importFile(selection.filePaths[0]))
|
|
|
@@ -294,7 +320,9 @@ else {
|
|
|
{label:'桌面主机',submenu:[{id:'desktop-host-status',label:'未配置桌面主机',enabled:false},{type:'separator'},
|
|
|
{id:'desktop-host-import',label:'导入主机配置…',click:importDesktopHost},
|
|
|
{id:'desktop-host-reconnect',label:'重新连接',click:()=>hostAction(()=>hostManager.start())},
|
|
|
- {id:'desktop-host-forget',label:'断开并忘记配置',click:()=>hostAction(()=>hostManager.forget())}]},
|
|
|
+ {id:'desktop-host-forget',label:'断开并忘记配置',click:()=>hostAction(()=>hostManager.forget())},{type:'separator'},
|
|
|
+ {id:'desktop-host-only',label:'仅作为桌面主机运行',type:'checkbox',checked:preferences.value.hostOnly,
|
|
|
+ toolTip:'不启动本机 Web 服务,只连接远程夭夭服务器',click:toggleHostOnly}]},
|
|
|
{ role: 'editMenu', label: '编辑' }, { role: 'viewMenu', label: '显示' }, { role: 'windowMenu', label: '窗口' },
|
|
|
]))
|
|
|
const icon = nativeImage.createFromPath(join(desktopRoot, 'icon.png')).resize({ width: 20, height: 20 })
|
|
|
@@ -303,12 +331,16 @@ else {
|
|
|
tray.setToolTip('夭夭')
|
|
|
tray.setContextMenu(Menu.buildFromTemplate([{ label: '打开夭夭', click: show }, { label: '查看日志', click: () => shell.showItemInFolder(logFile) }, { type: 'separator' }, { label: '退出夭夭(后台继续运行)', click: () => requestQuit() }, { label: '停止后台服务并退出', click: () => requestQuit(true) }]))
|
|
|
tray.on('click', show)
|
|
|
- createWindow()
|
|
|
+ if(!preferences.value.hostOnly)createWindow()
|
|
|
powerMonitor.on('resume', () => { if(!closing&&!quitting)void manager.check() })
|
|
|
timer = setInterval(() => { void manager.check() }, 10_000); timer.unref()
|
|
|
- await manager.start().catch(error => log(error.message))
|
|
|
- if(!closing)environmentHost.start()
|
|
|
+ if(preferences.value.hostOnly){
|
|
|
+ log('仅桌面主机模式:不启动本机 Web 服务')
|
|
|
+ }else{
|
|
|
+ await manager.start().catch(error => log(error.message))
|
|
|
+ if(!closing)environmentHost.start()
|
|
|
+ }
|
|
|
if(!closing)hostManager.start().catch(error=>{hostManager.publish(error.message)})
|
|
|
- if(!closing&&manager.state.phase==='ready')await runnerManager.start().catch(error=>{runnerManager.publish(error.message)})
|
|
|
+ if(!closing&&!preferences.value.hostOnly&&manager.state.phase==='ready')await runnerManager.start().catch(error=>{runnerManager.publish(error.message)})
|
|
|
}).catch(error => { log(error.stack || error.message); quitting = true; app.quit() })
|
|
|
}
|