Skip to content

Commit

Permalink
fix: downloads views
Browse files Browse the repository at this point in the history
  • Loading branch information
duzda committed Nov 15, 2024
1 parent e33a9d5 commit 8d80d21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ if (!gotTheLock) {
loadBounds(mainWindow);
initializeSettings(mainWindow, view);
initializePlayer(view);
initializeDownloads(view);
initializeDownloads(mainView, view);
createHistoryHandles(view);
createKeyboardHandles(view);

Expand Down
26 changes: 19 additions & 7 deletions src/main/downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ const containsWarning = (stdout: string) =>
.split('\n')
.some((l) => warningMessages.some((error) => l.endsWith(error)));

const download = async (url: string, view: WebContentsView) => {
const download = async (url: string, mainView: WebContentsView) => {
try {
const { stdout, stderr } = await exec(`deemix ${url}`);
let execStatus: ExecStatus = 'Success';
if (containsWarning(stdout)) {
execStatus = 'Warning';
}

view.webContents.send(DOWNLOADS_FINISHED, execStatus, url, stdout, stderr);
mainView.webContents.send(
DOWNLOADS_FINISHED,
execStatus,
url,
stdout,
stderr
);
} catch (e) {
const execException = e as ExecException;
view.webContents.send(
mainView.webContents.send(
DOWNLOADS_FINISHED,
'Error',
url,
Expand All @@ -35,12 +41,18 @@ const download = async (url: string, view: WebContentsView) => {
}
};

const createDownloadHandles = (view: WebContentsView) => {
const createDownloadHandles = (
mainView: WebContentsView,
view: WebContentsView
) => {
ipcMain.on(DOWNLOADS_DOWNLOAD, () => {
download(view.webContents.getURL(), view);
download(view.webContents.getURL(), mainView);
});
};

export const initializeDownloads = (view: WebContentsView) => {
createDownloadHandles(view);
export const initializeDownloads = (
mainView: WebContentsView,
view: WebContentsView
) => {
createDownloadHandles(mainView, view);
};

0 comments on commit 8d80d21

Please sign in to comment.