Skip to content
Merged
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
3 changes: 3 additions & 0 deletions apps/desktop/src/ipc/DesktopIpcHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
setServerExposureMode,
setTailscaleServeEnabled,
} from "./methods/serverExposure.ts";
import { importT3Settings, previewT3SettingsImport } from "./methods/lastCodeSettings.ts";
import {
bootstrapSshBearerSession,
disconnectSshEnvironment,
Expand Down Expand Up @@ -88,6 +89,8 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
yield* ipc.handle(getUpdateState);
yield* ipc.handle(getLastCodeSettings);
yield* ipc.handle(setShowAndInstallLocalNightlies);
yield* ipc.handle(previewT3SettingsImport);
yield* ipc.handle(importT3Settings);
yield* ipc.handle(setUpdateChannel);
yield* ipc.handle(downloadUpdate);
yield* ipc.handle(installUpdate);
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/ipc/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const UPDATE_CHECK_CHANNEL = "desktop:update-check";
export const LASTCODE_SETTINGS_GET_CHANNEL = "desktop:lastcode-settings-get";
export const LASTCODE_SETTINGS_SET_LOCAL_NIGHTLIES_CHANNEL =
"desktop:lastcode-settings-set-local-nightlies";
export const LASTCODE_SETTINGS_IMPORT_PREVIEW_CHANNEL = "desktop:lastcode-settings-import-preview";
export const LASTCODE_SETTINGS_IMPORT_CHANNEL = "desktop:lastcode-settings-import";
export const GET_APP_BRANDING_CHANNEL = "desktop:get-app-branding";
export const GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL = "desktop:get-local-environment-bootstraps";
export const GET_LOCAL_ENVIRONMENT_BEARER_TOKEN_CHANNEL =
Expand Down
75 changes: 75 additions & 0 deletions apps/desktop/src/ipc/methods/lastCodeSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {
LastCodeSettingsImportPreviewSchema,
LastCodeSettingsImportResultSchema,
} from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";

import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts";
import * as DesktopLifecycle from "../../app/DesktopLifecycle.ts";
import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
import {
importT3Settings as importT3SettingsFiles,
isT3SettingsImportSupported,
previewT3SettingsImport as previewT3SettingsImportFiles,
type LastCodeSettingsImportPaths,
} from "../../settings/LastCodeSettingsImport.ts";
import * as IpcChannels from "../channels.ts";
import * as DesktopIpc from "../DesktopIpc.ts";

function resolveImportPaths(
environment: DesktopEnvironment.DesktopEnvironment["Service"],
): LastCodeSettingsImportPaths {
return {
sourceDirectory: environment.path.join(environment.homeDirectory, ".t3", "userdata"),
destinationDirectory: environment.stateDir,
Comment thread
lastobelus marked this conversation as resolved.
backupRootDirectory: environment.path.join(environment.baseDir, "settings-import-backups"),
};
}

const WSL_ONLY_IMPORT_MESSAGE =
"Import is unavailable while WSL-only mode is selected. Disable WSL-only mode before importing the Windows profile.";

class LastCodeSettingsImportUnavailableError extends Schema.TaggedErrorClass<LastCodeSettingsImportUnavailableError>()(
"LastCodeSettingsImportUnavailableError",
{ reason: Schema.String },
) {
override get message(): string {
return this.reason;
}
}

export const previewT3SettingsImport = DesktopIpc.makeIpcMethod({
channel: IpcChannels.LASTCODE_SETTINGS_IMPORT_PREVIEW_CHANNEL,
payload: Schema.Void,
result: LastCodeSettingsImportPreviewSchema,
handler: Effect.fn("desktop.ipc.lastCodeSettings.previewImport")(function* () {
const environment = yield* DesktopEnvironment.DesktopEnvironment;
const appSettings = yield* DesktopAppSettings.DesktopAppSettings;
const preview = yield* Effect.tryPromise(() =>
previewT3SettingsImportFiles(resolveImportPaths(environment)),
);
return !isT3SettingsImportSupported(environment.platform, (yield* appSettings.get).wslOnly)
Comment thread
lastobelus marked this conversation as resolved.
? { ...preview, canImport: false, message: WSL_ONLY_IMPORT_MESSAGE }
: preview;
}),
});

export const importT3Settings = DesktopIpc.makeIpcMethod({
channel: IpcChannels.LASTCODE_SETTINGS_IMPORT_CHANNEL,
payload: Schema.Void,
result: LastCodeSettingsImportResultSchema,
handler: Effect.fn("desktop.ipc.lastCodeSettings.import")(function* () {
const environment = yield* DesktopEnvironment.DesktopEnvironment;
const appSettings = yield* DesktopAppSettings.DesktopAppSettings;
if (!isT3SettingsImportSupported(environment.platform, (yield* appSettings.get).wslOnly)) {
return yield* new LastCodeSettingsImportUnavailableError({ reason: WSL_ONLY_IMPORT_MESSAGE });
}
const result = yield* Effect.tryPromise(() =>
importT3SettingsFiles(resolveImportPaths(environment)),
);
const lifecycle = yield* DesktopLifecycle.DesktopLifecycle;
yield* lifecycle.relaunch("t3-settings-imported");
return result;
}),
});
3 changes: 3 additions & 0 deletions apps/desktop/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ contextBridge.exposeInMainWorld("desktopBridge", {
getLastCodeSettings: () => ipcRenderer.invoke(IpcChannels.LASTCODE_SETTINGS_GET_CHANNEL),
setShowAndInstallLocalNightlies: (enabled) =>
ipcRenderer.invoke(IpcChannels.LASTCODE_SETTINGS_SET_LOCAL_NIGHTLIES_CHANNEL, enabled),
previewT3SettingsImport: () =>
ipcRenderer.invoke(IpcChannels.LASTCODE_SETTINGS_IMPORT_PREVIEW_CHANNEL),
importT3Settings: () => ipcRenderer.invoke(IpcChannels.LASTCODE_SETTINGS_IMPORT_CHANNEL),
setUpdateChannel: (channel) =>
ipcRenderer.invoke(IpcChannels.UPDATE_SET_CHANNEL_CHANNEL, channel),
checkForUpdate: () => ipcRenderer.invoke(IpcChannels.UPDATE_CHECK_CHANNEL),
Expand Down
Loading