Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"effect": "catalog:",
"electron": "40.6.0",
"electron": "40.7.0",
"electron-updater": "^6.6.2"
},
"devDependencies": {
Expand Down
90 changes: 75 additions & 15 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
nativeTheme,
protocol,
shell,
MenuItem,
} from "electron";
import type { MenuItemConstructorOptions } from "electron";
import * as Effect from "effect/Effect";
Expand Down Expand Up @@ -277,6 +278,8 @@ let updateCheckInFlight = false;
let updateDownloadInFlight = false;
let updaterConfigured = false;
let updateState: DesktopUpdateState = initialUpdateState();
const updateStateListeners = new Set<(state: DesktopUpdateState) => void>();
updateStateListeners.add(() => emitUpdateState());

function resolveUpdaterErrorContext(): DesktopUpdateErrorContext {
if (updateDownloadInFlight) return "download";
Expand Down Expand Up @@ -559,18 +562,77 @@ async function checkForUpdatesFromMenu(): Promise<void> {
}
}

const CHECK_FOR_UPDATES_MENU_ITEM_LABEL_DEFAULT = "Check for Updates...";
const CHECK_FOR_UPDATES_MENU_ITEM_LABEL_CHECKING = "Checking for Updates...";
const CHECK_FOR_UPDATES_MENU_ITEM_LABEL_IDLE = CHECK_FOR_UPDATES_MENU_ITEM_LABEL_DEFAULT;
const CHECK_FOR_UPDATES_MENU_ITEM_LABEL_DISABLED = "Updates unavailable";
const CHECK_FOR_UPDATES_MENU_ITEM_LABEL_DOWNLOADING = "Downloading update...";
const CHECK_FOR_UPDATES_MENU_ITEM_LABEL_DOWNLOADED = "Update downloaded";
const CHECK_FOR_UPDATES_MENU_ITEM_LABEL_AVAILABLE = "Update available";
const CHECK_FOR_UPDATES_MENU_ITEM_LABEL_UP_TO_DATE = "You're up to date!";
const CHECK_FOR_UPDATES_MENU_ITEM_LABEL_ERROR = "Update check failed";
function makeCheckForUpdatesMenuItem(): MenuItem {
return new MenuItem({
label: CHECK_FOR_UPDATES_MENU_ITEM_LABEL_DEFAULT,
click: async () => await handleCheckForUpdatesMenuClick(),
});
}
const checkForUpdatesMenuItemInAppMenu = makeCheckForUpdatesMenuItem();
const checkForUpdatesMenuItemInHelpMenu = makeCheckForUpdatesMenuItem();

function updateCheckForUpdatesMenuItem(menuItem: MenuItem, state: DesktopUpdateState): void {
switch (state.status) {
case "checking":
menuItem.label = CHECK_FOR_UPDATES_MENU_ITEM_LABEL_CHECKING;
menuItem.enabled = false;
break;
case "available":
menuItem.label = CHECK_FOR_UPDATES_MENU_ITEM_LABEL_AVAILABLE;
menuItem.enabled = false;
break;
case "downloading":
menuItem.label = CHECK_FOR_UPDATES_MENU_ITEM_LABEL_DOWNLOADING;
menuItem.enabled = false;
break;
case "downloaded":
menuItem.label = CHECK_FOR_UPDATES_MENU_ITEM_LABEL_DOWNLOADED;
menuItem.enabled = false;
break;
case "disabled":
menuItem.label = CHECK_FOR_UPDATES_MENU_ITEM_LABEL_DISABLED;
menuItem.enabled = false;
break;
case "error":
menuItem.label = CHECK_FOR_UPDATES_MENU_ITEM_LABEL_ERROR;
menuItem.enabled = false;
break;
case "up-to-date":
menuItem.label = CHECK_FOR_UPDATES_MENU_ITEM_LABEL_UP_TO_DATE;
menuItem.enabled = false;
break;
case "idle":
menuItem.label = CHECK_FOR_UPDATES_MENU_ITEM_LABEL_IDLE;
menuItem.enabled = true;
break;
}
}

updateStateListeners.add((state) => {
updateCheckForUpdatesMenuItem(checkForUpdatesMenuItemInAppMenu, state);
updateCheckForUpdatesMenuItem(checkForUpdatesMenuItemInHelpMenu, state);
});

let applicationMenu: Menu | null = null;

function configureApplicationMenu(): void {
const template: MenuItemConstructorOptions[] = [];
const template: (MenuItemConstructorOptions | MenuItem)[] = [];

if (process.platform === "darwin") {
template.push({
label: app.name,
submenu: [
submenu: Menu.buildFromTemplate([
{ role: "about" },
{
label: "Check for Updates...",
click: () => handleCheckForUpdatesMenuClick(),
},
checkForUpdatesMenuItemInAppMenu,
{ type: "separator" },
{
label: "Settings...",
Expand All @@ -585,7 +647,7 @@ function configureApplicationMenu(): void {
{ role: "unhide" },
{ type: "separator" },
{ role: "quit" },
],
]),
});
}

Expand Down Expand Up @@ -625,16 +687,12 @@ function configureApplicationMenu(): void {
{ role: "windowMenu" },
{
role: "help",
submenu: [
{
label: "Check for Updates...",
click: () => handleCheckForUpdatesMenuClick(),
},
],
submenu: Menu.buildFromTemplate([checkForUpdatesMenuItemInHelpMenu]),
},
);

Menu.setApplicationMenu(Menu.buildFromTemplate(template));
applicationMenu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(applicationMenu);
}

function resolveResourcePath(fileName: string): string | null {
Expand Down Expand Up @@ -727,7 +785,9 @@ function emitUpdateState(): void {

function setUpdateState(patch: Partial<DesktopUpdateState>): void {
updateState = { ...updateState, ...patch };
emitUpdateState();
for (const listener of updateStateListeners) {
listener(updateState);
}
}

function shouldEnableAutoUpdates(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.