Skip to content
Open
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
1 change: 1 addition & 0 deletions apps/desktop/src/app/DesktopAppIdentity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const makeElectronAppLayer = (calls: ElectronAppCalls) =>
Layer.succeed(ElectronApp.ElectronApp, {
metadata: Effect.die("unexpected metadata read"),
name: Effect.succeed("T3 Code"),
preferredSystemLanguages: Effect.succeed(["en-US"]),
systemLocale: Effect.succeed("en-US"),
whenReady: Effect.void,
quit: Effect.void,
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/app/DesktopLifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function makeElectronAppLayer(
return Layer.succeed(ElectronApp.ElectronApp, {
metadata: Effect.die("unexpected metadata read"),
name: Effect.succeed("T3 Code"),
preferredSystemLanguages: Effect.succeed(["en-US"]),
systemLocale: Effect.succeed("en-US"),
whenReady: Effect.void,
quit,
Expand Down
11 changes: 11 additions & 0 deletions apps/desktop/src/electron/ElectronApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
autoUpdaterRemoveListenerMock,
exitMock,
getAppPathMock,
getPreferredSystemLanguagesMock,
getSystemLocaleMock,
getVersionMock,
isDefaultProtocolClientMock,
Expand All @@ -30,6 +31,7 @@ const {
autoUpdaterRemoveListenerMock: vi.fn(),
exitMock: vi.fn(),
getAppPathMock: vi.fn(() => "/app"),
getPreferredSystemLanguagesMock: vi.fn(() => ["pt_BR", "en-US"]),
getSystemLocaleMock: vi.fn(() => "en-GB"),
getVersionMock: vi.fn(() => "1.2.3"),
isDefaultProtocolClientMock: vi.fn(() => false),
Expand Down Expand Up @@ -62,6 +64,7 @@ vi.mock("electron", () => ({
setIcon: setDockIconMock,
},
getAppPath: getAppPathMock,
getPreferredSystemLanguages: getPreferredSystemLanguagesMock,
getSystemLocale: getSystemLocaleMock,
getVersion: getVersionMock,
isDefaultProtocolClient: isDefaultProtocolClientMock,
Expand Down Expand Up @@ -122,6 +125,14 @@ describe("ElectronApp", () => {
}).pipe(Effect.provide(ElectronApp.layer)),
);

it.effect("reads and normalizes the OS preferred languages", () =>
Effect.gen(function* () {
const electronApp = yield* ElectronApp.ElectronApp;

assert.deepEqual(yield* electronApp.preferredSystemLanguages, ["pt-BR", "en-US"]);
}).pipe(Effect.provide(ElectronApp.layer)),
);

it.effect("normalizes POSIX-style locale identifiers that Intl rejects", () =>
Effect.gen(function* () {
getSystemLocaleMock.mockImplementationOnce(() => "en_GB");
Expand Down
8 changes: 8 additions & 0 deletions apps/desktop/src/electron/ElectronApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export class ElectronApp extends Context.Service<
* pinned to `en-US` however the machine is configured.
*/
readonly systemLocale: Effect.Effect<string>;
/**
* The user's ordered OS language preferences, distinct from the regional
* locale. Keyboard input methods are discovered separately.
*/
readonly preferredSystemLanguages: Effect.Effect<readonly string[]>;
readonly whenReady: Effect.Effect<void, ElectronAppWhenReadyError>;
readonly quit: Effect.Effect<void>;
readonly exit: (code: number) => Effect.Effect<void>;
Expand Down Expand Up @@ -130,6 +135,9 @@ export const make = ElectronApp.of({
// (`en_GB`). `Intl` rejects those outright rather than normalizing them, so
// the tag is normalized here rather than in the renderer that consumes it.
systemLocale: Effect.sync(() => Electron.app.getSystemLocale().replace(/_/g, "-")),
preferredSystemLanguages: Effect.sync(() =>
Electron.app.getPreferredSystemLanguages().map((language) => language.replace(/_/g, "-")),
),
Comment thread
hevlyo marked this conversation as resolved.
whenReady: Effect.gen(function* () {
const isPackaged = Electron.app.isPackaged;
yield* Effect.tryPromise({
Expand Down
Loading
Loading