From 7bdb46e16111dc568d76f3e046d4ecdfbe737df0 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Wed, 8 Nov 2023 16:35:19 +0900 Subject: [PATCH] fix: fixed an issue if "Always on top" is enabled, the dialog is displayed below the window - fix #1379 --- src/index.ts | 10 +++++++++- src/plugins/downloader/back.ts | 7 ++++--- src/plugins/quality-changer/back.ts | 6 +++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5ca5f290..82a7eeaf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -554,7 +554,15 @@ app.on('ready', async () => { message: 'A new version is available', detail: `A new version is available and can be downloaded at ${downloadLink}`, }; - dialog.showMessageBox(dialogOptions).then((dialogOutput) => { + + let dialogPromise: Promise; + if (mainWindow) { + dialogPromise = dialog.showMessageBox(mainWindow, dialogOptions); + } else { + dialogPromise = dialog.showMessageBox(dialogOptions); + } + + dialogPromise.then((dialogOutput) => { switch (dialogOutput.response) { // Download case 1: { diff --git a/src/plugins/downloader/back.ts b/src/plugins/downloader/back.ts index c50bad18..f48372f6 100644 --- a/src/plugins/downloader/back.ts +++ b/src/plugins/downloader/back.ts @@ -68,8 +68,9 @@ const sendError = (error: Error, source?: string) => { const cause = error.cause ? `\n\n${String(error.cause)}` : ''; const message = `${error.toString()}${songNameMessage}${cause}`; - console.error(message, error, error?.stack); - dialog.showMessageBox({ + console.error(message); + console.trace(error); + dialog.showMessageBox(win, { type: 'info', buttons: ['OK'], title: 'Error in download!', @@ -527,7 +528,7 @@ export async function downloadPlaylist(givenUrl?: string | URL) { mkdirSync(playlistFolder, { recursive: true }); } - dialog.showMessageBox({ + dialog.showMessageBox(win, { type: 'info', buttons: ['OK'], title: 'Started Download', diff --git a/src/plugins/quality-changer/back.ts b/src/plugins/quality-changer/back.ts index 957320dd..aa6d0b36 100644 --- a/src/plugins/quality-changer/back.ts +++ b/src/plugins/quality-changer/back.ts @@ -1,7 +1,7 @@ -import { ipcMain, dialog } from 'electron'; +import { ipcMain, dialog, BrowserWindow } from 'electron'; -export default () => { - ipcMain.handle('qualityChanger', async (_, qualityLabels: string[], currentIndex: number) => await dialog.showMessageBox({ +export default (win: BrowserWindow) => { + ipcMain.handle('qualityChanger', async (_, qualityLabels: string[], currentIndex: number) => await dialog.showMessageBox(win, { type: 'question', buttons: qualityLabels, defaultId: currentIndex,