mirror of https://github.com/TriliumNext/Notes
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)pull/2300/head
commit
f0c696d6fd
@ -0,0 +1,26 @@
|
||||
import server from "../services/server";
|
||||
import Component from "./component";
|
||||
|
||||
// TODO: Deduplicate.
|
||||
interface CpuArchResponse {
|
||||
isCpuArchMismatch: boolean;
|
||||
}
|
||||
|
||||
export class StartupChecks extends Component {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.checkCpuArchMismatch();
|
||||
}
|
||||
|
||||
async checkCpuArchMismatch() {
|
||||
try {
|
||||
const response = await server.get("system-checks") as CpuArchResponse;
|
||||
if (response.isCpuArchMismatch) {
|
||||
this.triggerCommand("showCpuArchWarning", {});
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Could not check CPU arch status:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
import BasicWidget from "../basic_widget.js";
|
||||
import { Modal } from "bootstrap";
|
||||
import utils from "../../services/utils.js";
|
||||
import { t } from "../../services/i18n.js";
|
||||
|
||||
const TPL = /*html*/`
|
||||
<div class="cpu-arch-dialog modal mx-auto" tabindex="-1" role="dialog" style="z-index: 2000;">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">${t("cpu_arch_warning.title")}</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>${utils.isMac() ? t("cpu_arch_warning.message_macos") : t("cpu_arch_warning.message_windows")}</p>
|
||||
|
||||
<p>${t("cpu_arch_warning.recommendation")}</p>
|
||||
</div>
|
||||
<div class="modal-footer d-flex justify-content-between align-items-center">
|
||||
<button class="download-correct-version-button btn btn-primary btn-lg me-2">
|
||||
<span class="bx bx-download"></span>
|
||||
${t("cpu_arch_warning.download_link")}
|
||||
</button>
|
||||
|
||||
<button class="btn btn-secondary" data-bs-dismiss="modal">${t("cpu_arch_warning.continue_anyway")}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
export default class IncorrectCpuArchDialog extends BasicWidget {
|
||||
private modal!: Modal;
|
||||
private $downloadButton!: JQuery<HTMLElement>;
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.modal = Modal.getOrCreateInstance(this.$widget[0]);
|
||||
this.$downloadButton = this.$widget.find(".download-correct-version-button");
|
||||
|
||||
this.$downloadButton.on("click", () => {
|
||||
// Open the releases page where users can download the correct version
|
||||
if (utils.isElectron()) {
|
||||
const { shell } = utils.dynamicRequire("electron");
|
||||
shell.openExternal("https://github.com/TriliumNext/Notes/releases/latest");
|
||||
} else {
|
||||
window.open("https://github.com/TriliumNext/Notes/releases/latest", "_blank");
|
||||
}
|
||||
});
|
||||
|
||||
// Auto-focus the download button when shown
|
||||
this.$widget.on("shown.bs.modal", () => {
|
||||
this.$downloadButton.trigger("focus");
|
||||
});
|
||||
}
|
||||
|
||||
showCpuArchWarningEvent() {
|
||||
this.modal.show();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
import { execSync } from "child_process";
|
||||
import { isMac, isWindows } from "../../services/utils";
|
||||
import { arch, cpus } from "os";
|
||||
|
||||
function systemChecks() {
|
||||
return {
|
||||
isCpuArchMismatch: isCpuArchMismatch()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if the application is running under emulation on Apple Silicon or Windows on ARM.
|
||||
* This happens when an x64 version of the app is run on an M1/M2/M3 Mac or on a Windows Snapdragon chip.
|
||||
* @returns true if running on x86 emulation on ARM, false otherwise.
|
||||
*/
|
||||
export const isCpuArchMismatch = () => {
|
||||
if (isMac) {
|
||||
try {
|
||||
// Use child_process to check sysctl.proc_translated
|
||||
// This is the proper way to detect Rosetta 2 translation
|
||||
const result = execSync("sysctl -n sysctl.proc_translated 2>/dev/null", {
|
||||
encoding: "utf8",
|
||||
timeout: 1000
|
||||
}).trim();
|
||||
|
||||
// 1 means the process is being translated by Rosetta 2
|
||||
// 0 means native execution
|
||||
// If the sysctl doesn't exist (on Intel Macs), this will return empty/error
|
||||
return result === "1";
|
||||
} catch (error) {
|
||||
// If sysctl fails or doesn't exist (Intel Macs), not running under Rosetta 2
|
||||
return false;
|
||||
}
|
||||
} else if (isWindows && arch() === "x64") {
|
||||
return cpus().some(cpu =>
|
||||
cpu.model.includes('Microsoft SQ') ||
|
||||
cpu.model.includes('Snapdragon'));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
systemChecks
|
||||
};
|
||||
Loading…
Reference in New Issue