Skip to content

Commit

Permalink
Apple M1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwchadwick committed Dec 21, 2021
1 parent 21ab3dd commit 327bc17
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
20 changes: 20 additions & 0 deletions packages/insomnia-app/app/common/electron-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as electron from 'electron';
import { statSync } from 'fs';
import mkdirp from 'mkdirp';
import { join } from 'path';

Expand Down Expand Up @@ -28,6 +29,25 @@ export function getDataDirectory() {
return process.env.INSOMNIA_DATA_PATH || app.getPath('userData');
}

export function getAppPathUniversal() {
const { app } = electron.remote || electron;

const appPath = app.getAppPath();

if (process.platform !== 'darwin' || !appPath.endsWith('/app.asar')) {
return appPath;
}

const archAppPath = appPath.replace(/\/app\.asar$/, `app-${process.arch}.asar`);

try {
statSync(archAppPath);
return archAppPath;
} catch (e) {
return appPath;
}
}

export function getViewportSize(): string | null {
const { BrowserWindow } = electron.remote || electron;
const browserWindow = BrowserWindow.getFocusedWindow() || BrowserWindow.getAllWindows()[0];
Expand Down
6 changes: 3 additions & 3 deletions packages/insomnia-app/app/main/window-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
MNEMONIC_SYM,
} from '../common/constants';
import { docsBase } from '../common/documentation';
import { clickLink, getDataDirectory, restartApp } from '../common/electron-helpers';
import { clickLink, getAppPathUniversal, getDataDirectory, restartApp } from '../common/electron-helpers';
import * as log from '../common/log';
import LocalStorage from './local-storage';

Expand Down Expand Up @@ -124,7 +124,7 @@ export function createWindow() {

// Load the html of the app.
const url = process.env.APP_RENDER_URL;
const appUrl = url || `file://${app.getAppPath()}/renderer.html`;
const appUrl = url || `file://${getAppPathUniversal()}/renderer.html`.replace('app.asar', 'app-arm64.asar');
console.log(`[main] Loading ${appUrl}`);
mainWindow?.loadURL(appUrl);
// Emitted when the window is closed.
Expand Down Expand Up @@ -359,7 +359,7 @@ export function createWindow() {
{
label: 'Show Open Source Licenses',
click: () => {
const licensePath = path.resolve(app.getAppPath(), '../opensource-licenses.txt');
const licensePath = path.resolve(getAppPathUniversal(), '../opensource-licenses.txt');
shell.openPath(licensePath);
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/insomnia-app/scripts/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const pkg = () => {
return electronBuilder.build({
config,
[targetPlatform]: target,
...targetPlatform === 'mac' ? { universal: true } : {},
});
};

Expand Down

0 comments on commit 327bc17

Please sign in to comment.