mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-12-05 22:36:23 +01:00
Yaak Proxy: release build, dry run and updater (#836)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9cc9f7a5b8
commit
6e39955f17
40 files changed
+3024
-536
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import { useState } from "react";
|
||||
import type { ButtonProps } from "./Button";
|
||||
import { Button } from "./Button";
|
||||
|
||||
export function ButtonInfiniteLoading({
|
||||
onClick,
|
||||
isLoading,
|
||||
loadingChildren,
|
||||
children,
|
||||
...props
|
||||
}: ButtonProps & { loadingChildren?: string }) {
|
||||
const [localIsLoading, setLocalIsLoading] = useState<boolean>(false);
|
||||
return (
|
||||
<Button
|
||||
isLoading={localIsLoading || isLoading}
|
||||
onClick={(e) => {
|
||||
setLocalIsLoading(true);
|
||||
onClick?.(e);
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
{localIsLoading ? (loadingChildren ?? children) : children}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -145,12 +145,14 @@ export function SettingsUpdatesSection({
|
||||
onChange={(autoDownloadUpdates) => callbacks.onChange({ autoDownloadUpdates })}
|
||||
/>
|
||||
|
||||
<SettingRowBoolean
|
||||
title="Check for notifications"
|
||||
description="Periodically ping Yaak servers to check for relevant notifications."
|
||||
checked={values.checkNotifications}
|
||||
onChange={(checkNotifications) => callbacks.onChange({ checkNotifications })}
|
||||
/>
|
||||
{view.updates?.notificationsSetting !== false && (
|
||||
<SettingRowBoolean
|
||||
title="Check for notifications"
|
||||
description="Periodically ping Yaak servers to check for relevant notifications."
|
||||
checked={values.checkNotifications}
|
||||
onChange={(checkNotifications) => callbacks.onChange({ checkNotifications })}
|
||||
/>
|
||||
)}
|
||||
|
||||
<SettingRowBoolean
|
||||
title="Send anonymous usage statistics"
|
||||
|
||||
@@ -129,6 +129,22 @@ describe("SettingsGeneral", () => {
|
||||
expect(withFeedback).toContain("Prompt for feedback");
|
||||
});
|
||||
|
||||
test("leaves out the notifications row only when the app asks", () => {
|
||||
const shown = text(render(<SettingsGeneral view={stubView()} callbacks={callbacks} />));
|
||||
expect(shown).toContain("Check for notifications");
|
||||
|
||||
const hidden = text(
|
||||
render(
|
||||
<SettingsGeneral
|
||||
view={stubView({ updates: { checking: false, notificationsSetting: false } })}
|
||||
callbacks={callbacks}
|
||||
/>,
|
||||
),
|
||||
);
|
||||
expect(hidden).toContain("Update Channel");
|
||||
expect(hidden).not.toContain("Check for notifications");
|
||||
});
|
||||
|
||||
test("puts the app's banner under the heading and its own sections before App Info", () => {
|
||||
const t = text(
|
||||
render(
|
||||
|
||||
@@ -69,6 +69,8 @@ export interface SettingsFontsView {
|
||||
export interface SettingsUpdatesView {
|
||||
/** A check for updates is running */
|
||||
checking: boolean;
|
||||
/** Show the row that turns notification checks off; shown unless false */
|
||||
notificationsSetting?: boolean;
|
||||
}
|
||||
|
||||
/** Where a license stands, with what each state's copy needs */
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
import { createStore } from "jotai";
|
||||
import type { ReactNode } from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from "vite-plus/test";
|
||||
import { toastsAtom } from "../../lib/toast";
|
||||
import {
|
||||
showUpdateAvailableToast,
|
||||
showUpdateInstalledToast,
|
||||
showUpdateStateToast,
|
||||
UPDATE_STATE_TOAST_ID,
|
||||
UPDATE_TOAST_ID,
|
||||
updateStateMessage,
|
||||
} from "./updateToasts";
|
||||
|
||||
function text(node: ReactNode) {
|
||||
return renderToStaticMarkup(<>{node}</>)
|
||||
.replace(/<[^>]+>/g, " ")
|
||||
.replace(/'/g, "'")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
/** The toast shown, with its message and its action as they read */
|
||||
function shown(store: ReturnType<typeof createStore>) {
|
||||
vi.runAllTimers();
|
||||
const toasts = store.get(toastsAtom);
|
||||
expect(toasts).toHaveLength(1);
|
||||
const toast = toasts[0]!;
|
||||
return {
|
||||
toast,
|
||||
message: text(toast.message),
|
||||
action: text(toast.action?.({ hide: () => {} }) ?? null),
|
||||
};
|
||||
}
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
describe("update toasts", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
test("offers an update the app installs, in the app's name", () => {
|
||||
const store = createStore();
|
||||
showUpdateAvailableToast(store, {
|
||||
appName: "Yaak Proxy",
|
||||
update: { version: "2026.11.0", downloaded: false, install: "integrated" },
|
||||
onOpenUrl: noop,
|
||||
onInstall: noop,
|
||||
});
|
||||
const { toast, message, action } = shown(store);
|
||||
expect(toast.id).toBe(UPDATE_TOAST_ID);
|
||||
expect(toast.timeout).toBeNull();
|
||||
expect(message).toBe("Yaak Proxy 2026.11.0 is available Download and install the update?");
|
||||
// No release notes given, so no What's New
|
||||
expect(action).toBe("Download and Install");
|
||||
});
|
||||
|
||||
test("offers What's New and installing a downloaded update, as Yaak's does", () => {
|
||||
const store = createStore();
|
||||
showUpdateAvailableToast(store, {
|
||||
appName: "Yaak",
|
||||
update: { version: "2026.11.0", downloaded: true, install: "integrated" },
|
||||
whatsNewUrl: "https://yaak.app/changelog/2026.11.0",
|
||||
downloadUrl: "https://yaak.app/download",
|
||||
onOpenUrl: noop,
|
||||
onInstall: noop,
|
||||
});
|
||||
const { message, action } = shown(store);
|
||||
expect(message).toBe("Yaak 2026.11.0 is available Do you want to install the update?");
|
||||
expect(action).toBe("Install Now What's New");
|
||||
});
|
||||
|
||||
test("says how to update an install the app can't update itself", () => {
|
||||
const store = createStore();
|
||||
showUpdateAvailableToast(store, {
|
||||
appName: "Yaak",
|
||||
update: { version: "2026.11.0", downloaded: false, install: "manual" },
|
||||
downloadUrl: "https://yaak.app/download",
|
||||
onOpenUrl: noop,
|
||||
onInstall: noop,
|
||||
});
|
||||
const { message, action } = shown(store);
|
||||
expect(message).toBe("Yaak 2026.11.0 is available Download the new version to upgrade.");
|
||||
expect(action).toBe("Download");
|
||||
});
|
||||
|
||||
test("offers to relaunch into an installed update", () => {
|
||||
const store = createStore();
|
||||
const onRelaunch = vi.fn();
|
||||
showUpdateInstalledToast(store, { appName: "Yaak Proxy", version: "2026.11.0", onRelaunch });
|
||||
const { message, action } = shown(store);
|
||||
expect(message).toBe("Yaak Proxy 2026.11.0 was installed Start using the new version now?");
|
||||
expect(action).toBe("Relaunch Yaak Proxy");
|
||||
});
|
||||
|
||||
test("says where an update already in hand stands, apart from its prompt", () => {
|
||||
const store = createStore();
|
||||
showUpdateStateToast(store, {
|
||||
appName: "Yaak Proxy",
|
||||
state: { state: "downloading", version: "2026.11.0" },
|
||||
});
|
||||
const { toast, message } = shown(store);
|
||||
expect(toast.id).toBe(UPDATE_STATE_TOAST_ID);
|
||||
expect(toast.id).not.toBe(UPDATE_TOAST_ID);
|
||||
expect(message).toBe("Yaak Proxy 2026.11.0 is downloading.");
|
||||
});
|
||||
|
||||
test("words each state, and shows nothing for idle", () => {
|
||||
expect(updateStateMessage("Yaak", { state: "checking" })).toBe("Already checking for updates.");
|
||||
expect(updateStateMessage("Yaak", { state: "offered", version: "1.0.0" })).toBe(
|
||||
"Yaak 1.0.0 is available.",
|
||||
);
|
||||
expect(updateStateMessage("Yaak", { state: "installing", version: "1.0.0" })).toBe(
|
||||
"Yaak 1.0.0 is installing.",
|
||||
);
|
||||
expect(updateStateMessage("Yaak", { state: "installed", version: "1.0.0" })).toBe(
|
||||
"Yaak 1.0.0 is installed. Relaunch to start using it.",
|
||||
);
|
||||
const store = createStore();
|
||||
expect(showUpdateStateToast(store, { appName: "Yaak", state: { state: "idle" } })).toBeNull();
|
||||
vi.runAllTimers();
|
||||
expect(store.get(toastsAtom)).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,211 @@
|
||||
import type { createStore } from "jotai";
|
||||
import { showToast } from "../../lib/toast";
|
||||
import { Button } from "../Button";
|
||||
import { ButtonInfiniteLoading } from "../ButtonInfiniteLoading";
|
||||
import { Icon } from "../Icon";
|
||||
import { InlineCode } from "../InlineCode";
|
||||
import { HStack, VStack } from "../Stacks";
|
||||
|
||||
type Store = ReturnType<typeof createStore>;
|
||||
|
||||
/** The one toast an app's update shows, replaced as it moves from available to installed */
|
||||
export const UPDATE_TOAST_ID = "update-info";
|
||||
|
||||
/** An available update, as the app's updater describes it */
|
||||
export interface UpdateToastInfo {
|
||||
version: string;
|
||||
/** Downloaded already, so installing needs no download */
|
||||
downloaded: boolean;
|
||||
/** `integrated` when the app installs it itself; otherwise the user is told how to update */
|
||||
install: "integrated" | "flatpak" | "manual";
|
||||
}
|
||||
|
||||
export interface ShowUpdateAvailableToastArgs {
|
||||
/** As the copy says it: `Yaak`, `Yaak Proxy` */
|
||||
appName: string;
|
||||
update: UpdateToastInfo;
|
||||
/** The release notes for this version; no What's New button without them */
|
||||
whatsNewUrl?: string;
|
||||
/** Where to download the app by hand, for an install that can't update itself */
|
||||
downloadUrl?: string;
|
||||
onOpenUrl: (url: string) => void | Promise<void>;
|
||||
/** The user chose to install an `integrated` update */
|
||||
onInstall: () => void | Promise<void>;
|
||||
}
|
||||
|
||||
/** Offers an available update: to install it, or, where the app can't, says how to get it */
|
||||
export function showUpdateAvailableToast(
|
||||
store: Store,
|
||||
{ appName, update, whatsNewUrl, downloadUrl, onOpenUrl, onInstall }: ShowUpdateAvailableToastArgs,
|
||||
) {
|
||||
const { version, downloaded, install } = update;
|
||||
|
||||
const whatsNewButton = whatsNewUrl != null && (
|
||||
<Button
|
||||
size="xs"
|
||||
color="info"
|
||||
variant="border"
|
||||
rightSlot={<Icon icon="external_link" />}
|
||||
onClick={async () => {
|
||||
await onOpenUrl(whatsNewUrl);
|
||||
}}
|
||||
>
|
||||
What's New
|
||||
</Button>
|
||||
);
|
||||
|
||||
if (install !== "integrated") {
|
||||
const flatpak = install === "flatpak";
|
||||
return showToast(store, {
|
||||
id: UPDATE_TOAST_ID,
|
||||
color: "info",
|
||||
timeout: null,
|
||||
message: (
|
||||
<VStack>
|
||||
<h2 className="font-semibold">
|
||||
{appName} {version} is available
|
||||
</h2>
|
||||
<p className="text-text-subtle text-sm">
|
||||
{flatpak ? (
|
||||
<>
|
||||
Update with <InlineCode>flatpak update</InlineCode> or your software center.
|
||||
</>
|
||||
) : (
|
||||
"Download the new version to upgrade."
|
||||
)}
|
||||
</p>
|
||||
</VStack>
|
||||
),
|
||||
action: () => (
|
||||
<HStack space={1.5}>
|
||||
{!flatpak && downloadUrl != null && (
|
||||
<Button
|
||||
size="xs"
|
||||
color="info"
|
||||
rightSlot={<Icon icon="external_link" />}
|
||||
onClick={async () => {
|
||||
await onOpenUrl(downloadUrl);
|
||||
}}
|
||||
>
|
||||
Download
|
||||
</Button>
|
||||
)}
|
||||
{whatsNewButton}
|
||||
</HStack>
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
return showToast(store, {
|
||||
id: UPDATE_TOAST_ID,
|
||||
color: "info",
|
||||
timeout: null,
|
||||
message: (
|
||||
<VStack>
|
||||
<h2 className="font-semibold">
|
||||
{appName} {version} is available
|
||||
</h2>
|
||||
<p className="text-text-subtle text-sm">
|
||||
{downloaded ? "Do you want to install" : "Download and install"} the update?
|
||||
</p>
|
||||
</VStack>
|
||||
),
|
||||
action: () => (
|
||||
<HStack space={1.5}>
|
||||
<ButtonInfiniteLoading
|
||||
size="xs"
|
||||
color="info"
|
||||
className="min-w-40"
|
||||
loadingChildren={downloaded ? "Installing..." : "Downloading..."}
|
||||
onClick={async () => {
|
||||
await onInstall();
|
||||
}}
|
||||
>
|
||||
{downloaded ? "Install Now" : "Download and Install"}
|
||||
</ButtonInfiniteLoading>
|
||||
{whatsNewButton}
|
||||
</HStack>
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
/** The toast saying where an update already in hand stands, apart from its prompt */
|
||||
export const UPDATE_STATE_TOAST_ID = "update-state";
|
||||
|
||||
/** Where an app's update stands, as its updater reports it */
|
||||
export type UpdateToastState =
|
||||
| { state: "idle" }
|
||||
| { state: "checking" }
|
||||
| { state: "offered" | "downloading" | "installing" | "installed"; version: string };
|
||||
|
||||
/** What the user who asked for a check is told while an update is already in hand */
|
||||
export function updateStateMessage(appName: string, state: UpdateToastState): string | null {
|
||||
switch (state.state) {
|
||||
case "idle":
|
||||
return null;
|
||||
case "checking":
|
||||
return "Already checking for updates.";
|
||||
case "offered":
|
||||
return `${appName} ${state.version} is available.`;
|
||||
case "downloading":
|
||||
return `${appName} ${state.version} is downloading.`;
|
||||
case "installing":
|
||||
return `${appName} ${state.version} is installing.`;
|
||||
case "installed":
|
||||
return `${appName} ${state.version} is installed. Relaunch to start using it.`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the user who asked for a check where the update already in hand stands, instead of
|
||||
* starting another. The prompt it belongs to, if any, keeps its own toast.
|
||||
*/
|
||||
export function showUpdateStateToast(
|
||||
store: Store,
|
||||
{ appName, state }: { appName: string; state: UpdateToastState },
|
||||
) {
|
||||
const message = updateStateMessage(appName, state);
|
||||
if (message == null) return null;
|
||||
return showToast(store, { id: UPDATE_STATE_TOAST_ID, color: "info", message });
|
||||
}
|
||||
|
||||
export interface ShowUpdateInstalledToastArgs {
|
||||
appName: string;
|
||||
version: string;
|
||||
/** Relaunch the app into the installed version */
|
||||
onRelaunch: () => void;
|
||||
}
|
||||
|
||||
/** Says an update installed and offers to relaunch into it */
|
||||
export function showUpdateInstalledToast(
|
||||
store: Store,
|
||||
{ appName, version, onRelaunch }: ShowUpdateInstalledToastArgs,
|
||||
) {
|
||||
return showToast(store, {
|
||||
id: UPDATE_TOAST_ID,
|
||||
color: "primary",
|
||||
timeout: null,
|
||||
message: (
|
||||
<VStack>
|
||||
<h2 className="font-semibold">
|
||||
{appName} {version} was installed
|
||||
</h2>
|
||||
<p className="text-text-subtle text-sm">Start using the new version now?</p>
|
||||
</VStack>
|
||||
),
|
||||
action: ({ hide }) => (
|
||||
<ButtonInfiniteLoading
|
||||
size="xs"
|
||||
className="mr-auto min-w-20"
|
||||
color="primary"
|
||||
loadingChildren="Restarting..."
|
||||
onClick={() => {
|
||||
hide();
|
||||
setTimeout(onRelaunch, 200);
|
||||
}}
|
||||
>
|
||||
Relaunch {appName}
|
||||
</ButtonInfiniteLoading>
|
||||
),
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user