Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as path from 'path'
import { nativeImage, NativeImage } from 'electron'
import { platform as selectPlatform, is } from 'electron-util'
// URL: `mail.google.com/mail/u/`
export function getUrlAccountId(url: string): null | string {
const accountIdRegExp = /mail\/u\/(\d+)/
const res = accountIdRegExp.exec(url)
return res && res[1]
}
export const platform = selectPlatform({
macos: 'macos',
linux: 'linux',
windows: 'windows'
})
/**
* Create a tray icon.
*
* @param unread True to create the unead icon; false to create the normal icon.
*/
export function createTrayIcon(unread: boolean): NativeImage {
let iconFileName
if (is.macos) {
iconFileName = 'tray-icon.macos.Template.png'
} else {
initialState() {
return platform({
macos: {},
default: {backgroundColor: this.backgroundColor}
})
}
render() {
return platform({
macos: null,
default: (
<div>
</div>
)
})
}
}
render() {
return platform({
macos: null,
default: createElement(
'div',
{},
createElement(Minimize), createElement(Maximize), createElement(Close)
)
})
}
}
newWindow.removeAllListeners('context-menu')
}
})
newWindow.once('ready-to-show', newWindow.show)
newWindow.webContents.once('did-finish-load', () => {
if (newWindow.title) {
newWindow.setTitle(newWindow.title)
}
})
return newWindow
}
export const accelerators = platform({
macos: darwinAccelerators,
linux: linuxAccelerators,
windows: windowsAccelerators
})
const loadUrl = (browserWindow, anchor) => {
let url
if (is.development && process.env.ELECTRON_WEBPACK_WDS_PORT) {
url = `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}#${anchor}`
} else if (is.development && !process.env.ELECTRON_WEBPACK_WDS_PORT) {
url = `file://${__dirname}/../renderer/index.html#${anchor}`
} else {
url = `file:///${__dirname}/index.html#${anchor}`
}
render() {
return platform({
macos: null,
default: createElement(
'div',
{},
createElement(Minimize), createElement(Maximize), createElement(Close)
)
})
}
}
render() {
return platform({
macos: null,
default:
<div style="{{background:"></div>
<div style="{{background:"></div>
<div style="{{background:"></div>
})
}
get defaultKeybindings() {
return platform({
linux: [
{keystroke: 'home', command: '\\x1bOH'},
{keystroke: 'end', command: '\\x1bOF'},
{keystroke: 'ctrl-backspace', command: '\\x1b\\x08'},
{keystroke: 'ctrl-del', command: '\\x1bd'},
{keystroke: 'ctrl-home', command: '\\x1bw'},
{keystroke: 'ctrl-end', command: '\\x10B'}
],
windows: [
{keystroke: 'home', command: '\\x1bOH'},
{keystroke: 'end', command: '\\x1bOF'},
{keystroke: 'ctrl-backspace', command: '\\x1b\\x08'},
{keystroke: 'cltr-del', command: '\\x1bd'},
{keystroke: 'ctrl-home', command: '\\x1bw'},
{keystroke: 'ctrl-end', command: '\\x10B'}
],
export function extractSeven(path, destinationPath) {
const def = deferred()
let pathTo7zip
if (is.development) {
pathTo7zip = sevenBin.path7za
} else {
const binName = platform({
macos: '7za',
linux: '7za',
windows: '7za.exe',
})
pathTo7zip = getAppResourcesPath('7zip-bin', binName)
}
const seven = extractFull(path, destinationPath, {
$bin: pathTo7zip,
recursive: true,
})
seven.on('end', () => {
def.resolve()
})