Skip to content

Commit b72d5d7

Browse files
authored
fix(desktop): timestamps follow the OS locale instead of en-US (pingdotgg#6190)
1 parent 31d0fb6 commit b72d5d7

13 files changed

Lines changed: 131 additions & 1 deletion

‎apps/desktop/src/app/DesktopAppIdentity.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const makeElectronAppLayer = (calls: ElectronAppCalls) =>
4040
Layer.succeed(ElectronApp.ElectronApp, {
4141
metadata: Effect.die("unexpected metadata read"),
4242
name: Effect.succeed("T3 Code"),
43+
systemLocale: Effect.succeed("en-US"),
4344
whenReady: Effect.void,
4445
quit: Effect.void,
4546
exit: () => Effect.void,

‎apps/desktop/src/app/DesktopLifecycle.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe("DesktopLifecycle", () => {
2121
const electronAppLayer = Layer.succeed(ElectronApp.ElectronApp, {
2222
metadata: Effect.die("unexpected metadata read"),
2323
name: Effect.succeed("T3 Code"),
24+
systemLocale: Effect.succeed("en-US"),
2425
whenReady: Effect.void,
2526
quit: Effect.void,
2627
exit: () => Effect.void,

‎apps/desktop/src/electron/ElectronApp.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
autoUpdaterRemoveListenerMock,
99
exitMock,
1010
getAppPathMock,
11+
getSystemLocaleMock,
1112
getVersionMock,
1213
isDefaultProtocolClientMock,
1314
onMock,
@@ -29,6 +30,7 @@ const {
2930
autoUpdaterRemoveListenerMock: vi.fn(),
3031
exitMock: vi.fn(),
3132
getAppPathMock: vi.fn(() => "/app"),
33+
getSystemLocaleMock: vi.fn(() => "en-GB"),
3234
getVersionMock: vi.fn(() => "1.2.3"),
3335
isDefaultProtocolClientMock: vi.fn(() => false),
3436
onMock: vi.fn(),
@@ -60,6 +62,7 @@ vi.mock("electron", () => ({
6062
setIcon: setDockIconMock,
6163
},
6264
getAppPath: getAppPathMock,
65+
getSystemLocale: getSystemLocaleMock,
6366
getVersion: getVersionMock,
6467
isDefaultProtocolClient: isDefaultProtocolClientMock,
6568
isPackaged: true,
@@ -111,6 +114,23 @@ describe("ElectronApp", () => {
111114
}).pipe(Effect.provide(ElectronApp.layer)),
112115
);
113116

117+
it.effect("reads the OS locale through the service", () =>
118+
Effect.gen(function* () {
119+
const electronApp = yield* ElectronApp.ElectronApp;
120+
121+
assert.strictEqual(yield* electronApp.systemLocale, "en-GB");
122+
}).pipe(Effect.provide(ElectronApp.layer)),
123+
);
124+
125+
it.effect("normalizes POSIX-style locale identifiers that Intl rejects", () =>
126+
Effect.gen(function* () {
127+
getSystemLocaleMock.mockImplementationOnce(() => "en_GB");
128+
const electronApp = yield* ElectronApp.ElectronApp;
129+
130+
assert.strictEqual(yield* electronApp.systemLocale, "en-GB");
131+
}).pipe(Effect.provide(ElectronApp.layer)),
132+
);
133+
114134
it.effect("reports which app metadata property failed", () =>
115135
Effect.gen(function* () {
116136
const cause = new Error("version unavailable");

‎apps/desktop/src/electron/ElectronApp.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ export class ElectronApp extends Context.Service<
4343
{
4444
readonly metadata: Effect.Effect<ElectronAppMetadata, ElectronAppMetadataReadError>;
4545
readonly name: Effect.Effect<string>;
46+
/**
47+
* The OS locale, read from the operating system rather than from Chromium's
48+
* resolved application locale — the packaged app ships only the `en-US`
49+
* locale pak, so `app.getLocale()` and the renderer's `Intl` default are
50+
* pinned to `en-US` however the machine is configured.
51+
*/
52+
readonly systemLocale: Effect.Effect<string>;
4653
readonly whenReady: Effect.Effect<void, ElectronAppWhenReadyError>;
4754
readonly quit: Effect.Effect<void>;
4855
readonly exit: (code: number) => Effect.Effect<void>;
@@ -119,6 +126,10 @@ export const make = ElectronApp.of({
119126
};
120127
}),
121128
name: Effect.sync(() => Electron.app.name),
129+
// macOS derives this from NSLocale, which uses POSIX-style identifiers
130+
// (`en_GB`). `Intl` rejects those outright rather than normalizing them, so
131+
// the tag is normalized here rather than in the renderer that consumes it.
132+
systemLocale: Effect.sync(() => Electron.app.getSystemLocale().replace(/_/g, "-")),
122133
whenReady: Effect.gen(function* () {
123134
const isPackaged = Electron.app.isPackaged;
124135
yield* Effect.tryPromise({

‎apps/desktop/src/ipc/DesktopIpcHandlers.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
getAppBranding,
3535
getLocalEnvironmentBootstraps,
3636
getLocalEnvironmentBearerToken,
37+
getSystemLocale,
3738
getWindowFullscreenState,
3839
openExternal,
3940
probeRemoteEditors,
@@ -50,6 +51,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
5051
yield* PreviewIpc.installPreviewEventForwarding();
5152

5253
yield* ipc.handleSync(getAppBranding);
54+
yield* ipc.handleSync(getSystemLocale);
5355
yield* ipc.handleSync(getWindowFullscreenState);
5456
yield* ipc.handleSync(getLocalEnvironmentBootstraps);
5557
yield* ipc.handle(getLocalEnvironmentBearerToken);

‎apps/desktop/src/ipc/channels.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const UPDATE_DOWNLOAD_CHANNEL = "desktop:update-download";
1515
export const UPDATE_INSTALL_CHANNEL = "desktop:update-install";
1616
export const UPDATE_CHECK_CHANNEL = "desktop:update-check";
1717
export const GET_APP_BRANDING_CHANNEL = "desktop:get-app-branding";
18+
export const GET_SYSTEM_LOCALE_CHANNEL = "desktop:get-system-locale";
1819
export const GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL = "desktop:get-local-environment-bootstraps";
1920
export const GET_LOCAL_ENVIRONMENT_BEARER_TOKEN_CHANNEL =
2021
"desktop:get-local-environment-bearer-token";

‎apps/desktop/src/ipc/methods/window.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts";
2626
import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
2727
import * as DesktopWslBackend from "../../wsl/DesktopWslBackend.ts";
2828
import * as DesktopWslEnvironment from "../../wsl/DesktopWslEnvironment.ts";
29+
import * as ElectronApp from "../../electron/ElectronApp.ts";
2930
import * as ElectronDialog from "../../electron/ElectronDialog.ts";
3031
import * as ElectronMenu from "../../electron/ElectronMenu.ts";
3132
import * as ElectronShell from "../../electron/ElectronShell.ts";
@@ -64,6 +65,15 @@ export const getAppBranding = DesktopIpc.makeSyncIpcMethod({
6465
}),
6566
});
6667

68+
export const getSystemLocale = DesktopIpc.makeSyncIpcMethod({
69+
channel: IpcChannels.GET_SYSTEM_LOCALE_CHANNEL,
70+
result: Schema.String,
71+
handler: Effect.fn("desktop.ipc.window.getSystemLocale")(function* () {
72+
const electronApp = yield* ElectronApp.ElectronApp;
73+
return yield* electronApp.systemLocale;
74+
}),
75+
});
76+
6777
export const getWindowFullscreenState = DesktopIpc.makeSyncIpcMethod({
6878
channel: IpcChannels.GET_WINDOW_FULLSCREEN_STATE_CHANNEL,
6979
result: Schema.Boolean,

‎apps/desktop/src/preload.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ contextBridge.exposeInMainWorld("desktopBridge", {
3535
}
3636
return result as ReturnType<DesktopBridge["getAppBranding"]>;
3737
},
38+
getSystemLocale: () => {
39+
const result = ipcRenderer.sendSync(IpcChannels.GET_SYSTEM_LOCALE_CHANNEL);
40+
return typeof result === "string" ? result : null;
41+
},
3842
getLocalEnvironmentBootstraps: () => {
3943
const result = ipcRenderer.sendSync(IpcChannels.GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL);
4044
if (!Array.isArray(result)) {

‎apps/desktop/src/telemetry/DesktopTelemetryPublisher.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function makeElectronAppLayer(
2626
return Layer.succeed(ElectronApp.ElectronApp, {
2727
metadata: Effect.die("unexpected metadata read"),
2828
name: Effect.succeed("T3 Code"),
29+
systemLocale: Effect.succeed("en-US"),
2930
whenReady: Effect.void,
3031
quit: Effect.void,
3132
exit: () => Effect.void,

‎apps/desktop/src/window/DesktopApplicationMenu.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const environmentInput = {
3131
const electronAppLayer = Layer.succeed(ElectronApp.ElectronApp, {
3232
metadata: Effect.die("unexpected metadata read"),
3333
name: Effect.succeed("T3 Code"),
34+
systemLocale: Effect.succeed("en-US"),
3435
whenReady: Effect.void,
3536
quit: Effect.void,
3637
exit: () => Effect.void,

0 commit comments

Comments
 (0)