Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit f0c696d

Browse files
authored
Merge pull request #2281 from TriliumNext/fix/show-warning-when-rosetta-2
fix(client): show warning/error when app is using Rosetta 2 translation (running wrong arch)
2 parents c34c0c4 + 9713864 commit f0c696d

8 files changed

Lines changed: 154 additions & 1 deletion

File tree

apps/client/src/components/app_context.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import type { NativeImage, TouchBar } from "electron";
2828
import TouchBarComponent from "./touch_bar.js";
2929
import type { CKTextEditor } from "@triliumnext/ckeditor5";
3030
import type CodeMirror from "@triliumnext/codemirror";
31+
import { StartupChecks } from "./startup_checks.js";
3132

3233
interface Layout {
3334
getRootWidget: (appContext: AppContext) => RootWidget;
@@ -128,6 +129,7 @@ export type CommandMappings = {
128129
openAboutDialog: CommandData;
129130
hideFloatingButtons: {};
130131
hideLeftPane: CommandData;
132+
showCpuArchWarning: CommandData;
131133
showLeftPane: CommandData;
132134
hoistNote: CommandData & { noteId: string };
133135
leaveProtectedSession: CommandData;
@@ -473,7 +475,14 @@ export class AppContext extends Component {
473475
initComponents() {
474476
this.tabManager = new TabManager();
475477

476-
this.components = [this.tabManager, new RootCommandExecutor(), new Entrypoints(), new MainTreeExecutors(), new ShortcutComponent()];
478+
this.components = [
479+
this.tabManager,
480+
new RootCommandExecutor(),
481+
new Entrypoints(),
482+
new MainTreeExecutors(),
483+
new ShortcutComponent(),
484+
new StartupChecks()
485+
];
477486

478487
if (utils.isMobile()) {
479488
this.components.push(new MobileScreenSwitcherExecutor());
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import server from "../services/server";
2+
import Component from "./component";
3+
4+
// TODO: Deduplicate.
5+
interface CpuArchResponse {
6+
isCpuArchMismatch: boolean;
7+
}
8+
9+
export class StartupChecks extends Component {
10+
11+
constructor() {
12+
super();
13+
this.checkCpuArchMismatch();
14+
}
15+
16+
async checkCpuArchMismatch() {
17+
try {
18+
const response = await server.get("system-checks") as CpuArchResponse;
19+
if (response.isCpuArchMismatch) {
20+
this.triggerCommand("showCpuArchWarning", {});
21+
}
22+
} catch (error) {
23+
console.warn("Could not check CPU arch status:", error);
24+
}
25+
}
26+
}

apps/client/src/desktop.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import electronContextMenu from "./menus/electron_context_menu.js";
88
import glob from "./services/glob.js";
99
import { t } from "./services/i18n.js";
1010
import options from "./services/options.js";
11+
import server from "./services/server.js";
1112
import type ElectronRemote from "@electron/remote";
1213
import type Electron from "electron";
1314
import "./stylesheets/bootstrap.scss";

apps/client/src/layouts/layout_commons.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import ConfirmDialog from "../widgets/dialogs/confirm.js";
2121
import RevisionsDialog from "../widgets/dialogs/revisions.js";
2222
import DeleteNotesDialog from "../widgets/dialogs/delete_notes.js";
2323
import InfoDialog from "../widgets/dialogs/info.js";
24+
import IncorrectCpuArchDialog from "../widgets/dialogs/incorrect_cpu_arch.js";
2425

2526
export function applyModals(rootContainer: RootContainer) {
2627
rootContainer
@@ -45,4 +46,5 @@ export function applyModals(rootContainer: RootContainer) {
4546
.child(new InfoDialog())
4647
.child(new ConfirmDialog())
4748
.child(new PromptDialog())
49+
.child(new IncorrectCpuArchDialog())
4850
}

apps/client/src/translations/en/translation.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,5 +1918,14 @@
19181918
"title": "Appearance",
19191919
"word_wrapping": "Word wrapping",
19201920
"color-scheme": "Color scheme"
1921+
},
1922+
"cpu_arch_warning": {
1923+
"title": "Please download the ARM64 version",
1924+
"message_macos": "TriliumNext is currently running under Rosetta 2 translation, which means you're using the Intel (x64) version on Apple Silicon Mac. This will significantly impact performance and battery life.",
1925+
"message_windows": "TriliumNext is currently running emulation, which means you're using the Intel (x64) version on a Windows on ARM device. This will significantly impact performance and battery life.",
1926+
"recommendation": "For the best experience, please download the native ARM64 version of TriliumNext from our releases page.",
1927+
"download_link": "Download Native Version",
1928+
"continue_anyway": "Continue Anyway",
1929+
"dont_show_again": "Don't show this warning again"
19211930
}
19221931
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import BasicWidget from "../basic_widget.js";
2+
import { Modal } from "bootstrap";
3+
import utils from "../../services/utils.js";
4+
import { t } from "../../services/i18n.js";
5+
6+
const TPL = /*html*/`
7+
<div class="cpu-arch-dialog modal mx-auto" tabindex="-1" role="dialog" style="z-index: 2000;">
8+
<div class="modal-dialog modal-lg" role="document">
9+
<div class="modal-content">
10+
<div class="modal-header">
11+
<h5 class="modal-title">${t("cpu_arch_warning.title")}</h5>
12+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
13+
</div>
14+
<div class="modal-body">
15+
<p>${utils.isMac() ? t("cpu_arch_warning.message_macos") : t("cpu_arch_warning.message_windows")}</p>
16+
17+
<p>${t("cpu_arch_warning.recommendation")}</p>
18+
</div>
19+
<div class="modal-footer d-flex justify-content-between align-items-center">
20+
<button class="download-correct-version-button btn btn-primary btn-lg me-2">
21+
<span class="bx bx-download"></span>
22+
${t("cpu_arch_warning.download_link")}
23+
</button>
24+
25+
<button class="btn btn-secondary" data-bs-dismiss="modal">${t("cpu_arch_warning.continue_anyway")}</button>
26+
</div>
27+
</div>
28+
</div>
29+
</div>`;
30+
31+
export default class IncorrectCpuArchDialog extends BasicWidget {
32+
private modal!: Modal;
33+
private $downloadButton!: JQuery<HTMLElement>;
34+
35+
doRender() {
36+
this.$widget = $(TPL);
37+
this.modal = Modal.getOrCreateInstance(this.$widget[0]);
38+
this.$downloadButton = this.$widget.find(".download-correct-version-button");
39+
40+
this.$downloadButton.on("click", () => {
41+
// Open the releases page where users can download the correct version
42+
if (utils.isElectron()) {
43+
const { shell } = utils.dynamicRequire("electron");
44+
shell.openExternal("https://github.com/TriliumNext/Notes/releases/latest");
45+
} else {
46+
window.open("https://github.com/TriliumNext/Notes/releases/latest", "_blank");
47+
}
48+
});
49+
50+
// Auto-focus the download button when shown
51+
this.$widget.on("shown.bs.modal", () => {
52+
this.$downloadButton.trigger("focus");
53+
});
54+
}
55+
56+
showCpuArchWarningEvent() {
57+
this.modal.show();
58+
}
59+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { execSync } from "child_process";
2+
import { isMac, isWindows } from "../../services/utils";
3+
import { arch, cpus } from "os";
4+
5+
function systemChecks() {
6+
return {
7+
isCpuArchMismatch: isCpuArchMismatch()
8+
}
9+
}
10+
11+
/**
12+
* Detects if the application is running under emulation on Apple Silicon or Windows on ARM.
13+
* This happens when an x64 version of the app is run on an M1/M2/M3 Mac or on a Windows Snapdragon chip.
14+
* @returns true if running on x86 emulation on ARM, false otherwise.
15+
*/
16+
export const isCpuArchMismatch = () => {
17+
if (isMac) {
18+
try {
19+
// Use child_process to check sysctl.proc_translated
20+
// This is the proper way to detect Rosetta 2 translation
21+
const result = execSync("sysctl -n sysctl.proc_translated 2>/dev/null", {
22+
encoding: "utf8",
23+
timeout: 1000
24+
}).trim();
25+
26+
// 1 means the process is being translated by Rosetta 2
27+
// 0 means native execution
28+
// If the sysctl doesn't exist (on Intel Macs), this will return empty/error
29+
return result === "1";
30+
} catch (error) {
31+
// If sysctl fails or doesn't exist (Intel Macs), not running under Rosetta 2
32+
return false;
33+
}
34+
} else if (isWindows && arch() === "x64") {
35+
return cpus().some(cpu =>
36+
cpu.model.includes('Microsoft SQ') ||
37+
cpu.model.includes('Snapdragon'));
38+
} else {
39+
return false;
40+
}
41+
};
42+
43+
export default {
44+
systemChecks
45+
};

apps/server/src/routes/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import ollamaRoute from "./api/ollama.js";
5858
import openaiRoute from "./api/openai.js";
5959
import anthropicRoute from "./api/anthropic.js";
6060
import llmRoute from "./api/llm.js";
61+
import systemInfoRoute from "./api/system_info.js";
6162

6263
import etapiAuthRoutes from "../etapi/auth.js";
6364
import etapiAppInfoRoutes from "../etapi/app_info.js";
@@ -238,6 +239,7 @@ function register(app: express.Application) {
238239
apiRoute(PST, "/api/recent-notes", recentNotesRoute.addRecentNote);
239240
apiRoute(GET, "/api/app-info", appInfoRoute.getAppInfo);
240241
apiRoute(GET, "/api/metrics", metricsRoute.getMetrics);
242+
apiRoute(GET, "/api/system-checks", systemInfoRoute.systemChecks);
241243

242244
// docker health check
243245
route(GET, "/api/health-check", [], () => ({ status: "ok" }), apiResultHandler);

0 commit comments

Comments
 (0)