Skip to content
Merged
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
1 change: 0 additions & 1 deletion apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"prepackage": "bun run copy:native-modules",
"package": "electron-builder --config electron-builder.ts",
"install:deps": "electron-builder install-app-deps",
"make:release": "tsx ./src/lib/electron-app/release/modules/release.ts",
"release": "electron-builder --publish always",
"clean:dev": "rimraf ./node_modules/.dev",
"typecheck": "tsc --noEmit",
Expand Down
88 changes: 81 additions & 7 deletions apps/desktop/src/main/lib/auto-updater.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,65 @@
import { app } from "electron";
import { app, type BrowserWindow, dialog } from "electron";
import { autoUpdater } from "electron-updater";
import { ENVIRONMENT, PLATFORM } from "shared/constants";

const UPDATE_CHECK_INTERVAL_MS = 1000 * 60 * 60 * 1; // 1 hour
const UPDATE_FEED_URL =
"https://github.com/superset-sh/superset/releases/latest/download";

let mainWindow: BrowserWindow | null = null;

export function setMainWindow(window: BrowserWindow): void {
mainWindow = window;
}

export function checkForUpdates(): void {
if (ENVIRONMENT.IS_DEV || !PLATFORM.IS_MAC) {
return;
}
autoUpdater.checkForUpdates().catch((error) => {
console.error("[auto-updater] Failed to check for updates:", error);
});
}

export function checkForUpdatesInteractive(): void {
if (ENVIRONMENT.IS_DEV) {
dialog.showMessageBox({
type: "info",
title: "Updates",
message: "Auto-updates are disabled in development mode.",
});
return;
}
if (!PLATFORM.IS_MAC) {
dialog.showMessageBox({
type: "info",
title: "Updates",
message: "Auto-updates are only available on macOS.",
});
return;
}

autoUpdater
.checkForUpdates()
.then((result) => {
if (!result || !result.updateInfo) {
dialog.showMessageBox({
type: "info",
title: "No Updates",
message: "You are running the latest version.",
});
}
})
.catch((error) => {
console.error("[auto-updater] Failed to check for updates:", error);
dialog.showMessageBox({
type: "error",
title: "Update Error",
message: "Failed to check for updates. Please try again later.",
});
});
}

export function setupAutoUpdater(): void {
if (ENVIRONMENT.IS_DEV || !PLATFORM.IS_MAC) {
return;
Expand Down Expand Up @@ -36,14 +90,34 @@ export function setupAutoUpdater(): void {

autoUpdater.on("update-downloaded", (info) => {
console.info(
`[auto-updater] Update downloaded (${info.version}). Will install on quit.`,
`[auto-updater] Update downloaded (${info.version}). Prompting user to restart.`,
);
});

const checkForUpdates = () =>
autoUpdater.checkForUpdatesAndNotify().catch((error) => {
console.error("[auto-updater] Failed to check for updates:", error);
});
const dialogOptions = {
type: "info" as const,
buttons: ["Restart Now", "Later"],
defaultId: 0,
cancelId: 1,
title: "Update Ready",
message: `Version ${info.version} is ready to install`,
detail:
"A new version has been downloaded. Restart the application to apply the update.",
};

const showDialog = mainWindow
? dialog.showMessageBox(mainWindow, dialogOptions)
: dialog.showMessageBox(dialogOptions);

showDialog
.then((response) => {
if (response.response === 0) {
autoUpdater.quitAndInstall(false, true);
}
})
.catch((error) => {
console.error("[auto-updater] Failed to show update dialog:", error);
});
});

const interval = setInterval(checkForUpdates, UPDATE_CHECK_INTERVAL_MS);
interval.unref();
Expand Down
7 changes: 7 additions & 0 deletions apps/desktop/src/main/lib/menu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { app, type BrowserWindow, Menu } from "electron";
import { checkForUpdatesInteractive } from "./auto-updater";

export function createApplicationMenu(mainWindow: BrowserWindow) {
const template: Electron.MenuItemConstructorOptions[] = [
Expand Down Expand Up @@ -63,6 +64,12 @@ export function createApplicationMenu(mainWindow: BrowserWindow) {
label: app.name,
submenu: [
{ role: "about" },
{
label: "Check for Updates...",
click: () => {
checkForUpdatesInteractive();
},
},
{ type: "separator" },
{ role: "services" },
{ type: "separator" },
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/src/main/windows/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createAppRouter } from "lib/trpc/routers";
import { PORTS } from "shared/constants";
import { createIPCHandler } from "trpc-electron/main";
import { productName } from "~/package.json";
import { setMainWindow } from "../lib/auto-updater";
import { createApplicationMenu } from "../lib/menu";
import {
type AgentCompleteEvent,
Expand Down Expand Up @@ -37,6 +38,9 @@ export async function MainWindow() {
},
});

// Set main window for auto-updater dialogs
setMainWindow(window);

// Create application menu
createApplicationMenu(window);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button } from "@superset/ui/button";
import { Input } from "@superset/ui/input";
import { useRef, useState } from "react";
import { useDrag, useDrop } from "react-dnd";
import { HiMiniXMark } from "react-icons/hi2";
Expand All @@ -7,7 +8,6 @@ import { useWindowsStore } from "renderer/stores/tabs/store";
import type { Window } from "renderer/stores/tabs/types";
import { getWindowDisplayName } from "renderer/stores/tabs/utils";
import { WindowContextMenu } from "./WindowContextMenu";
import { Input } from "@superset/ui/input";

const DRAG_TYPE = "WINDOW";

Expand Down