Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/main/ipc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { setLocale } from '../util/i18n';
import { localSource } from '../util/localFile';
import { getStorageInfo, systemOpen } from '../util/system';
import { exportSnippet } from '../util/snippetExport';
import { focusSenderWindow } from '../windows';

export const WORKSPACE_CHANGED_CHANNEL = 'workspace:changed';

Expand Down Expand Up @@ -106,9 +107,11 @@ export function registerIpc(
services.dataset.test(sourceConfig, authSessionId),
);

ipcMain.handle('githubConnect', (_event, connectionId: unknown) =>
services.dataset.connectGitHub(githubConnectionIdSchema.parse(connectionId)),
);
ipcMain.handle('githubConnect', async (event, connectionId: unknown) => {
const result = await services.dataset.connectGitHub(githubConnectionIdSchema.parse(connectionId));
focusSenderWindow(event.sender);
return result;
});

ipcMain.handle('githubConnectCancel', (_event, connectionId: unknown) =>
services.dataset.cancelGitHubConnect(githubConnectionIdSchema.parse(connectionId)),
Expand All @@ -120,10 +123,7 @@ export function registerIpc(

ipcMain.handle('oAuthStart', async (event, type: DataSourceConfig['type']) => {
const result = await services.dataset.oAuthStart(type);
if (process.platform === 'darwin') app.focus({ steal: true });
const window = BrowserWindow.fromWebContents(event.sender);
window?.show();
window?.focus();
focusSenderWindow(event.sender);
return result;
});

Expand Down
12 changes: 11 additions & 1 deletion src/main/windows.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path';
import { BrowserWindow } from 'electron';
import { app, BrowserWindow } from 'electron';
import type { BrowserWindowConstructorOptions, WebContents } from 'electron';

type AppWindow = 'workspace' | 'settings';
Expand Down Expand Up @@ -63,6 +63,16 @@ export function closeAppWindow(kind: AppWindow, sender: WebContents) {
if (window?.webContents.id === sender.id) window.close();
}

export function focusSenderWindow(sender: WebContents) {
if (sender.isDestroyed()) return;
const window = BrowserWindow.fromWebContents(sender);
if (!window || window.isDestroyed()) return;
if (process.platform === 'darwin') app.focus({ steal: true });
if (window.isMinimized()) window.restore();
window.show();
window.focus();
}

function loadRenderer(window: BrowserWindow, hash?: string) {
if (process.env.ELECTRON_RENDERER_URL) {
const url = new URL(process.env.ELECTRON_RENDERER_URL);
Expand Down
Loading