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
8 changes: 5 additions & 3 deletions apps/desktop/scripts/dev-electron.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ const watchedDirectories = [
const forcedShutdownTimeoutMs = 1_500;
const restartDebounceMs = 120;
const childTreeGracePeriodMs = 1_200;
const remoteDebuggingPort = process.env.T3CODE_DESKTOP_REMOTE_DEBUGGING_PORT?.trim();
const remoteDebuggingPort =
process.env.M3CODE_DESKTOP_REMOTE_DEBUGGING_PORT?.trim() ||
process.env.T3CODE_DESKTOP_REMOTE_DEBUGGING_PORT?.trim();
// oxlint-disable-next-line t3code/no-global-process-runtime -- Standalone dev script has no Effect runtime.
const hostPlatform = NodeOS.platform();
const parentPid = process.ppid;
Expand Down Expand Up @@ -79,8 +81,8 @@ const childEnv = { ...process.env };
delete childEnv.ELECTRON_RUN_AS_NODE;
const devProtocolClient = resolveDevProtocolClient();
if (devProtocolClient) {
childEnv.T3CODE_DESKTOP_APP_USER_MODEL_ID = devProtocolClient.appBundleId;
childEnv.T3CODE_DESKTOP_PROTOCOL_REGISTRATION_MANAGED = "1";
childEnv.M3CODE_DESKTOP_APP_USER_MODEL_ID = devProtocolClient.appBundleId;
childEnv.M3CODE_DESKTOP_PROTOCOL_REGISTRATION_MANAGED = "1";
}

let shuttingDown = false;
Expand Down
14 changes: 7 additions & 7 deletions apps/desktop/scripts/electron-launcher.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const devBundleIdSuffix = NodePath.basename(repoRoot)
.replaceAll(/[^a-z0-9]+/g, "");
const APP_DISPLAY_NAME = isDevelopment ? "M3 Code (Dev)" : "M3 Code (Beta)";
const APP_BUNDLE_ID = isDevelopment
? `com.t3tools.t3code.dev.${devBundleIdSuffix || "local"}`
: "com.t3tools.t3code";
const APP_PROTOCOL_SCHEMES = isDevelopment ? ["t3code-dev"] : ["t3code"];
? `com.m3code.m3code.dev.${devBundleIdSuffix || "local"}`
: "com.m3code.m3code";
const APP_PROTOCOL_SCHEMES = isDevelopment ? ["m3code-dev", "t3code-dev"] : ["m3code", "t3code"];
const LAUNCHER_VERSION = 21;
const developmentMacIconPngPath = NodePath.join(
repoRoot,
Expand Down Expand Up @@ -109,10 +109,10 @@ function shellSingleQuote(value) {
export function makeDevelopmentEnvironmentScript(environment) {
const envEntries = [
["VITE_DEV_SERVER_URL", environment.VITE_DEV_SERVER_URL],
["T3CODE_PORT", environment.T3CODE_PORT],
["T3CODE_HOME", environment.T3CODE_HOME],
["T3CODE_COMMIT_HASH", environment.T3CODE_COMMIT_HASH],
["T3CODE_DESKTOP_APP_USER_MODEL_ID", APP_BUNDLE_ID],
["M3CODE_PORT", environment.M3CODE_PORT ?? environment.T3CODE_PORT],
["M3CODE_HOME", environment.M3CODE_HOME ?? environment.T3CODE_HOME],
["M3CODE_COMMIT_HASH", environment.M3CODE_COMMIT_HASH ?? environment.T3CODE_COMMIT_HASH],
["M3CODE_DESKTOP_APP_USER_MODEL_ID", APP_BUNDLE_ID],
].filter((entry) => typeof entry[1] === "string" && entry[1].trim().length > 0);
return [
...envEntries.map(
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/scripts/electron-launcher.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("electron development launcher", () => {
);
assert.include(
environmentScript,
"if [ -z \"${T3CODE_COMMIT_HASH:-}\" ]; then export T3CODE_COMMIT_HASH='abc123'; fi",
"if [ -z \"${M3CODE_COMMIT_HASH:-}\" ]; then export M3CODE_COMMIT_HASH='abc123'; fi",
);
assert.notInclude(environmentScript, "\nexport VITE_DEV_SERVER_URL=");
});
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/app/DesktopApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class DesktopDevelopmentBackendPortRequiredError extends Schema.TaggedErr
{},
) {
override get message(): string {
return "T3CODE_PORT is required in desktop development.";
return "M3CODE_PORT (or legacy T3CODE_PORT) is required in desktop development.";
}
}

Expand Down
75 changes: 59 additions & 16 deletions apps/desktop/src/app/DesktopConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,32 @@ const trimNonEmptyOption = (value: string): Option.Option<string> => {
export const trimmedString = (name: string) =>
Config.String(name).pipe(Config.option, Config.map(Option.flatMap(trimNonEmptyOption)));

const optionalBoolean = (name: string) =>
Config.Boolean(name).pipe(Config.option, Config.map(Option.getOrElse(() => false)));
export const trimmedStringWithLegacy = (primary: string, legacy: string) =>
Config.all([trimmedString(primary), trimmedString(legacy)]).pipe(
Config.map(([next, prev]) => Option.orElse(next, () => prev)),
);

const optionalBooleanWithLegacy = (primary: string, legacy: string) =>
Config.all([
Config.Boolean(primary).pipe(Config.option),
Config.Boolean(legacy).pipe(Config.option),
]).pipe(
Config.map(([next, prev]) =>
Option.getOrElse(
Option.orElse(next, () => prev),
() => false,
),
),
);

const optionalPortWithLegacy = (primary: string, legacy: string) =>
Config.all([
Config.Port(primary).pipe(Config.option),
Config.Port(legacy).pipe(Config.option),
]).pipe(Config.map(([next, prev]) => Option.orElse(next, () => prev)));

const commaSeparatedStrings = (name: string) =>
trimmedString(name).pipe(
const commaSeparatedStringsWithLegacy = (primary: string, legacy: string) =>
trimmedStringWithLegacy(primary, legacy).pipe(
Config.map(
Option.match({
onNone: () => [],
Expand All @@ -36,21 +57,43 @@ export const DesktopConfig = Config.all({
appDataDirectory: trimmedString("APPDATA"),
xdgConfigHome: trimmedString("XDG_CONFIG_HOME"),
xdgDataHome: trimmedString("XDG_DATA_HOME"),
t3Home: trimmedString("T3CODE_HOME"),
t3Home: trimmedStringWithLegacy("M3CODE_HOME", "T3CODE_HOME"),
devServerUrl: Config.URL("VITE_DEV_SERVER_URL").pipe(Config.option),
appUserModelIdOverride: trimmedString("T3CODE_DESKTOP_APP_USER_MODEL_ID"),
devRemoteT3ServerEntryPath: trimmedString("T3CODE_DEV_REMOTE_T3_SERVER_ENTRY_PATH"),
configuredBackendPort: Config.Port("T3CODE_PORT").pipe(Config.option),
commitHashOverride: trimmedString("T3CODE_COMMIT_HASH"),
desktopLanHostOverride: trimmedString("T3CODE_DESKTOP_LAN_HOST"),
desktopHttpsEndpointUrls: commaSeparatedStrings("T3CODE_DESKTOP_HTTPS_ENDPOINTS"),
desktopLauncherPath: trimmedString("T3CODE_DESKTOP_LAUNCHER_PATH"),
appUserModelIdOverride: trimmedStringWithLegacy(
"M3CODE_DESKTOP_APP_USER_MODEL_ID",
"T3CODE_DESKTOP_APP_USER_MODEL_ID",
),
devRemoteT3ServerEntryPath: trimmedStringWithLegacy(
"M3CODE_DEV_REMOTE_M3_SERVER_ENTRY_PATH",
"T3CODE_DEV_REMOTE_T3_SERVER_ENTRY_PATH",
),
configuredBackendPort: optionalPortWithLegacy("M3CODE_PORT", "T3CODE_PORT"),
commitHashOverride: trimmedStringWithLegacy("M3CODE_COMMIT_HASH", "T3CODE_COMMIT_HASH"),
desktopLanHostOverride: trimmedStringWithLegacy(
"M3CODE_DESKTOP_LAN_HOST",
"T3CODE_DESKTOP_LAN_HOST",
),
desktopHttpsEndpointUrls: commaSeparatedStringsWithLegacy(
"M3CODE_DESKTOP_HTTPS_ENDPOINTS",
"T3CODE_DESKTOP_HTTPS_ENDPOINTS",
),
desktopLauncherPath: trimmedStringWithLegacy(
"M3CODE_DESKTOP_LAUNCHER_PATH",
"T3CODE_DESKTOP_LAUNCHER_PATH",
),
appImagePath: trimmedString("APPIMAGE"),
disableAutoUpdate: optionalBoolean("T3CODE_DISABLE_AUTO_UPDATE"),
mockUpdates: optionalBoolean("T3CODE_DESKTOP_MOCK_UPDATES"),
mockUpdateServerPort: Config.Port("T3CODE_DESKTOP_MOCK_UPDATE_SERVER_PORT").pipe(
Config.withDefault(3000),
disableAutoUpdate: optionalBooleanWithLegacy(
"M3CODE_DISABLE_AUTO_UPDATE",
"T3CODE_DISABLE_AUTO_UPDATE",
),
mockUpdates: optionalBooleanWithLegacy(
"M3CODE_DESKTOP_MOCK_UPDATES",
"T3CODE_DESKTOP_MOCK_UPDATES",
),
mockUpdateServerPort: optionalPortWithLegacy(
"M3CODE_DESKTOP_MOCK_UPDATE_SERVER_PORT",
"T3CODE_DESKTOP_MOCK_UPDATE_SERVER_PORT",
).pipe(Config.map(Option.getOrElse(() => 3000))),
});

export const layerTest = (env: Readonly<Record<string, string | undefined>>) =>
Expand Down
9 changes: 7 additions & 2 deletions apps/desktop/src/app/DesktopEarlyElectronStartup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface EarlyDesktopSettingsInput {
readonly homeDirectory: string;
readonly joinPath: JoinPath;
readonly readFileString: (path: string) => string;
readonly pathExists?: (path: string) => boolean;
}

type EarlyLinuxElectronOptionsInput = EarlyDesktopSettingsInput;
Expand All @@ -31,7 +32,7 @@ export interface EarlyLinuxElectronOptions {
}

export const resolveLinuxDesktopEntryName = (isDevelopment: boolean): string =>
isDevelopment ? "com.t3tools.T3Code.Development.desktop" : "com.t3tools.T3Code.desktop";
isDevelopment ? "com.m3code.M3Code.Development.desktop" : "com.m3code.M3Code.desktop";

const trimNonEmpty = (value: string | undefined): string | null => {
const trimmed = value?.trim();
Expand All @@ -52,12 +53,16 @@ function resolveEarlyDesktopSettingsPath(input: {
readonly env: NodeJS.ProcessEnv;
readonly homeDirectory: string;
readonly joinPath: JoinPath;
readonly pathExists?: (path: string) => boolean;
}): string {
const t3Home = Option.fromUndefinedOr(input.env.T3CODE_HOME);
const t3Home = Option.fromUndefinedOr(
trimNonEmpty(input.env.M3CODE_HOME) ?? trimNonEmpty(input.env.T3CODE_HOME) ?? undefined,
);
const baseDir = resolveDesktopBaseDir({
homeDirectory: input.homeDirectory,
joinPath: input.joinPath,
t3Home,
...(input.pathExists ? { pathExists: input.pathExists } : {}),
});
const stateDir = resolveDesktopStateDir({
baseDir,
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/app/DesktopEnvironment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ describe("DesktopEnvironment", () => {
);
const production = yield* makeEnvironment();

assert.equal(development.stateDir, "/Users/alice/.t3/dev");
assert.equal(production.stateDir, "/Users/alice/.t3/userdata");
assert.equal(development.stateDir, "/Users/alice/.m3/dev");
assert.equal(production.stateDir, "/Users/alice/.m3/userdata");
}),
);
});
16 changes: 15 additions & 1 deletion apps/desktop/src/app/DesktopEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
import * as Config from "effect/Config";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Path from "effect/Path";
Expand Down Expand Up @@ -149,10 +150,23 @@ const make = Effect.fn("desktop.environment.make")(function* (
: input.platform === "darwin"
? path.join(homeDirectory, "Library", "Application Support")
: Option.getOrElse(config.xdgConfigHome, () => path.join(homeDirectory, ".config"));
const maybeFileSystem = yield* Effect.serviceOption(FileSystem.FileSystem);
const m3Dir = path.join(homeDirectory, ".m3");
const legacyT3Dir = path.join(homeDirectory, ".t3");
const existingPaths = new Set<string>();
if (Option.isNone(config.t3Home) && Option.isSome(maybeFileSystem)) {
const fs = maybeFileSystem.value;
if (yield* fs.exists(m3Dir).pipe(Effect.orElseSucceed(() => false))) {
existingPaths.add(m3Dir);
} else if (yield* fs.exists(legacyT3Dir).pipe(Effect.orElseSucceed(() => false))) {
existingPaths.add(legacyT3Dir);
}
}
const baseDir = resolveDesktopBaseDir({
homeDirectory,
joinPath: path.join,
t3Home: config.t3Home,
pathExists: (candidate) => existingPaths.has(candidate),
});
const rootDir = path.resolve(input.dirname, "../../..");
const appRoot = input.isPackaged ? input.appPath : rootDir;
Expand Down Expand Up @@ -215,7 +229,7 @@ const make = Effect.fn("desktop.environment.make")(function* (
branding,
displayName,
appUserModelId: Option.getOrElse(config.appUserModelIdOverride, () =>
isDevelopment ? "com.t3tools.t3code.dev" : "com.t3tools.t3code",
isDevelopment ? "com.m3code.m3code.dev" : "com.m3code.m3code",
),
linuxDesktopEntryName: resolveLinuxDesktopEntryName(isDevelopment),
linuxApplicationsDir,
Expand Down
12 changes: 6 additions & 6 deletions apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe("DesktopPreReadyPlatform", () => {
let desktopEntry = previousEntry;
let iconInstalled = false;
const iconSource = "/tmp/.mount_T3/resources/app.asar/apps/desktop/prod-resources/icon.png";
const iconPath = "/xdg/icons/com.t3tools.T3Code.desktop.png";
const iconPath = "/xdg/icons/com.m3code.M3Code.desktop.png";
const iconBytes = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
readFileSyncMock.mockImplementation((path: string) => {
if (path === iconSource) return iconBytes;
Expand All @@ -144,7 +144,7 @@ describe("DesktopPreReadyPlatform", () => {
desktopName = name;
});
writeFileSyncMock.mockImplementation((path: string, contents: string | Buffer) => {
if (path === "/xdg/applications/com.t3tools.T3Code.desktop") desktopEntry = String(contents);
if (path === "/xdg/applications/com.m3code.M3Code.desktop") desktopEntry = String(contents);
if (path === iconPath) iconInstalled = Buffer.compare(Buffer.from(contents), iconBytes) === 0;
});

Expand All @@ -167,13 +167,13 @@ describe("DesktopPreReadyPlatform", () => {
),
);
const identity = yield* Effect.promise(() => portalIdentity);
assert.equal(identity.desktopName, "com.t3tools.T3Code.desktop");
assert.equal(identity.desktopName, "com.m3code.M3Code.desktop");
assert.include(identity.desktopEntry ?? "", "Exec=/Applications/current.AppImage %U");
assert.include(identity.desktopEntry ?? "", "Name=M3 Code (Beta)");
assert.include(identity.desktopEntry ?? "", "MimeType=x-scheme-handler/t3code;");
assert.include(
identity.desktopEntry ?? "",
"Icon=/xdg/icons/com.t3tools.T3Code.desktop.png",
"Icon=/xdg/icons/com.m3code.M3Code.desktop.png",
);
assert.equal(
copyFileSyncMock.mock.calls.length,
Expand All @@ -193,7 +193,7 @@ describe("DesktopPreReadyPlatform", () => {
({ relaunchedByUpdater, restored }) => {
vi.stubEnv("VITE_DEV_SERVER_URL", "");
getSwitchValueMock.mockReturnValue("");
const entryPath = "/xdg/applications/com.t3tools.T3Code.desktop";
const entryPath = "/xdg/applications/com.m3code.M3Code.desktop";
const files = new Map([[entryPath, "Exec=/Applications/T3-Code-0.1.8-x86_64.AppImage %U\n"]]);
readFileSyncMock.mockImplementation((path: string) => files.get(path) ?? "{}");
writeFileSyncMock.mockImplementation((path: string, contents: string | Buffer) => {
Expand Down Expand Up @@ -245,7 +245,7 @@ describe("DesktopPreReadyPlatform", () => {
),
);
const entry = writeFileSyncMock.mock.calls.find(
([path]) => path === "/xdg/applications/com.t3tools.T3Code.desktop",
([path]) => path === "/xdg/applications/com.m3code.M3Code.desktop",
)?.[1];
assert.include(entry, 'Exec="/opt/M3 Code/t3code" %U');
}),
Expand Down
21 changes: 19 additions & 2 deletions apps/desktop/src/app/DesktopPreReadyPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as Electron from "electron";
import * as HostProcess from "@t3tools/shared/HostProcess";

import * as DesktopEarlyElectronStartup from "./DesktopEarlyElectronStartup.ts";
import { trimmedString } from "./DesktopConfig.ts";
import { trimmedString, trimmedStringWithLegacy } from "./DesktopConfig.ts";
import { resolveDesktopAppBranding } from "./DesktopEnvironment.ts";
import {
renderUrlHandlerDesktopEntry,
Expand Down Expand Up @@ -45,6 +45,13 @@ export const resolveEarlyLinuxElectronOptionsFromProcess = (
homeDirectory,
joinPath: NodePath.posix.join,
readFileString: (path) => NodeFS.readFileSync(path, "utf8"),
pathExists: (path) => {
try {
return typeof NodeFS.existsSync === "function" && NodeFS.existsSync(path);
} catch {
return false;
}
},
});

export class DesktopPreReadyElectronOptions extends Context.Service<
Expand All @@ -57,7 +64,10 @@ export class DesktopPreReadyElectronOptions extends Context.Service<

const LinuxDesktopEntryConfig = Config.all({
xdgDataHome: trimmedString("XDG_DATA_HOME"),
launcherPath: trimmedString("T3CODE_DESKTOP_LAUNCHER_PATH"),
launcherPath: trimmedStringWithLegacy(
"M3CODE_DESKTOP_LAUNCHER_PATH",
"T3CODE_DESKTOP_LAUNCHER_PATH",
),
appImagePath: trimmedString("APPIMAGE"),
// electron-updater sets this on the AppImage it relaunches after installing an update.
relaunchedByUpdater: trimmedString("APPIMAGE_SILENT_INSTALL"),
Expand All @@ -83,6 +93,13 @@ export const make = Effect.gen(function* () {
joinPath: NodePath.posix.join,
commandLine: Electron.app.commandLine,
readFileString: (path) => NodeFS.readFileSync(path, "utf8"),
pathExists: (path) => {
try {
return typeof NodeFS.existsSync === "function" && NodeFS.existsSync(path);
} catch {
return false;
}
},
writeFileString: (path, value) => {
NodeFS.mkdirSync(NodePath.posix.dirname(path), { recursive: true });
NodeFS.writeFileSync(path, value, "utf8");
Expand Down
16 changes: 13 additions & 3 deletions apps/desktop/src/app/DesktopStatePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ function normalizeConfiguredBaseDir(t3Home: Option.Option<string>): Option.Optio
return trimmed.length > 0 ? Option.some(trimmed) : Option.none();
}

/**
* Resolves the desktop base dir: explicit `M3CODE_HOME`/`T3CODE_HOME`, else `~/.m3`,
* falling back to legacy `~/.t3` when `~/.m3` does not exist yet and `~/.t3` exists.
*/
export function resolveDesktopBaseDir(input: {
readonly homeDirectory: string;
readonly joinPath: JoinPath;
readonly t3Home: Option.Option<string>;
readonly pathExists?: (path: string) => boolean;
}): string {
return Option.getOrElse(normalizeConfiguredBaseDir(input.t3Home), () =>
input.joinPath(input.homeDirectory, ".t3"),
);
return Option.getOrElse(normalizeConfiguredBaseDir(input.t3Home), () => {
const m3Dir = input.joinPath(input.homeDirectory, ".m3");
const legacyT3Dir = input.joinPath(input.homeDirectory, ".t3");
if (input.pathExists && !input.pathExists(m3Dir) && input.pathExists(legacyT3Dir)) {
return legacyT3Dir;
}
return m3Dir;
});
}

export function resolveDesktopStateDir(input: {
Expand Down
Loading
Loading