2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-06-07 23:10:48 +00:00
nativefier/src/infer/inferOs.ts
Adam Weeden 7a08a2d676
Enable TypeScript strict:true, and more typescript-eslint rules (#1223)
* Catch promise errors better

* Move subFunctions to bottom of createNewWindow

* Use parents when creating child BrowserWindow instances

* Some about:blank pages have an anchor (for some reason)

* Inject browserWindowOptions better

* Interim refactor to MainWindow object

* Split up the window functions/helpers/events some

* Further separate out window functions + tests

* Add a mock for unit testing functions that access electron

* Add unit tests for onWillPreventUnload

* Improve windowEvents tests

* Add the first test for windowHelpers

* Move WebRequest event handling to node

* insertCSS completely under test

* clearAppData completely under test

* Fix contextMenu require bug

* More tests + fixes

* Fix + add to createNewTab tests

* Convert createMainWindow back to func + work out gremlins

* Move setupWindow away from main since its shared

* Make sure contextMenu is handling promises

* Fix issues with fullscreen not working + menu refactor

* Run jest against app/dist so that we can hit app unit tests as well

* Requested PR changes

* Add strict typing; tests currently failing

* Fix failing unit tests

* Add some more eslint warnings and fixes

* More eslint fixes

* Strict typing on (still issues with the lib dir)

* Fix the package.json import/require

* Fix some funky test errors

* Warn -> Error for eslint rules

* @ts-ignore -> @ts-expect-error

* Add back the ext code I removed
2021-06-15 22:20:49 -04:00

38 lines
1.1 KiB
TypeScript

import * as os from 'os';
import * as log from 'loglevel';
// Ideally we'd get this list directly from electron-packager, but it's not
// accessible in the package without importing its private js files, which felt
// dirty. So if those change, we'll update these as well.
// https://electron.github.io/electron-packager/master/interfaces/electronpackager.options.html#platform
// https://electron.github.io/electron-packager/master/interfaces/electronpackager.options.html#arch
export const supportedArchs = ['ia32', 'x64', 'armv7l', 'arm64'];
export const supportedPlatforms = [
'darwin',
'linux',
'mac',
'mas',
'osx',
'windows',
];
export function inferPlatform(): string {
const platform = os.platform();
if (['darwin', 'linux', 'win32'].includes(platform)) {
log.debug('Inferred platform', platform);
return platform;
}
throw new Error(`Untested platform ${platform} detected`);
}
export function inferArch(): string {
const arch = os.arch();
if (!supportedArchs.includes(arch)) {
throw new Error(`Incompatible architecture ${arch} detected`);
}
log.debug('Inferred arch', arch);
return arch;
}