fix(app): improve macos version and arch detection (#36)

This commit is contained in:
hampus-fluxer
2026-01-06 01:15:21 +01:00
committed by GitHub
parent 7f219a9e1e
commit ea0a2d8aae
4 changed files with 236 additions and 17 deletions

View File

@@ -28,6 +28,8 @@ export interface DesktopInfo {
version: string;
channel: 'stable' | 'canary';
arch: string;
hardwareArch: string;
runningUnderRosetta: boolean;
os: NodeJS.Platform;
osVersion: string;
}

View File

@@ -17,6 +17,7 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import child_process from 'node:child_process';
import fs from 'node:fs';
import http from 'node:http';
import https from 'node:https';
@@ -193,6 +194,39 @@ const ensureRpId = (value: string | undefined, context: string): string => {
return value;
};
const runSysctl = (query: string): string | null => {
try {
return child_process
.execSync(query, {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore'],
})
.trim();
} catch {
return null;
}
};
const detectRosettaMode = (): boolean => {
if (process.platform !== 'darwin') {
return false;
}
const translated = runSysctl('sysctl -n sysctl.proc_translated');
return translated === '1';
};
const detectHardwareArch = (): string => {
if (process.platform !== 'darwin') {
return os.arch();
}
const optionalArm64 = runSysctl('sysctl -n hw.optional.arm64');
if (optionalArm64 === '1') {
return 'arm64';
}
return os.arch();
};
const convertMacCreationOptions = (options: PublicKeyCredentialCreationOptionsJSON): CreateCredentialOptions => ({
rpId: ensureRpId(options.rp.id, 'registration'),
userId: base64UrlToBuffer(options.user.id).toString('base64'),
@@ -374,6 +408,8 @@ export function registerIpcHandlers(): void {
version: app.getVersion(),
channel: BUILD_CHANNEL,
arch: process.arch,
hardwareArch: detectHardwareArch(),
runningUnderRosetta: detectRosettaMode(),
os: process.platform,
osVersion: os.release(),
}),