Skip to content

Commit

Permalink
Bring Window To Front for win32
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovNikita committed Jan 10, 2024
1 parent 3f37991 commit 3013188
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
17 changes: 17 additions & 0 deletions apps/desktop/src/electron/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,21 @@ export abstract class MainWindow {

return this.mainWindow;
}

static async bringToFront() {
if (process.platform === 'win32') {
if (this.mainWindow) {
if (this.mainWindow.isMinimized()) this.mainWindow.restore();
this.mainWindow.focus();
} else {
// Open main windows
await this.openMainWindow();
}
} else {
const window = await this.openMainWindow();
window.show();
}

return this.mainWindow;
}
}
19 changes: 8 additions & 11 deletions apps/desktop/src/electron/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@ export const setProtocolHandlerWindowsLinux = () => {
const gotTheLock = app.requestSingleInstanceLock();

app.on('second-instance', async (e: Electron.Event, argv: string[]) => {
// Someone tried to run a second instance, we should focus our window.
if (MainWindow.mainWindow) {
if (MainWindow.mainWindow.isMinimized()) MainWindow.mainWindow.restore();
MainWindow.mainWindow.focus();
} else {
// Open main windows
await MainWindow.openMainWindow();
}
const window = await MainWindow.bringToFront();

const url = argv.pop();
if (url.startsWith('--')) return;

const url = process.platform === "linux" ? argv.pop() : argv.pop().slice(0, -1);
log.info({ secondInsUrl: url });
app.whenReady().then(() => {
MainWindow.mainWindow.webContents.send('tc', url);
window.webContents.send('tc', url);
});
});

Expand Down Expand Up @@ -74,7 +69,9 @@ const initMainWindow = async () => {
if (process.argv.length == 1) return;
try {
await delay(500);
const url = process.platform === "linux" ? process.argv.pop() : process.argv.pop().slice(0, -1);
const url = process.argv.pop();
if (url.startsWith('--')) return;

log.info({ initUrl: url });

if (url != null) {
Expand Down
3 changes: 1 addition & 2 deletions apps/desktop/src/electron/sseEvetns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ export class TonConnectSSE {

const account = await getAccountState(mainStorage);

const window = await MainWindow.openMainWindow();
window.show();
const window = await MainWindow.bringToFront();

if (account.activePublicKey !== walletPublicKey) {
await accountSelectWallet(mainStorage, walletPublicKey);
Expand Down

0 comments on commit 3013188

Please sign in to comment.