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

Commit e401c8c

Browse files
committed
fix(client): also move the logic from the server to the client lol
1 parent 3041af7 commit e401c8c

File tree

5 files changed

+39
-47
lines changed

5 files changed

+39
-47
lines changed

apps/client/src/desktop.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +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";
11+
import { isRunningUnderRosetta2 } from "./services/rosetta_detection.js";
1212
import type ElectronRemote from "@electron/remote";
1313
import type Electron from "electron";
1414
import "./stylesheets/bootstrap.scss";
@@ -119,13 +119,12 @@ function initDarkOrLightMode(style: CSSStyleDeclaration) {
119119
nativeTheme.themeSource = themeSource;
120120
}
121121

122-
async function checkRosetta2Warning() {
122+
function checkRosetta2Warning() {
123123
if (!utils.isElectron()) return;
124124

125125
try {
126-
// Check if running under Rosetta 2 by calling the server
127-
const response = await server.get("api/system-info/rosetta-check") as { isRunningUnderRosetta2: boolean };
128-
if (response.isRunningUnderRosetta2) {
126+
// Check if running under Rosetta 2 directly on client
127+
if (isRunningUnderRosetta2()) {
129128
// Trigger the Rosetta 2 warning dialog
130129
appContext.triggerCommand("showRosettaWarning", {});
131130
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import utils from "./utils.js";
2+
3+
/**
4+
* Detects if the application is running under Rosetta 2 translation on Apple Silicon.
5+
* This happens when an x64 version of the app is run on an M1/M2/M3 Mac.
6+
* Uses the macOS sysctl.proc_translated to properly detect translation.
7+
* @returns true if running under Rosetta 2, false otherwise
8+
*/
9+
export function isRunningUnderRosetta2(): boolean {
10+
if (!utils.isElectron()) return false;
11+
12+
const process = utils.dynamicRequire("process");
13+
const { execSync } = utils.dynamicRequire("child_process");
14+
15+
// Only check on macOS
16+
if (process.platform !== "darwin") return false;
17+
18+
try {
19+
// Use sysctl.proc_translated to check if process is being translated by Rosetta 2
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+
// Returns "1" if running under Rosetta 2, "0" if native ARM64
27+
// Returns empty string or error on Intel Macs (where the key doesn't exist)
28+
return result === "1";
29+
} catch (error) {
30+
// If the command fails (e.g., on Intel Macs), assume not running under Rosetta 2
31+
console.debug("Could not check Rosetta 2 status:", error);
32+
return false;
33+
}
34+
}

apps/server/src/routes/api/system_info.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

apps/server/src/routes/routes.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ 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";
6261

6362
import etapiAuthRoutes from "../etapi/auth.js";
6463
import etapiAppInfoRoutes from "../etapi/app_info.js";
@@ -239,7 +238,6 @@ function register(app: express.Application) {
239238
apiRoute(PST, "/api/recent-notes", recentNotesRoute.addRecentNote);
240239
apiRoute(GET, "/api/app-info", appInfoRoute.getAppInfo);
241240
apiRoute(GET, "/api/metrics", metricsRoute.getMetrics);
242-
apiRoute(GET, "/api/system-info/rosetta-check", systemInfoRoute.rosettaCheck);
243241

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

apps/server/src/services/utils.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,7 @@ export const isElectron = !!process.versions["electron"];
2323

2424
export const isDev = !!(process.env.TRILIUM_ENV && process.env.TRILIUM_ENV === "dev");
2525

26-
/**
27-
* Detects if the application is running under Rosetta 2 translation on Apple Silicon.
28-
* This happens when an x64 version of the app is run on an M1/M2/M3 Mac.
29-
* Uses the macOS sysctl.proc_translated to properly detect translation.
30-
* @returns true if running under Rosetta 2, false otherwise
31-
*/
32-
export const isRunningUnderRosetta2 = () => {
33-
if (!isMac) return false;
34-
35-
try {
36-
// Use child_process to check sysctl.proc_translated
37-
// This is the proper way to detect Rosetta 2 translation
38-
const { execSync } = require("child_process");
39-
const result = execSync("sysctl -n sysctl.proc_translated 2>/dev/null", {
40-
encoding: "utf8",
41-
timeout: 1000
42-
}).trim();
43-
44-
// 1 means the process is being translated by Rosetta 2
45-
// 0 means native execution
46-
// If the sysctl doesn't exist (on Intel Macs), this will return empty/error
47-
return result === "1";
48-
} catch (error) {
49-
// If sysctl fails or doesn't exist (Intel Macs), not running under Rosetta 2
50-
return false;
51-
}
52-
};
26+
5327

5428
export function newEntityId() {
5529
return randomString(12);
@@ -423,7 +397,6 @@ export default {
423397
isElectron,
424398
isEmptyOrWhitespace,
425399
isMac,
426-
isRunningUnderRosetta2,
427400
isStringNote,
428401
isWindows,
429402
md5,

0 commit comments

Comments
 (0)