Skip to content

Commit 4fcb982

Browse files
committed
修复:Windows 自定义协议不生效问题
1 parent 0a3adc2 commit 4fcb982

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

electron/main/index.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {app, BrowserWindow, desktopCapturer, session, shell, protocol} from 'electron'
22
import {optimizer} from '@electron-toolkit/utils'
3+
import fs from 'node:fs'
34

45
/** process.js 必须位于非依赖项的顶部 */
56
import {isDummy} from "../lib/process";
@@ -33,6 +34,13 @@ if (process.env['ELECTRON_ENV_PROD']) {
3334
DevToolsManager.setEnable(false)
3435
}
3536

37+
const logDebugContent = (label: string, content: any) => {
38+
const filePath = AppEnv.userData + '/debug.log'
39+
const msg = label + " - " + JSON.stringify(content)
40+
console.log(msg)
41+
fs.appendFileSync(filePath, msg + '\n')
42+
}
43+
3644
process.on('uncaughtException', (reason) => {
3745
let error: any = reason
3846
if (error instanceof Error) {
@@ -156,8 +164,9 @@ async function createWindow() {
156164
FastPanelMain.init()
157165
}
158166

159-
const handleArgsForOpenFile = (argv: string[]) => {
167+
const handleArgsForApp = (argv: string[]) => {
160168
let filePath = null
169+
let url = null
161170
for (let i = 1; i < argv.length; i++) {
162171
const arg = argv[i]
163172
if (arg.startsWith('--')) {
@@ -166,12 +175,19 @@ const handleArgsForOpenFile = (argv: string[]) => {
166175
if (['.'].includes(arg)) {
167176
continue
168177
}
178+
if (arg.startsWith('focusany://')) {
179+
url = arg
180+
continue
181+
}
169182
filePath = arg
170183
break
171184
}
172185
if (filePath) {
173186
ManagerEditor.openQueue(filePath).then()
174187
}
188+
if (url) {
189+
ProtocolMain.queue(url).then()
190+
}
175191
}
176192

177193
app.on('open-file', (event, path) => {
@@ -208,7 +224,7 @@ app.whenReady()
208224
optimizer.watchWindowShortcuts(window)
209225
})
210226
createWindow().then()
211-
handleArgsForOpenFile(process.argv)
227+
handleArgsForApp(process.argv)
212228
})
213229

214230
app.on('before-quit', (event) => {
@@ -233,7 +249,7 @@ app.on('second-instance', (event, argv) => {
233249
AppRuntime.mainWindow.show()
234250
AppRuntime.mainWindow.focus()
235251
}
236-
handleArgsForOpenFile(argv)
252+
handleArgsForApp(argv)
237253
})
238254

239255
app.on('activate', () => {

0 commit comments

Comments
 (0)