fix windows

This commit is contained in:
jhyang0 2025-07-07 18:39:24 +09:00
parent d2ca68b177
commit a089a5f98b

View File

@ -57,24 +57,36 @@ function setupProtocolHandling() {
app.on('second-instance', (event, commandLine, workingDirectory) => { app.on('second-instance', (event, commandLine, workingDirectory) => {
console.log('[Protocol] Second instance command line:', commandLine); console.log('[Protocol] Second instance command line:', commandLine);
// Focus existing window first
focusMainWindow(); focusMainWindow();
// Look for protocol URL in command line arguments - filter out invalid paths let protocolUrl = null;
const protocolUrl = commandLine.find(arg => {
return arg && if (process.platform === 'win32') {
typeof arg === 'string' && // Windows
arg.startsWith('pickleglass://') && const lastArg = commandLine.length > 0 ? commandLine[commandLine.length - 1] : null;
arg.includes('://') && if (lastArg &&
!arg.includes('\\') && // Exclude Windows paths typeof lastArg === 'string' &&
!arg.includes('₩'); // Exclude corrupted characters lastArg.startsWith('pickleglass://') &&
}); !lastArg.includes('\\') &&
!lastArg.includes('₩')) {
protocolUrl = lastArg;
}
} else {
// Linux or etc
const lastArg = commandLine.length > 0 ? commandLine[commandLine.length - 1] : null;
if (lastArg &&
typeof lastArg === 'string' &&
lastArg.startsWith('pickleglass://')) {
protocolUrl = lastArg;
}
}
if (protocolUrl) { if (protocolUrl) {
console.log('[Protocol] Valid URL found from second instance:', protocolUrl); console.log('[Protocol] Valid URL found from second instance (last arg):', protocolUrl);
handleCustomUrl(protocolUrl); handleCustomUrl(protocolUrl);
} else { } else {
console.log('[Protocol] No valid protocol URL found in command line arguments'); console.log('[Protocol] No valid protocol URL found in command line arguments');
console.log('[Protocol] Command line args:', commandLine);
} }
}); });
@ -123,18 +135,19 @@ function focusMainWindow() {
} }
if (process.platform === 'win32') { if (process.platform === 'win32') {
const protocolArg = process.argv.find(arg => const lastArg = process.argv.length > 0 ? process.argv[process.argv.length - 1] : null;
arg &&
typeof arg === 'string' &&
arg.startsWith('pickleglass://') &&
!arg.includes('\\') &&
!arg.includes('₩')
);
if (protocolArg) { if (lastArg &&
console.log('[Protocol] Found protocol URL in initial arguments:', protocolArg); typeof lastArg === 'string' &&
pendingDeepLinkUrl = protocolArg; lastArg.startsWith('pickleglass://') &&
!lastArg.includes('\\') &&
!lastArg.includes('₩')) {
console.log('[Protocol] Found protocol URL in initial arguments (last arg):', lastArg);
pendingDeepLinkUrl = lastArg;
} }
console.log('[Protocol] Initial process.argv:', process.argv);
} }
const gotTheLock = app.requestSingleInstanceLock(); const gotTheLock = app.requestSingleInstanceLock();