Skip to content

Commit a01d2bd

Browse files
committed
fix: attempt to fix windows sso login. increase logging
Signed-off-by: Adam Setch <[email protected]>
1 parent b66d459 commit a01d2bd

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/main/main.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { menubar } from 'menubar';
44

55
import { APPLICATION } from '../shared/constants';
66
import { namespacedEvent } from '../shared/events';
7-
import { isMacOS, isWindows } from '../shared/platform';
7+
import { logInfo, logWarn } from '../shared/logger';
8+
import { isLinux, isMacOS, isWindows } from '../shared/platform';
89
import { onFirstRunMaybe } from './first-run';
910
import { TrayIcons } from './icons';
1011
import MenuBuilder from './menu';
@@ -90,6 +91,31 @@ app.whenReady().then(async () => {
9091
});
9192
});
9293

94+
/** Prevent second instances */
95+
if (isWindows() || isLinux()) {
96+
const gotTheLock = app.requestSingleInstanceLock();
97+
98+
if (!gotTheLock) {
99+
logWarn('main:gotTheLock', 'Second instance detected, quitting');
100+
app.quit(); // Quit the second instance
101+
return;
102+
}
103+
104+
app.on('second-instance', (_event, commandLine, _workingDirectory) => {
105+
logInfo(
106+
'main:second-instance',
107+
'Second instance was launched. extracting command to forward',
108+
);
109+
110+
// Get the URL from the command line arguments
111+
const url = commandLine.find((arg) => arg.startsWith(`${protocol}://`));
112+
113+
if (url) {
114+
handleURL(url);
115+
}
116+
});
117+
}
118+
93119
/**
94120
* Gitify custom IPC events
95121
*/
@@ -183,5 +209,13 @@ ipc.handle(namespacedEvent('safe-storage-decrypt'), (_, settings) => {
183209
// Handle gitify:// custom protocol URL events for OAuth 2.0 callback
184210
app.on('open-url', (event, url) => {
185211
event.preventDefault();
186-
mb.window.webContents.send(namespacedEvent('auth-callback'), url);
212+
logInfo('main:open-url', `URL received ${url}`);
213+
handleURL(url);
187214
});
215+
216+
const handleURL = (url: string) => {
217+
if (url.startsWith(`${protocol}://`)) {
218+
logInfo('main:handleUrl', `forwarding URL ${url} to renderer process`);
219+
mb.window.webContents.send(namespacedEvent('auth-callback'), url);
220+
}
221+
};

src/renderer/utils/auth/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import semver from 'semver';
44
import { ipcRenderer } from 'electron';
55
import { APPLICATION } from '../../../shared/constants';
66
import { namespacedEvent } from '../../../shared/events';
7-
import { logError, logWarn } from '../../../shared/logger';
7+
import { logError, logInfo, logWarn } from '../../../shared/logger';
88
import type {
99
Account,
1010
AuthCode,
@@ -62,6 +62,10 @@ export function authGitHub(
6262
ipcRenderer.on(
6363
namespacedEvent('auth-callback'),
6464
(_, callbackUrl: string) => {
65+
logInfo(
66+
'renderer:auth-callback',
67+
`received authentication callback URL ${callbackUrl}`,
68+
);
6569
handleCallback(callbackUrl);
6670
},
6771
);

0 commit comments

Comments
 (0)