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
15 changes: 14 additions & 1 deletion apps/desktop/src/lib/trpc/routers/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ import { TRPCError } from "@trpc/server";
import { observable } from "@trpc/server/observable";
import { app } from "electron";
import { env } from "main/env.main";
import { exitImmediately } from "main/index";
import { exitImmediately, quitApp } from "main/index";
import { installUpdate, isUpdateReadyToInstall } from "main/lib/auto-updater";
import { hasCustomRingtone } from "main/lib/custom-ringtones";
import { getHostServiceCoordinator } from "main/lib/host-service-coordinator";
import { applyAppLanguage, languageEvents } from "main/lib/language";
import { localDb } from "main/lib/local-db";
import { relaunchApp } from "main/lib/relaunch-app";
import {
DEFAULT_AUTO_APPLY_DEFAULT_PRESET,
DEFAULT_CONFIRM_ON_QUIT,
Expand Down Expand Up @@ -924,6 +926,17 @@ export const createSettingsRouter = () => {
return { success: true };
}),

/** Relaunch through the normal quit path so cleanup and DB flushes run. */
relaunchApp: publicProcedure.mutation(() => {
relaunchApp({
isUpdateReadyToInstall,
installUpdate,
relaunch: () => app.relaunch(),
quit: quitApp,
});
return { success: true };
}),

getBranchPrefix: publicProcedure.query(() => {
const row = getSettings();
return {
Expand Down
33 changes: 33 additions & 0 deletions apps/desktop/src/main/lib/relaunch-app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, mock, test } from "bun:test";
import { type RelaunchAppDeps, relaunchApp } from "./relaunch-app";

function createDeps(updateReady: boolean) {
const calls: string[] = [];
const deps: RelaunchAppDeps = {
isUpdateReadyToInstall: () => updateReady,
installUpdate: mock(() => calls.push("installUpdate")),
relaunch: mock(() => calls.push("relaunch")),
quit: mock(() => calls.push("quit")),
};
return { deps, calls };
}

describe("relaunchApp", () => {
test("without a staged update, relaunches and then quits through the normal path", () => {
const { deps, calls } = createDeps(false);

relaunchApp(deps);

expect(calls).toEqual(["relaunch", "quit"]);
});

test("with a staged update, hands off to the updater and never relaunches the old bundle", () => {
const { deps, calls } = createDeps(true);

relaunchApp(deps);

expect(calls).toEqual(["installUpdate"]);
expect(deps.relaunch).not.toHaveBeenCalled();
expect(deps.quit).not.toHaveBeenCalled();
});
});
21 changes: 21 additions & 0 deletions apps/desktop/src/main/lib/relaunch-app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export interface RelaunchAppDeps {
isUpdateReadyToInstall: () => boolean;
installUpdate: () => void;
relaunch: () => void;
quit: () => void;
}

/**
* With an update staged, Squirrel.Mac installs it once this process exits.
* `app.relaunch()` would start the old bundle in that same second, so the
* user comes back on the old version while ShipIt swaps the bundle beneath
* it. The updater's own install restarts into the new version instead.
*/
export function relaunchApp(deps: RelaunchAppDeps): void {
if (deps.isUpdateReadyToInstall()) {
deps.installUpdate();
return;
}
deps.relaunch();
deps.quit();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { afterAll, afterEach, describe, expect, mock, test } from "bun:test";
import { GlobalRegistrator } from "@happy-dom/global-registrator";

// happy-dom for real clicks; unregister in afterAll so the shared mock
// document used by the other renderer suites is restored (see Redirect.test).
const alreadyRegistered = GlobalRegistrator.isRegistered;
if (!alreadyRegistered) GlobalRegistrator.register();
(
globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
).IS_REACT_ACT_ENVIRONMENT = true;

const ORG = "org-flip-notice";
const tracked: string[] = [];
let relaunchCalls = 0;

mock.module("renderer/lib/analytics", () => ({
track: (event: string) => {
tracked.push(event);
},
}));
mock.module("renderer/lib/trpc-client", () => ({
electronTrpcClient: {
settings: {
relaunchApp: {
mutate: async () => {
relaunchCalls++;
return { success: true };
},
},
},
},
}));
const realAuthClient = await import("renderer/lib/auth-client");
mock.module("renderer/lib/auth-client", () => ({
...realAuthClient,
authClient: {
...realAuthClient.authClient,
useSession: () => ({
data: { session: { activeOrganizationId: ORG }, user: {} },
}),
},
}));
// The card's cover shader needs WebGL; the notice's behaviour does not.
mock.module("@paper-design/shaders-react", () => ({
Dithering: () => null,
}));

// Queries come from render(): the module-level `screen` binds document.body
// at first import, which an earlier suite may have done against the shared
// mock document rather than happy-dom.
const { act, cleanup, fireEvent, render } = await import(
"@testing-library/react"
);
const { markV1MigrationComplete } = await import(
"renderer/lib/v1-migration/completion"
);
const { V1FlipNotice } = await import("./V1FlipNotice");

afterEach(() => {
cleanup();
tracked.length = 0;
relaunchCalls = 0;
});
afterAll(async () => {
if (!alreadyRegistered) await GlobalRegistrator.unregister();
});

describe("V1FlipNotice", () => {
test("renders nothing until the org's migration completes", () => {
const { queryByText } = render(<V1FlipNotice />);
expect(queryByText("A better Superset is ready")).toBeNull();
});

test("shows once complete; Relaunch now tracks and relaunches", async () => {
const { getByRole, getByText } = render(<V1FlipNotice />);
await act(async () => {
markV1MigrationComplete(ORG);
});
expect(getByText("A better Superset is ready")).toBeTruthy();
expect(tracked).toContain("v1_flip_notice_shown");

fireEvent.click(getByRole("button", { name: "Relaunch now" }));
await act(async () => {});
expect(relaunchCalls).toBe(1);
expect(tracked).toContain("v1_flip_notice_relaunch");
expect(tracked).not.toContain("v1_flip_notice_dismissed");
});

test("Later dismisses without relaunching", async () => {
const { getByRole, queryByText } = render(<V1FlipNotice />);
await act(async () => {
markV1MigrationComplete(ORG);
});
fireEvent.click(getByRole("button", { name: "Later" }));
expect(queryByText("A better Superset is ready")).toBeNull();
expect(tracked).toContain("v1_flip_notice_dismissed");
expect(relaunchCalls).toBe(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useLingui as useTranslation } from "@lingui/react";
import { useEffect, useRef, useState } from "react";
import { track } from "renderer/lib/analytics";
import { authClient } from "renderer/lib/auth-client";
import { electronTrpcClient } from "renderer/lib/trpc-client";
import {
isV1MigrationComplete,
V1_MIGRATION_COMPLETED_EVENT,
Expand Down Expand Up @@ -53,12 +54,23 @@ export function V1FlipNotice() {
setDismissed(true);
};

const relaunch = () => {
track("v1_flip_notice_relaunch");
electronTrpcClient.settings.relaunchApp.mutate().catch((err) => {
console.error("[v1-migration] relaunch failed", err);
});
};

return (
<FlipNoticeCard
title={translate(msg({ message: "A better Superset is ready" }))}
body="Superset has been upgraded: faster, cleaner, and built around your projects. Everything comes along on your next launch."
warning="Running terminal sessions won't carry over."
ctaLabel="Got it"
action={{
label: translate(msg({ message: "Relaunch now" })),
onClick: relaunch,
}}
ctaLabel={translate(msg({ message: "Later" }))}
onDismiss={dismiss}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface FlipNoticeCardProps {
body: string;
/** Rendered as an amber callout row (WorkspaceHoverCard idiom). */
warning?: string;
/** Primary button; when present the dismiss cta renders as secondary. */
action?: { label: string; onClick: () => void };
ctaLabel: string;
onDismiss: () => void;
}
Expand All @@ -32,6 +34,7 @@ export function FlipNoticeCard({
title,
body,
warning,
action,
ctaLabel,
onDismiss,
}: FlipNoticeCardProps) {
Expand Down Expand Up @@ -74,9 +77,20 @@ export function FlipNoticeCard({
<p className="text-sm">{warning}</p>
</div>
) : null}
<Button size="sm" onClick={onDismiss}>
{ctaLabel}
</Button>
<div className="flex gap-2">
{action ? (
<Button size="sm" onClick={action.onClick}>
{action.label}
</Button>
) : null}
<Button
size="sm"
variant={action ? "outline" : "default"}
onClick={onDismiss}
>
{ctaLabel}
</Button>
</div>
</div>
</div>
);
Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/cs/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "Související články"
msgid "Relative path copied"
msgstr "Relativní cesta zkopírována"

msgid "Relaunch now"
msgstr "Restartovat nyní"

msgid "Relaunch running agents to switch them."
msgstr "Běžící agenty přepnete jejich novým spuštěním."

Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "Verwandte Beiträge"
msgid "Relative path copied"
msgstr "Relativer Pfad kopiert"

msgid "Relaunch now"
msgstr "Jetzt neu starten"

msgid "Relaunch running agents to switch them."
msgstr "Starte laufende Agenten neu, um sie umzustellen."

Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "Related Posts"
msgid "Relative path copied"
msgstr "Relative path copied"

msgid "Relaunch now"
msgstr "Relaunch now"

msgid "Relaunch running agents to switch them."
msgstr "Relaunch running agents to switch them."

Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/es/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "Publicaciones relacionadas"
msgid "Relative path copied"
msgstr "Ruta relativa copiada"

msgid "Relaunch now"
msgstr "Reiniciar ahora"

msgid "Relaunch running agents to switch them."
msgstr "Vuelve a lanzar los agentes en marcha para cambiarlos."

Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "Articles liés"
msgid "Relative path copied"
msgstr "Chemin relatif copié"

msgid "Relaunch now"
msgstr "Redémarrer maintenant"

msgid "Relaunch running agents to switch them."
msgstr "Relancez les agents en cours pour les basculer."

Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/id/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "Tulisan Terkait"
msgid "Relative path copied"
msgstr "Path relatif disalin"

msgid "Relaunch now"
msgstr "Mulai ulang sekarang"

msgid "Relaunch running agents to switch them."
msgstr "Jalankan ulang agen yang sedang berjalan untuk menggantinya."

Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/it/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "Post correlati"
msgid "Relative path copied"
msgstr "Percorso relativo copiato"

msgid "Relaunch now"
msgstr "Riavvia ora"

msgid "Relaunch running agents to switch them."
msgstr "Riavvia gli agenti in esecuzione per cambiarli."

Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/ja/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "関連記事"
msgid "Relative path copied"
msgstr "相対パスをコピーしました"

msgid "Relaunch now"
msgstr "今すぐ再起動"

msgid "Relaunch running agents to switch them."
msgstr "実行中のエージェントを切り替えるには再起動してください。"

Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/ko/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "관련 게시물"
msgid "Relative path copied"
msgstr "상대 경로 복사됨"

msgid "Relaunch now"
msgstr "지금 다시 시작"

msgid "Relaunch running agents to switch them."
msgstr "실행 중인 에이전트는 다시 실행해야 바뀝니다."

Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/nl/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "Gerelateerde berichten"
msgid "Relative path copied"
msgstr "Relatief pad gekopieerd"

msgid "Relaunch now"
msgstr "Nu opnieuw starten"

msgid "Relaunch running agents to switch them."
msgstr "Herstart draaiende agents om ze te wisselen."

Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/pl/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "Powiązane wpisy"
msgid "Relative path copied"
msgstr "Skopiowano ścieżkę względną"

msgid "Relaunch now"
msgstr "Uruchom ponownie teraz"

msgid "Relaunch running agents to switch them."
msgstr "Uruchom ponownie działających agentów, aby ich przełączyć."

Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/pt-BR/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "Posts relacionados"
msgid "Relative path copied"
msgstr "Caminho relativo copiado"

msgid "Relaunch now"
msgstr "Reiniciar agora"

msgid "Relaunch running agents to switch them."
msgstr "Reinicie os agentes em execução para trocar a conta deles."

Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/ru/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11984,6 +11984,9 @@ msgstr "Похожие посты"
msgid "Relative path copied"
msgstr "Относительный путь скопирован"

msgid "Relaunch now"
msgstr "Перезапустить сейчас"

msgid "Relaunch running agents to switch them."
msgstr "Перезапустите работающих агентов, чтобы переключить их."

Expand Down
Loading
Loading