Skip to content
Closed
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
18 changes: 18 additions & 0 deletions packages/app/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,8 @@ export default function App() {
setPendingUpdate,
updateEnv,
setUpdateEnv,
updateChannel,
setUpdateChannel,
checkForUpdates,
downloadUpdate,
installUpdateAndRestart,
Expand Down Expand Up @@ -3340,6 +3342,11 @@ export default function App() {
}
}

const storedUpdateChannel = window.localStorage.getItem("openwork.updateChannel");
if (storedUpdateChannel === "stable" || storedUpdateChannel === "prerelease") {
setUpdateChannel(storedUpdateChannel);
}

const storedNotionStatus = window.localStorage.getItem("openwork.notionStatus");
if (
storedNotionStatus === "disconnected" ||
Expand Down Expand Up @@ -3655,6 +3662,15 @@ export default function App() {
}
});

createEffect(() => {
if (typeof window === "undefined") return;
try {
window.localStorage.setItem("openwork.updateChannel", updateChannel());
} catch {
// ignore
}
});

createEffect(() => {
if (typeof window === "undefined") return;
try {
Expand Down Expand Up @@ -4059,6 +4075,8 @@ export default function App() {
checkForUpdates: () => checkForUpdates(),
downloadUpdate: () => downloadUpdate(),
installUpdateAndRestart,
updateChannel: updateChannel(),
setUpdateChannel,
anyActiveRuns: anyActiveRuns(),
engineSource: engineSource(),
setEngineSource,
Expand Down
9 changes: 7 additions & 2 deletions packages/app/src/app/context/updater.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSignal } from "solid-js";

import type { UpdateHandle } from "../types";
import type { UpdaterEnvironment } from "../lib/tauri";
import type { UpdateChannel, UpdaterEnvironment } from "../lib/tauri";

export type UpdateStatus =
| { state: "idle"; lastCheckedAt: number | null }
Expand All @@ -16,15 +16,18 @@ export type UpdateStatus =
notes?: string;
}
| { state: "ready"; lastCheckedAt: number; version: string; notes?: string }
| { state: "applying"; lastCheckedAt: number; version: string; notes?: string }
| { state: "restart-required"; lastCheckedAt: number; version: string; notes?: string }
| { state: "error"; lastCheckedAt: number | null; message: string };

export type PendingUpdate = { update: UpdateHandle; version: string; notes?: string } | null;
export type PendingUpdate = { version: string; notes?: string; date?: string } | null;

export function createUpdaterState() {
const [updateAutoCheck, setUpdateAutoCheck] = createSignal(true);
const [updateStatus, setUpdateStatus] = createSignal<UpdateStatus>({ state: "idle", lastCheckedAt: null });
const [pendingUpdate, setPendingUpdate] = createSignal<PendingUpdate>(null);
const [updateEnv, setUpdateEnv] = createSignal<UpdaterEnvironment | null>(null);
const [updateChannel, setUpdateChannel] = createSignal<UpdateChannel>("stable");

return {
updateAutoCheck,
Expand All @@ -35,5 +38,7 @@ export function createUpdaterState() {
setPendingUpdate,
updateEnv,
setUpdateEnv,
updateChannel,
setUpdateChannel,
} as const;
}
32 changes: 31 additions & 1 deletion packages/app/src/app/lib/tauri.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { invoke } from "@tauri-apps/api/core";
import { Channel, invoke } from "@tauri-apps/api/core";
import { fetch as tauriFetch } from "@tauri-apps/plugin-http";
import { isTauriRuntime } from "../utils";
import { validateMcpServerName } from "../mcp";
Expand Down Expand Up @@ -496,10 +496,40 @@ export type UpdaterEnvironment = {
appBundlePath: string | null;
};

export type UpdateChannel = "stable" | "prerelease";

export type UpdaterCheckResult = {
version: string;
currentVersion: string;
date?: string;
notes?: string;
} | null;

export type UpdaterDownloadEvent =
| { event: "Started"; data: { contentLength?: number | null } }
| { event: "Progress"; data: { chunkLength: number } }
| { event: "Finished"; data: Record<string, never> };

export async function updaterEnvironment(): Promise<UpdaterEnvironment> {
return invoke<UpdaterEnvironment>("updater_environment");
}

export async function updaterCheck(channel: UpdateChannel): Promise<UpdaterCheckResult> {
return invoke<UpdaterCheckResult>("updater_check", { channel });
}

export async function updaterDownload(
onEvent: (event: UpdaterDownloadEvent) => void,
): Promise<void> {
const channel = new Channel<UpdaterDownloadEvent>();
channel.onmessage = onEvent;
await invoke("updater_download", { onEvent: channel });
}

export async function updaterInstall(): Promise<void> {
await invoke("updater_install");
}

export async function readOpencodeConfig(
scope: "project" | "global",
projectDir: string,
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/app/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ export type DashboardViewProps = {
downloadedBytes?: number;
message?: string;
} | null;
updateChannel: "stable" | "prerelease";
setUpdateChannel: (value: "stable" | "prerelease") => void;
updateEnv: { supported?: boolean; reason?: string | null } | null;
appVersion: string | null;
checkForUpdates: () => void;
Expand Down Expand Up @@ -1025,6 +1027,8 @@ export default function DashboardView(props: DashboardViewProps) {
downloadUpdate={props.downloadUpdate}
installUpdateAndRestart={props.installUpdateAndRestart}
anyActiveRuns={props.anyActiveRuns}
updateChannel={props.updateChannel}
setUpdateChannel={props.setUpdateChannel}
onResetStartupPreference={props.onResetStartupPreference}
openResetModal={props.openResetModal}
resetModalBusy={props.resetModalBusy}
Expand Down
Loading
Loading