| 1 | import * as Electron from "electron"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Option from "effect/Option"; |
| 4 | import * as Schema from "effect/Schema"; |
| 5 | |
| 6 | import * as DesktopLegacyLocalStorage from "../../app/DesktopLegacyLocalStorage.ts"; |
| 7 | import * as IpcChannels from "../channels.ts"; |
| 8 | import { makeIpcMethod, makeSyncIpcMethod } from "../DesktopIpc.ts"; |
| 9 | |
| 10 | export const takeLegacyLocalStorage = makeSyncIpcMethod({ |
| 11 | channel: IpcChannels.TAKE_LEGACY_LOCAL_STORAGE_CHANNEL, |
| 12 | result: Schema.NullOr(Schema.Record(Schema.String, Schema.String)), |
| 13 | handler: Effect.fn("desktop.ipc.legacyLocalStorage.take")(function* () { |
| 14 | const legacy = yield* DesktopLegacyLocalStorage.DesktopLegacyLocalStorage; |
| 15 | return Option.getOrNull(yield* legacy.take); |
| 16 | }), |
| 17 | }); |
| 18 | |
| 19 | export const completeLegacyLocalStorage = makeIpcMethod({ |
| 20 | channel: IpcChannels.COMPLETE_LEGACY_LOCAL_STORAGE_CHANNEL, |
| 21 | payload: Schema.Void, |
| 22 | result: Schema.Void, |
| 23 | handler: Effect.fn("desktop.ipc.legacyLocalStorage.complete")(function* (_, event) { |
| 24 | const legacy = yield* DesktopLegacyLocalStorage.DesktopLegacyLocalStorage; |
| 25 | // Chromium writes localStorage to disk lazily; persist the merge before |
| 26 | // the marker stops later launches from retrying it. |
| 27 | if (event) Electron.webContents.fromId(event.sender.id)?.session.flushStorageData(); |
| 28 | yield* legacy.complete; |
| 29 | }), |
| 30 | }); |