Skip to content

Commit 3887e8d

Browse files
committed
fix: show error box on linux-x64 without sse42 and quit
1 parent a2f2a3b commit 3887e8d

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

ts/mains/main_node.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
app,
99
BrowserWindow,
1010
crashReporter,
11+
dialog,
1112
protocol as electronProtocol,
1213
ipcMain as ipc,
1314
ipcMain,
@@ -199,6 +200,7 @@ import { initializeMainProcessLogger } from '../util/logger/main_process_logging
199200
import * as log from '../util/logger/log';
200201
import { DURATION } from '../session/constants';
201202
import { tr } from '../localization/localeTools';
203+
import { isSharpSupported } from '../node/sharp_support/sharpSupport';
202204

203205
import { logCrash } from '../node/crash/log_crash';
204206

@@ -224,6 +226,11 @@ function prepareURL(pathSegments: Array<string>, moreKeys?: { theme: any }) {
224226
return url.format(urlObject);
225227
}
226228

229+
async function showUnsupportedCpuDialog() {
230+
dialog.showErrorBox(tr('unsupportedCpu'), tr('yourCpuIsUnsupportedSSE42'));
231+
app.quit();
232+
}
233+
227234
function handleUrl(event: any, target: string) {
228235
event?.preventDefault();
229236
const { protocol } = url.parse(target);
@@ -769,6 +776,11 @@ app.on('ready', async () => {
769776
console.log(`crowdin locale is ${loadedLocale.crowdinLocale}`);
770777
}
771778

779+
if (!isSharpSupported()) {
780+
await showUnsupportedCpuDialog();
781+
return;
782+
}
783+
772784
const key = getDefaultSQLKey();
773785
// Try to show the main window with the default key
774786
// If that fails then show the password window
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { readFileSync } from 'fs';
2+
import { isLinux } from '../../OS';
3+
4+
/**
5+
* The return of this function should be used as override of `sse42FromCPUInfo` if different than null.
6+
* Used for testing purposes.
7+
* @returns true when process.env.SESSION_SSE42_OVERRIDE === '1', false when process.env.SESSION_SSE42_OVERRIDE === '0', null otherwise
8+
*/
9+
function overrideSSE42IsSupported() {
10+
if (process.env.SESSION_SSE42_OVERRIDE === '1') {
11+
return true;
12+
}
13+
14+
if (process.env.SESSION_SSE42_OVERRIDE === '0') {
15+
return false;
16+
}
17+
return null;
18+
}
19+
20+
/**
21+
* Checks from /proc/cpuinfo if the CPU supports SSE 4.2 instructions.
22+
*/
23+
function sse42FromCPUInfo() {
24+
const sse42Override = overrideSSE42IsSupported();
25+
if (sse42Override !== null) {
26+
return sse42Override;
27+
}
28+
try {
29+
const cpuinfo = readFileSync('/proc/cpuinfo', 'utf8');
30+
const flagsMatch = cpuinfo.match(/flags\s*:\s*(.+)/m);
31+
32+
if (flagsMatch) {
33+
const flags = flagsMatch[1].split(/\s+/);
34+
35+
const sseFlagFound = flags.includes('sse4_2');
36+
console.info('SSE 4.2 flag found:', sseFlagFound);
37+
return sseFlagFound && false;
38+
}
39+
return false;
40+
} catch (error) {
41+
console.warn('Could not read /proc/cpuinfo:', error);
42+
return false;
43+
}
44+
}
45+
46+
function isLinuxX64() {
47+
return isLinux() && process.arch === 'x64';
48+
}
49+
50+
/**
51+
* Returns true if sharp is supported on the current platform.
52+
* On linux x64, the CPU needs to support SSE 4.2 instructions to process images.
53+
* This function checks if we are on linux x64 and if yes, checks `/proc/cpuinfo` for the SSE 4.2 flag.
54+
*/
55+
export function isSharpSupported() {
56+
if (isLinuxX64()) {
57+
return sse42FromCPUInfo();
58+
}
59+
// sharp doesn't need sse42 on other platforms than linux x64 as of 18/09/2025
60+
return true;
61+
}

0 commit comments

Comments
 (0)