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
29 changes: 29 additions & 0 deletions apps/desktop/src/app/DesktopLinuxUrlHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,35 @@ describe("DesktopLinuxUrlHandler", () => {
assert.include(entry, "Icon=/home/al ice/icons/T3\\\\x.png");
});

it.each([
{ from: "T3-Code-0.1.8-x86_64.AppImage", to: "T3-Code-x86_64.AppImage", restored: true },
{
from: "T3-Code-0.1.9-nightly.20261110.4449-arm64.AppImage",
to: "T3-Code-Nightly-arm64.AppImage",
restored: true,
},
{ from: "T3-Code-0.1.8-x86_64.AppImage", to: "T3-Code-0.1.9-x86_64.AppImage", restored: false },
{ from: "t3code.AppImage", to: "T3-Code-x86_64.AppImage", restored: false },
{ from: "T3-Code-x86_64.AppImage", to: "T3-Code-x86_64.AppImage", restored: false },
{ from: "../T3-Code-0.1.8-x86_64.AppImage", to: "T3-Code-x86_64.AppImage", restored: false },
])("finds the launch path an update from $from to $to removed", ({ from, to, restored }) => {
for (const dir of ["/home/alice/Applications", '/home/al ice/My "100%" $Apps\\x']) {
const previous = dir + "/" + from;
const previousEntry = DesktopLinuxUrlHandler.renderUrlHandlerDesktopEntry({
displayName: "T3 Code (Beta)",
execTarget: previous,
scheme: "t3code",
});
assert.equal(
DesktopLinuxUrlHandler.replacedVersionedAppImagePath({
previousEntry,
appImagePath: dir + "/" + to,
}),
restored ? previous : null,
);
}
});

it.effect(
"writes the handler entry, refreshes the MIME cache, and claims the scheme default",
() => {
Expand Down
32 changes: 32 additions & 0 deletions apps/desktop/src/app/DesktopLinuxUrlHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,38 @@ export function renderUrlHandlerDesktopEntry(input: {
].join("\n");
}

function parseUrlHandlerExecTarget(entry: string): string | null {
const exec = /^Exec=(.*) %U$/mu.exec(entry)?.[1];
if (exec === undefined) return null;
const unescaped = exec.replace(/\\([\\nrt])/gu, (_, char: string) =>
char === "n" ? "\n" : char === "r" ? "\r" : char === "t" ? "\t" : char,
);
const quoted = /^"(.*)"$/su.exec(unescaped)?.[1];
return (
quoted === undefined ? unescaped : quoted.replace(/\\([\\`$"])/gu, (_, char: string) => char)
).replaceAll("%%", "%");
}

const APPIMAGE_NAME_VERSION = /\d+\.\d+\.\d+/u;

// An updater from before version-free AppImage names deletes its own file and installs the update
// beside it under the new name. The previous launch's entry still names the path launchers use.
export function replacedVersionedAppImagePath(input: {
readonly previousEntry: string;
readonly appImagePath: string;
}): string | null {
const previous = parseUrlHandlerExecTarget(input.previousEntry);
if (previous === null) return null;
const previousName = previous.slice(previous.lastIndexOf("/") + 1);
const currentName = input.appImagePath.slice(input.appImagePath.lastIndexOf("/") + 1);
return previous.startsWith("/") &&
previous.slice(0, -previousName.length) === input.appImagePath.slice(0, -currentName.length) &&
APPIMAGE_NAME_VERSION.test(previousName) &&
!APPIMAGE_NAME_VERSION.test(currentName)
? previous
: null;
}

// Docks may look up the Wayland app id without a desktop entry; icon theme lookups are case-sensitive.
const LINUX_THEME_ICON_SIZE = "256x256";

Expand Down
45 changes: 45 additions & 0 deletions apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
copyFileSyncMock,
execFileSyncMock,
readFileSyncMock,
symlinkSyncMock,
} = vi.hoisted(() => ({
appendSwitchMock: vi.fn(),
getSwitchValueMock: vi.fn(),
Expand All @@ -27,6 +28,7 @@ const {
copyFileSyncMock: vi.fn(),
execFileSyncMock: vi.fn(),
readFileSyncMock: vi.fn(),
symlinkSyncMock: vi.fn(),
}));

vi.mock("electron", () => ({
Expand All @@ -51,6 +53,7 @@ vi.mock("node:fs", () => ({
mkdirSync: mkdirSyncMock,
writeFileSync: writeFileSyncMock,
copyFileSync: copyFileSyncMock,
symlinkSync: symlinkSyncMock,
}));

vi.mock("node:child_process", () => ({
Expand All @@ -72,6 +75,7 @@ describe("DesktopPreReadyPlatform", () => {
copyFileSyncMock.mockReset();
execFileSyncMock.mockReset();
readFileSyncMock.mockReset().mockReturnValue("{}");
symlinkSyncMock.mockReset();
});

it.effect("persists Linux scaling synchronously across relaunches and settings rewrites", () => {
Expand Down Expand Up @@ -181,6 +185,47 @@ describe("DesktopPreReadyPlatform", () => {
).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs())));
});

it.effect.each([
{ relaunchedByUpdater: "true", restored: true },
{ relaunchedByUpdater: "", restored: false },
])(
"restores the versioned AppImage path an update removed (updater relaunch: $relaunchedByUpdater)",
({ relaunchedByUpdater, restored }) => {
vi.stubEnv("VITE_DEV_SERVER_URL", "");
getSwitchValueMock.mockReturnValue("");
const entryPath = "/xdg/applications/com.t3tools.T3Code.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) => {
files.set(path, String(contents));
});

return Effect.scoped(
Effect.gen(function* () {
yield* Layer.build(
DesktopPreReadyPlatform.layer.pipe(
Layer.provide(Layer.succeed(HostProcess.Platform, "linux")),
Layer.provide(
DesktopConfig.layerTest({
XDG_DATA_HOME: "/xdg",
APPIMAGE: "/Applications/T3-Code-x86_64.AppImage",
APPIMAGE_SILENT_INSTALL: relaunchedByUpdater,
}),
),
),
);
assert.deepEqual(
symlinkSyncMock.mock.calls,
restored
? [["T3-Code-x86_64.AppImage", "/Applications/T3-Code-0.1.8-x86_64.AppImage"]]
: [],
);
assert.include(files.get(entryPath), "Exec=/Applications/T3-Code-x86_64.AppImage %U");
}),
).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs())));
},
);

it.effect("points the early portal entry at a configured distribution launcher", () => {
vi.stubEnv("VITE_DEV_SERVER_URL", "");
getSwitchValueMock.mockReturnValue("");
Expand Down
27 changes: 25 additions & 2 deletions apps/desktop/src/app/DesktopPreReadyPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
import * as DesktopEarlyElectronStartup from "./DesktopEarlyElectronStartup.ts";
import { trimmedString } from "./DesktopConfig.ts";
import { resolveDesktopAppBranding } from "./DesktopEnvironment.ts";
import { renderUrlHandlerDesktopEntry } from "./DesktopLinuxUrlHandler.ts";
import {
renderUrlHandlerDesktopEntry,
replacedVersionedAppImagePath,
} from "./DesktopLinuxUrlHandler.ts";
import * as ElectronProtocol from "../electron/ElectronProtocol.ts";

export interface DesktopPreReadyCommandLineReader {
Expand Down Expand Up @@ -56,6 +59,8 @@ const LinuxDesktopEntryConfig = Config.all({
xdgDataHome: trimmedString("XDG_DATA_HOME"),
launcherPath: trimmedString("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"),
});

/** @public */
Expand Down Expand Up @@ -116,8 +121,26 @@ export const make = Effect.gen(function* () {
);
} catch {}
}
const desktopEntryPath = NodePath.posix.join(applicationsDir, linux.linuxDesktopEntryName);
const { appImagePath } = linuxDesktopEntryConfig;
if (
Option.isSome(appImagePath) &&
Option.isNone(linuxDesktopEntryConfig.launcherPath) &&
Option.contains(linuxDesktopEntryConfig.relaunchedByUpdater, "true")
) {
try {
const replacedPath = replacedVersionedAppImagePath({
previousEntry: NodeFS.readFileSync(desktopEntryPath, "utf8"),
appImagePath: appImagePath.value,
});
// Relative, so the pair survives a moved folder; symlink never overwrites a file.
if (replacedPath !== null) {
NodeFS.symlinkSync(NodePath.posix.basename(appImagePath.value), replacedPath);
}
} catch {}
}
NodeFS.writeFileSync(
NodePath.posix.join(applicationsDir, linux.linuxDesktopEntryName),
desktopEntryPath,
renderUrlHandlerDesktopEntry({
displayName: resolveDesktopAppBranding({
isDevelopment: linux.isDevelopment,
Expand Down
16 changes: 11 additions & 5 deletions packaging/aur/scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@ pkgrel="${PKGREL:-1}"

if [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
pkgname='t3code-bin'
asset_name='T3-Code-x86_64.AppImage'
elif [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-nightly\.[0-9]{8}\.[0-9]+$ ]]; then
pkgname='t3code-nightly-bin'
asset_name='T3-Code-Nightly-x86_64.AppImage'
else
echo "Release $tag does not publish an AUR package."
exit 0
fi

version="${tag#v}"
pkgver="${version//-/_}"
asset_name="T3-Code-${version}-x86_64.AppImage"
release_json="$(gh api "repos/$repo/releases/tags/$tag")"
asset_digest="$(jq -r --arg name "$asset_name" \
'.assets[] | select(.name == $name) | .digest' <<<"$release_json")"
appimage_sha256="${asset_digest#sha256:}"
# Older releases publish the AppImage under a versioned name.
for asset_name in "$asset_name" "T3-Code-${version}-x86_64.AppImage"; do
asset_digest="$(jq -r --arg name "$asset_name" \
'.assets[] | select(.name == $name) | .digest' <<<"$release_json")"
appimage_sha256="${asset_digest#sha256:}"
[[ "$appimage_sha256" =~ ^[0-9a-f]{64}$ ]] && break
done

if [[ ! "$appimage_sha256" =~ ^[0-9a-f]{64}$ ]]; then
echo "Release $tag is missing $asset_name or its SHA-256 digest." >&2
echo "Release $tag is missing its x86_64 AppImage or its SHA-256 digest." >&2
exit 1
fi

Expand All @@ -39,6 +44,7 @@ cd "$package_dir"
sed -Ei \
-e "s/^pkgver=.*/pkgver=$pkgver/" \
-e "s/^pkgrel=.*/pkgrel=$pkgrel/" \
-e "s/^_asset=.*/_asset='$asset_name'/" \
-e "/# AppImage$/s/'[0-9a-f]{64}'/'$appimage_sha256'/" \
-e "/# upstream license$/s/'[0-9a-f]{64}'/'$license_sha256'/" \
PKGBUILD
Expand Down
3 changes: 2 additions & 1 deletion packaging/aur/t3code-bin/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ conflicts=('t3code')
options=('!debug' '!strip')

_appimage="T3-Code-${pkgver}-x86_64.AppImage"
_asset="$_appimage"
source=(
"$_appimage::https://github.com/pingdotgg/t3code/releases/download/v${pkgver}/$_appimage"
"$_appimage::https://github.com/pingdotgg/t3code/releases/download/v${pkgver}/$_asset"
"${pkgname}-${pkgver}-LICENSE::https://raw.githubusercontent.com/pingdotgg/t3code/v${pkgver}/LICENSE"
)
sha256sums=(
Expand Down
3 changes: 2 additions & 1 deletion packaging/aur/t3code-nightly-bin/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ options=('!debug' '!strip')

_upstream_version="${pkgver/_nightly./-nightly.}"
_appimage="T3-Code-${_upstream_version}-x86_64.AppImage"
_asset="$_appimage"
source=(
"$_appimage::https://github.com/pingdotgg/t3code/releases/download/v${_upstream_version}/$_appimage"
"$_appimage::https://github.com/pingdotgg/t3code/releases/download/v${_upstream_version}/$_asset"
"${pkgname}-${pkgver}-LICENSE::https://raw.githubusercontent.com/pingdotgg/t3code/v${_upstream_version}/LICENSE"
)
sha256sums=(
Expand Down
22 changes: 22 additions & 0 deletions scripts/build-desktop-artifact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,28 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
}),
);

it.effect("names updatable AppImages without a version and apart per channel", () =>
Effect.gen(function* () {
const appImageName = (version: string) =>
createBuildConfig("linux", "AppImage", version, false, false, undefined, undefined).pipe(
Effect.map((config) => (config.appImage as { artifactName: string }).artifactName),
);

const stable = yield* appImageName("0.0.37");
const nightly = yield* appImageName("0.0.38-nightly.20261026.3740");

assert.notInclude(stable, "${version}");
assert.notInclude(nightly, "${version}");
assert.notEqual(stable, nightly);
}).pipe(
Effect.provide(
ConfigProvider.layer(
ConfigProvider.fromEnv({ env: { GITHUB_REPOSITORY: "pingdotgg/t3code" } }),
),
),
),
);

it.effect("declares Calendar access for hosted commands in macOS builds", () =>
Effect.gen(function* () {
for (const version of ["0.1.0", "0.1.1-nightly.20261019.1"]) {
Expand Down
7 changes: 7 additions & 0 deletions scripts/build-desktop-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2926,6 +2926,13 @@ export const createBuildConfig = Effect.fn("createBuildConfig")(function* (
},
},
};
// electron-updater replaces an installed AppImage in place only when its name has no x.y.z version.
if (buildConfig.publish) {
buildConfig.appImage = {
artifactName:
updateChannel === "nightly" ? "T3-Code-Nightly-${arch}.${ext}" : "T3-Code-${arch}.${ext}",
};
}
buildConfig.deb = {
// FPM runs outside the staged app directory, so source paths must be absolute.
fpm: [
Expand Down
Loading