mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 06:43:35 +00:00
Split jslib into multiple modules (#363)
* Split jslib into multiple modules
This commit is contained in:
48
electron/src/utils.ts
Normal file
48
electron/src/utils.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { ipcRenderer } from 'electron';
|
||||
|
||||
export type RendererMenuItem = {label?: string, type?: ('normal' | 'separator' | 'submenu' | 'checkbox' | 'radio'), click?: () => any};
|
||||
|
||||
export function invokeMenu(menu: RendererMenuItem[]) {
|
||||
const menuWithoutClick = menu.map(m => {
|
||||
return { label: m.label, type: m.type };
|
||||
});
|
||||
ipcRenderer.invoke('openContextMenu', { menu: menuWithoutClick }).then((i: number) => {
|
||||
if (i !== -1) {
|
||||
menu[i].click();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function isDev() {
|
||||
// ref: https://github.com/sindresorhus/electron-is-dev
|
||||
if ('ELECTRON_IS_DEV' in process.env) {
|
||||
return parseInt(process.env.ELECTRON_IS_DEV, 10) === 1;
|
||||
}
|
||||
return (process.defaultApp || /node_modules[\\/]electron[\\/]/.test(process.execPath));
|
||||
}
|
||||
|
||||
export function isAppImage() {
|
||||
return process.platform === 'linux' && 'APPIMAGE' in process.env;
|
||||
}
|
||||
|
||||
export function isMacAppStore() {
|
||||
return process.platform === 'darwin' && process.mas && process.mas === true;
|
||||
}
|
||||
|
||||
export function isWindowsStore() {
|
||||
const isWindows = process.platform === 'win32';
|
||||
let windowsStore = process.windowsStore;
|
||||
if (isWindows && !windowsStore &&
|
||||
process.resourcesPath.indexOf('8bitSolutionsLLC.bitwardendesktop_') > -1) {
|
||||
windowsStore = true;
|
||||
}
|
||||
return isWindows && windowsStore === true;
|
||||
}
|
||||
|
||||
export function isSnapStore() {
|
||||
return process.platform === 'linux' && process.env.SNAP_USER_DATA != null;
|
||||
}
|
||||
|
||||
export function isWindowsPortable() {
|
||||
return process.platform === 'win32' && process.env.PORTABLE_EXECUTABLE_DIR != null;
|
||||
}
|
||||
Reference in New Issue
Block a user