Skip to content

Commit d288ef2

Browse files
committed
changes from self-review
1 parent 5fe50e4 commit d288ef2

8 files changed

Lines changed: 29 additions & 45 deletions

File tree

apps/code/src/main/platform-adapters/electron-updater.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,10 @@ export class ElectronUpdater implements IUpdater {
6767
}
6868

6969
public quitAndInstall(): void {
70-
// An unpackaged (dev) build has no staged artifact to swap, so the real
71-
// quitAndInstall would no-op or throw. Relaunch instead, so a simulated
72-
// update can still exercise the post-update startup path (e.g. fullscreen
73-
// restore) during local testing.
70+
// An unpackaged (dev) build has no staged artifact to swap and
71+
// the real quitAndInstall would no-op or throw, so relaunch instead.
7472
if (!app.isPackaged) {
7573
app.relaunch();
76-
app.exit(0);
7774
return;
7875
}
7976
autoUpdater.quitAndInstall(false, true);

apps/code/src/main/services/app-lifecycle/service.test.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,16 @@ describe("AppLifecycleService", () => {
129129
expect(service.isQuittingForUpdate).toBe(false);
130130
});
131131

132-
it("remembers fullscreen for the next launch when quitting for update in fullscreen", () => {
133-
mockGetFullScreenState.mockReturnValue(true);
134-
service.setQuittingForUpdate();
135-
expect(mockSetRestoreFullScreenOnNextLaunch).toHaveBeenCalledWith(true);
136-
});
137-
138-
it("does not schedule a fullscreen restore when not fullscreen", () => {
139-
mockGetFullScreenState.mockReturnValue(false);
140-
service.setQuittingForUpdate();
141-
expect(mockSetRestoreFullScreenOnNextLaunch).toHaveBeenCalledWith(false);
142-
});
132+
it.each([[true], [false]])(
133+
"schedules restore-fullscreen=%s on update-quit",
134+
(isFullScreen) => {
135+
mockGetFullScreenState.mockReturnValue(isFullScreen);
136+
service.setQuittingForUpdate();
137+
expect(mockSetRestoreFullScreenOnNextLaunch).toHaveBeenCalledWith(
138+
isFullScreen,
139+
);
140+
},
141+
);
143142

144143
it("clears the fullscreen-restore flag when the update handoff is aborted", () => {
145144
mockGetFullScreenState.mockReturnValue(true);

apps/code/src/main/services/app-lifecycle/service.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,13 @@ export class AppLifecycleService {
5757

5858
setQuittingForUpdate(): void {
5959
this._isQuittingForUpdate = true;
60-
// Remember whether we were fullscreen so the post-update relaunch restores
61-
// it. A normal quit never runs this, so the flag stays false and the app
62-
// reopens windowed.
60+
// Remember fullscreen state so the post-update relaunch restores it.
6361
setRestoreFullScreenOnNextLaunch(getFullScreenState());
6462
}
6563

6664
clearQuittingForUpdate(): void {
6765
this._isQuittingForUpdate = false;
68-
// The install handoff was aborted; don't let a stale flag restore
69-
// fullscreen on the next manual launch.
66+
// The install handoff was aborted.
7067
setRestoreFullScreenOnNextLaunch(false);
7168
}
7269

apps/code/src/main/services/dev-actions/service.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { UPDATES_SERVICE } from "@posthog/core/updates/identifiers";
2+
import type { UpdatesService } from "@posthog/core/updates/updates";
13
import {
24
DEV_HOST_ACTIONS_SERVICE,
35
type IDevHostActions,
46
} from "@posthog/platform/dev-host-actions";
57
import { TypedEventEmitter } from "@posthog/shared";
6-
import { UPDATES_SERVICE } from "@posthog/core/updates/identifiers";
7-
import type { UpdatesService } from "@posthog/core/updates/updates";
88
import { inject, injectable } from "inversify";
99
import { DEV_NETWORK_SERVICE } from "../../di/tokens";
1010
import { getUserDataDir } from "../../utils/env";
@@ -52,8 +52,7 @@ export class DevActionsService extends TypedEventEmitter<DevActionsEvents> {
5252

5353
/**
5454
* Surfaces the real update banner in the sidebar without a packaged build or
55-
* a downloaded artifact. Clicking the banner's Restart then runs the normal
56-
* install path (which persists the restore-fullscreen intent and relaunches),
55+
* a downloaded artifact. Clicking Restart runs the normal install path,
5756
* so the update-restart behaviour can be exercised in local dev.
5857
*/
5958
simulateUpdate(): void {

apps/code/src/main/utils/store.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ export function getFullScreenState(): boolean {
7272
}
7373

7474
/**
75-
* One-shot flag that survives a single relaunch. Set only when the app quits
76-
* to install an update, so a fullscreen session is restored after the
77-
* "restart to apply" handoff — but a normal quit (Cmd+Q, window close) leaves
78-
* it false and launches windowed.
75+
* Set only when the app quits to install an update, so a fullscreen session
76+
* is restored after the "restart to apply" handoff.
77+
* A normal quit leaves it false and launches windowed.
7978
*/
8079
export function setRestoreFullScreenOnNextLaunch(restore: boolean): void {
8180
windowStateStore.set("restoreFullScreenOnNextLaunch", restore);

apps/code/src/main/window.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { collectMemorySnapshot } from "./utils/crash-diagnostics";
2424
import { isDevBuild } from "./utils/env";
2525
import { logger, readChromiumLogTail } from "./utils/logger";
2626
import {
27-
getRestoreFullScreenOnNextLaunch,
2827
saveFullScreenState,
2928
saveZoomLevel,
3029
setRestoreFullScreenOnNextLaunch,
@@ -79,10 +78,8 @@ export function saveWindowState(window: BrowserWindow): void {
7978
const isMaximized = window.isMaximized();
8079
windowStateStore.set("isMaximized", isMaximized);
8180

82-
// Only save bounds when the window is in its normal state. Persisting the
83-
// maximized or fullscreen bounds would clobber the user's windowed
84-
// size/position, so a later "revert to windowed" launch has nothing to
85-
// restore to.
81+
// Only save bounds when not maximized, so restoring from maximized
82+
// gives the user their previous windowed size/position
8683
if (!isMaximized && !window.isFullScreen()) {
8784
const bounds = window.getBounds();
8885
windowStateStore.set("x", bounds.x);
@@ -170,9 +167,8 @@ export function createWindow(): void {
170167
const savedState = getSavedWindowState();
171168

172169
// Read the one-shot fullscreen-restore flag and clear it immediately, so it
173-
// only ever affects the single launch that follows an update restart. A
174-
// normal quit never sets it, so this is false and the app launches windowed.
175-
const restoreFullScreen = getRestoreFullScreenOnNextLaunch();
170+
// only ever affects the single launch that follows an update restart.
171+
const restoreFullScreen = savedState.restoreFullScreenOnNextLaunch;
176172
if (restoreFullScreen) {
177173
setRestoreFullScreenOnNextLaunch(false);
178174
}

apps/code/src/renderer/features/dev-toolbar/components/DevToolbar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { updateStore } from "@posthog/core/updates/updateStore";
12
import {
23
DropdownMenu,
34
DropdownMenuContent,
@@ -11,7 +12,6 @@ import {
1112
ItemDescription,
1213
ItemTitle,
1314
} from "@posthog/quill";
14-
import { updateStore } from "@posthog/core/updates/updateStore";
1515
import { REGION_LABELS } from "@posthog/shared";
1616
import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient";
1717
import {
@@ -816,8 +816,8 @@ function QuickActionsMenu() {
816816
};
817817

818818
const handleSimulateUpdate = () => {
819-
// Updates report as disabled in dev, which hides the sidebar banner. Force
820-
// it on so the simulated "ready" state surfaces the real prompt.
819+
// Updates report as disabled in dev, which hides the sidebar banner.
820+
// Force it on so the simulated "ready" state surfaces the real prompt.
821821
updateStore.getState().setEnabled(true);
822822
void trpcClient.dev.simulateUpdate.mutate();
823823
};

packages/core/src/updates/updates.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,8 @@ export class UpdatesService extends TypedEventEmitter<UpdatesEvents> {
230230
}
231231

232232
/**
233-
* Dev/testing affordance (reached only through the dev-mode-gated toolbar):
234-
* forces a "ready" state with a fake version so the real update banner
235-
* surfaces, without a packaged build or a real downloaded artifact. Clicking
236-
* the banner's Restart then runs the normal installUpdate() path; in an
237-
* unpackaged build the updater relaunches instead of swapping binaries.
233+
* Forces a "ready" state with a fake version so the real update banner
234+
* surfaces, without a packaged build or a real downloaded artifact (dev only).
238235
*/
239236
simulateUpdateReady(version = "Update"): void {
240237
this.downloadedVersion = version;

0 commit comments

Comments
 (0)