Skip to content

Commit

Permalink
fix: order formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed May 20, 2023
1 parent bcbc65e commit b535a66
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions app/main/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import {
FullscreenState,
setFullscreenBreakHandler,
} from "./lifecycleEventHandlers/fullScreenBreak";
import WindowsToaster from "node-notifier/notifiers/toaster";
import NotificationCenter from "node-notifier/notifiers/notificationcenter";

const onProduction = app.isPackaged;

Expand Down Expand Up @@ -245,6 +247,32 @@ function createSystemTray() {
});
}

type NotificationProps = {
title: string;
message: string;
actions: string[];
callback?: (err: Error | null, response: string) => void;
};

function notify(props: NotificationProps) {
// This is because it can take different types depending on the initialised OS.
// Just for some reason, whoever sorted the types out fo this library only really considered JS rather than TS.
const notification: WindowsToaster.Notification &
NotificationCenter.Notification = {
icon: notificationIcon,
title: props.title,
message: props.message,
actions: props.actions,
appID: "com.roldanjr.pomatez",
sound: true,
wait: true,
};

notifier.notify(notification, (err, response) => {
if (props.callback) props.callback(err, response);
});
}

if (!onlySingleInstance) {
app.quit();
} else {
Expand Down Expand Up @@ -305,40 +333,30 @@ if (!onlySingleInstance) {

const autoUpdater = activateAutoUpdate({
onUpdateAvailable: (info) => {
notifier.notify(
{
icon: notificationIcon,
title: "NEW UPDATE IS AVAILABLE",
message: `App version ${info.version} ready to be downloaded.`,
actions: ["View Released Notes"],
sound: true,
wait: true,
},
(err, response) => {
notify({
title: "NEW UPDATE IS AVAILABLE",
message: `App version ${info.version} ready to be downloaded.`,
actions: ["View Released Notes"],
callback: (err, response) => {
if (!err) {
shell.openExternal(RELEASED_NOTES_LINK);
}
}
);
},
});
},
onUpdateDownloaded: (info) => {
notifier.notify(
{
icon: notificationIcon,
title: "READY TO BE INSTALLED",
message: "Update has been successfully downloaded.",
actions: ["Quit and Install", "Install it Later"],
sound: true,
wait: true,
},
(err, response) => {
notify({
title: "READY TO BE INSTALLED",
message: "Update has been successfully downloaded.",
actions: ["Quit and Install", "Install it Later"],
callback: (err, response) => {
if (!err) {
if (response === "quit and install") {
autoUpdater.quitAndInstall();
}
}
}
);
},
});
},
});
});
Expand Down

0 comments on commit b535a66

Please sign in to comment.