@@ -3,7 +3,7 @@ const DEV_MODE = process.env.HTK_DEV === 'true';
33// Set up error handling before everything else:
44import { logError , addBreadcrumb } from './errors' ;
55
6- import { spawn , ChildProcess } from 'child_process' ;
6+ import { spawn , exec , ChildProcess } from 'child_process' ;
77import * as os from 'os' ;
88import { promises as fs , createWriteStream , WriteStream } from 'fs'
99import * as net from 'net' ;
@@ -16,7 +16,9 @@ import { app, BrowserWindow, shell, Menu, dialog, session, ipcMain } from 'elect
1616import * as yargs from 'yargs' ;
1717import * as semver from 'semver' ;
1818import * as rimraf from 'rimraf' ;
19+
1920const rmRF = promisify ( rimraf ) ;
21+ const execAsync = promisify ( exec ) ;
2022
2123import * as windowStateKeeper from 'electron-window-state' ;
2224import { getSystemProxy } from 'os-proxy-config' ;
@@ -648,6 +650,54 @@ ipcMain.handle('open-context-menu', ipcHandler((options: ContextMenuDefinition)
648650
649651ipcMain . handle ( 'get-desktop-version' , ipcHandler ( ( ) => DESKTOP_VERSION ) ) ;
650652ipcMain . handle ( 'get-server-auth-token' , ipcHandler ( ( ) => AUTH_TOKEN ) ) ;
653+ ipcMain . handle ( 'get-device-info' , ipcHandler ( async ( ) => {
654+ const realArch = await getRealArch ( ) ;
655+
656+ return {
657+ platform : os . platform ( ) ,
658+ release : os . release ( ) ,
659+ runtimeArch : os . arch ( ) ,
660+ realArch : realArch
661+ }
662+ } ) ) ;
663+
664+ // Detect the 'real' architecture of the system. We're concerned here with detecting the real arch
665+ // despite emulation here, to help with launch subprocs. Not too worried about x86 vs x64.
666+ async function getRealArch ( ) {
667+ try {
668+ switch ( process . platform ) {
669+ case 'darwin' :
670+ const { stdout : armCheck } = await execAsync ( 'sysctl -n hw.optional.arm64' )
671+ . catch ( ( e : any ) => {
672+ const output = e . message + e . stdout + e . stderr ;
673+ // This id may not be available:
674+ if ( output ?. includes ?.( "unknown oid" ) ) return { stdout : "0" } ;
675+ else throw e ;
676+ } ) ;
677+ if ( armCheck . trim ( ) === '1' ) {
678+ return 'arm64' ;
679+ }
680+
681+ case 'linux' :
682+ const { stdout : cpuInfo } = await execAsync ( 'cat /proc/cpuinfo' ) ;
683+ const lcCpuInfo = cpuInfo . toLowerCase ( ) ;
684+ if ( lcCpuInfo . includes ( 'aarch64' ) || lcCpuInfo . includes ( 'arm64' ) ) {
685+ return 'arm64' ;
686+ }
687+
688+ case 'win32' :
689+ const arch = process . env . PROCESSOR_ARCHITEW6432 || process . env . PROCESSOR_ARCHITECTURE ;
690+ if ( arch ?. toLowerCase ( ) === 'arm64' ) {
691+ return 'arm64' ;
692+ }
693+ }
694+ } catch ( e ) {
695+ console . warn ( `Error querying system arch: ${ e . message } ` ) ;
696+ logError ( e ) ;
697+ }
698+
699+ return os . arch ( ) ;
700+ }
651701
652702let restarting = false ;
653703ipcMain . handle ( 'restart-app' , ipcHandler ( ( ) => {
0 commit comments