mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
9faf0b3fbb
* sanitize all electron.shell.openExternal calls * adds lint rule to disallow future usage of `openExternal` * updates to use URL constructor per review feedback
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import * as electron from 'electron';
|
|
import { join } from 'path';
|
|
import appConfig from '../../config/config.json';
|
|
import mkdirp from 'mkdirp';
|
|
|
|
export function clickLink(href: string) {
|
|
const { protocol } = new URL(href);
|
|
if (protocol === 'http:' || protocol === 'https:') {
|
|
// eslint-disable-next-line no-restricted-properties -- this is, other than tests, what _should be_ the one and only place in this project where this is called.
|
|
electron.shell.openExternal(href);
|
|
}
|
|
}
|
|
|
|
export function getDesignerDataDir() {
|
|
const { app } = electron.remote || electron;
|
|
return process.env.DESIGNER_DATA_PATH || join(app.getPath('appData'), 'Insomnia Designer');
|
|
}
|
|
|
|
export function getDataDirectory() {
|
|
const { app } = electron.remote || electron;
|
|
return process.env.INSOMNIA_DATA_PATH || app.getPath('userData');
|
|
}
|
|
|
|
export function getViewportSize(): string | null {
|
|
const { BrowserWindow } = electron.remote || electron;
|
|
const browserWindow = BrowserWindow.getFocusedWindow() || BrowserWindow.getAllWindows()[0];
|
|
|
|
if (browserWindow) {
|
|
const { width, height } = browserWindow.getContentBounds();
|
|
return `${width}x${height}`;
|
|
} else {
|
|
// No windows open
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function getScreenResolution() {
|
|
const { screen } = electron.remote || electron;
|
|
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
|
|
return `${width}x${height}`;
|
|
}
|
|
|
|
export function getUserLanguage() {
|
|
const { app } = electron.remote || electron;
|
|
return app.getLocale();
|
|
}
|
|
|
|
export function getTempDir() {
|
|
// NOTE: Using a fairly unique name here because "insomnia" is a common word
|
|
const { app } = electron.remote || electron;
|
|
const dir = join(app.getPath('temp'), `insomnia_${appConfig.version}`);
|
|
mkdirp.sync(dir);
|
|
return dir;
|
|
}
|
|
|
|
export function restartApp() {
|
|
const { app } = electron.remote || electron;
|
|
app.relaunch();
|
|
app.exit();
|
|
}
|