Skip to content

Commit a4b7811

Browse files
authored
LABS-354 Bring Chia Wallet to foreground when Wallet Connect confirmation dialog shows (#2808)
* LABS-354: Focus GUI on wallet connect request * LABS-354: Addressed Windows issue * LABS-354: Added `app.focus()`
1 parent 6740d52 commit a4b7811

5 files changed

Lines changed: 31 additions & 0 deletions

File tree

packages/gui/src/@types/AppService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ type AppService = {
4949
subscribeToMultipleDownloadProgress: (callback: (...args: unknown[]) => void) => () => void;
5050
subscribeToErrorDownloadingUrl: (callback: (...args: unknown[]) => void) => () => void;
5151
subscribeToMultipleDownloadDone: (callback: (...args: unknown[]) => void) => () => void;
52+
53+
// Window operations
54+
focusWindow: () => Promise<void>;
5255
};
5356

5457
export default AppService;

packages/gui/src/electron/constants/AppAPI.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ enum AppAPI {
3737
ON_MULTIPLE_DOWNLOAD_PROGRESS = `${API.APP}:onMultipleDownloadProgress`,
3838
ON_ERROR_DOWNLOADING_URL = `${API.APP}:onErrorDownloadingUrl`,
3939
ON_MULTIPLE_DOWNLOAD_DONE = `${API.APP}:onMultipleDownloadDone`,
40+
41+
FOCUS_WINDOW = `${API.APP}:focusWindow`,
4042
}
4143

4244
export default AppAPI;

packages/gui/src/electron/main.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,26 @@ if (ensureSingleInstance() && ensureCorrectEnvironment()) {
432432
tasks.forEach((task) => task(mainWindow!));
433433
});
434434

435+
ipcMainHandle(AppAPI.FOCUS_WINDOW, () => {
436+
if (mainWindow) {
437+
if (mainWindow.isMinimized()) {
438+
mainWindow.restore();
439+
}
440+
mainWindow.show();
441+
// On macOS, app.focus() brings the entire application to the foreground
442+
if (process.platform === 'darwin') {
443+
app.focus({ steal: true });
444+
}
445+
mainWindow.focus();
446+
// On Windows, focus() alone may not bring window to foreground due to OS restrictions.
447+
// Using setAlwaysOnTop temporarily ensures the window comes to front.
448+
if (process.platform === 'win32') {
449+
mainWindow.setAlwaysOnTop(true);
450+
mainWindow.setAlwaysOnTop(false);
451+
}
452+
}
453+
});
454+
435455
decidedToClose = false;
436456
const mainWindowState = windowStateKeeper({
437457
defaultWidth: 1200,

packages/gui/src/electron/preload.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ contextBridge.exposeInMainWorld(API.APP, {
6666
onIpcEvent(AppAPI.ON_ERROR_DOWNLOADING_URL, callback),
6767
subscribeToMultipleDownloadDone: (callback: (...args: unknown[]) => void) =>
6868
onIpcEvent(AppAPI.ON_MULTIPLE_DOWNLOAD_DONE, callback),
69+
70+
focusWindow: () => invokeWithCustomErrors(AppAPI.FOCUS_WINDOW),
6971
});
7072

7173
contextBridge.exposeInMainWorld(API.PREFERENCES, {

packages/gui/src/hooks/useWalletConnectCommand.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export default function useWalletConnectCommand(options: UseWalletConnectCommand
122122
if (hasPermissions) {
123123
return true;
124124
}
125+
// Bring the window to foreground when showing approval dialog
126+
await window.appAPI.focusWindow();
125127
const isConfirmed = await openDialog(
126128
<WalletConnectRequestPermissionsConfirmDialog
127129
topic={topic}
@@ -135,6 +137,8 @@ export default function useWalletConnectCommand(options: UseWalletConnectCommand
135137
return isConfirmed;
136138
}
137139

140+
// Bring the window to foreground when showing approval dialog
141+
await window.appAPI.focusWindow();
138142
const isConfirmed = await openDialog(
139143
<WalletConnectConfirmDialog
140144
topic={topic}

0 commit comments

Comments
 (0)