mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-05-26 00:55:16 -07:00
feat: add auto update support (#65)
This commit is contained in:
@@ -15,6 +15,12 @@ export type ShowMessageBox = (options: {
|
||||
cancelId?: number;
|
||||
}) => Promise<MessageBoxResultLike>;
|
||||
|
||||
export interface UpdateDialogPresenterDeps {
|
||||
showMessageBox: ShowMessageBox;
|
||||
focusApp?: () => void;
|
||||
platform?: NodeJS.Platform;
|
||||
}
|
||||
|
||||
export async function showNoUpdateDialog(
|
||||
showMessageBox: ShowMessageBox,
|
||||
version: string,
|
||||
@@ -27,6 +33,27 @@ export async function showNoUpdateDialog(
|
||||
});
|
||||
}
|
||||
|
||||
function maybeFocusAppForDialog(deps: UpdateDialogPresenterDeps): void {
|
||||
if ((deps.platform ?? process.platform) !== 'darwin') return;
|
||||
deps.focusApp?.();
|
||||
}
|
||||
|
||||
export function createUpdateDialogPresenter(deps: UpdateDialogPresenterDeps) {
|
||||
const showFocusedMessageBox: ShowMessageBox = async (options) => {
|
||||
maybeFocusAppForDialog(deps);
|
||||
return deps.showMessageBox(options);
|
||||
};
|
||||
|
||||
return {
|
||||
showNoUpdateDialog: (version: string) => showNoUpdateDialog(showFocusedMessageBox, version),
|
||||
showUpdateAvailableDialog: (version: string) =>
|
||||
showUpdateAvailableDialog(showFocusedMessageBox, version),
|
||||
showUpdateFailedDialog: (message: string) =>
|
||||
showUpdateFailedDialog(showFocusedMessageBox, message),
|
||||
showRestartDialog: () => showRestartDialog(showFocusedMessageBox),
|
||||
};
|
||||
}
|
||||
|
||||
export async function showUpdateAvailableDialog(
|
||||
showMessageBox: ShowMessageBox,
|
||||
version: string,
|
||||
|
||||
Reference in New Issue
Block a user