electron#shell JavaScript Examples
The following examples show how to use
electron#shell.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WindowManager.js From makerverse with GNU General Public License v3.0 | 6 votes |
openWindow(url, options) {
const window = new BrowserWindow({
...options,
show: false
});
const webContents = window.webContents;
window.on('closed', (event) => {
const index = this.windows.indexOf(event.sender);
console.assert(index >= 0);
this.windows.splice(index, 1);
});
// Open every external link in a new window
// https://github.com/electron/electron/blob/master/docs/api/web-contents.md
webContents.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});
webContents.once('dom-ready', () => {
window.show();
});
// Call `ses.setProxy` to ignore proxy settings
// http://electron.atom.io/docs/latest/api/session/#sessetproxyconfig-callback
const ses = webContents.session;
ses.setProxy({ proxyRules: 'direct://' }, () => {
window.loadURL(url);
});
this.windows.push(window);
// Disable AutoUpdater until an update server is available
//new AutoUpdater(window);
return window;
}
Example #2
Source File: help.js From Memocast with MIT License | 6 votes |
export default function () {
return {
label: i18n.t('help'),
role: 'help',
submenu: [{
label: i18n.t('quickStart'),
click () {
shell.openExternal('https://github.com/TankNee/Memocast/blob/master/docs/README.md').then()
}
}, {
label: i18n.t('changelog'),
click () {
shell.openExternal('https://github.com/TankNee/Memocast/blob/master/CHANGELOG.md').then()
}
}, {
type: 'separator'
}, {
label: i18n.t('reportIssue'),
click () {
shell.openExternal('https://github.com/TankNee/Memocast/issues').then()
}
}, {
type: 'separator'
}, {
label: i18n.t('watchOnGithub'),
click () {
shell.openExternal('https://github.com/TankNee/Memocast').then()
}
}, {
type: 'separator'
}, {
label: i18n.t('license'),
click () {
shell.openExternal('https://github.com/TankNee/Memocast/blob/master/LICENSE').then()
}
}]
}
}
Example #3
Source File: index.js From desktop with GNU General Public License v3.0 | 6 votes |
defaultWindowOpenHandler = (details) => {
if (isSafeOpenExternal(details.url)) {
setImmediate(() => {
shell.openExternal(details.url);
});
}
if (isDataURL(details.url)) {
createDataWindow(details.url);
}
return {
action: 'deny'
}
}
Example #4
Source File: index.js From desktop with GNU General Public License v3.0 | 6 votes |
configureRPC = win => {
rpc = createRPC(win);
rpc.on("open hamburger menu", () => {
hamburgerMenu.popup();
});
rpc.on("show notification", body => {
const notif = new Notification({
title: "VPN.ht",
body
});
notif.show();
});
rpc.on("set status login", () => {
isLogged = true;
updateHamburgerMenu();
});
rpc.on("set status logout", () => {
isLogged = false;
updateHamburgerMenu();
});
rpc.on("open url", url => {
shell.openExternal(url);
});
}
Example #5
Source File: index.js From desktop with GNU General Public License v3.0 | 6 votes |
showUpdateDialog = version => {
info(`New version available: ${version}`);
const clickedButton = dialog.showMessageBoxSync(null, {
type: "warning",
buttons: ["View update", "Remind me later"],
defaultId: 0,
title: "VPN.ht - Update available",
message: `Do you want to install the new version ${version}?`
});
if (clickedButton === 0) {
shell.openExternal(
`https://github.com/${repository}/releases/tag/v${version}`
);
}
if (clickedButton === 1) {
// just ignore and continue
return;
}
}
Example #6
Source File: update-checker.js From desktop with GNU General Public License v3.0 | 6 votes |
updateAvailable = async (latestVersion) => {
const ignoredUpdate = get(IGNORE_UPDATE_KEY);
if (ignoredUpdate !== null && ignoredUpdate === latestVersion) {
log('not showing update message: ignored by user');
return;
}
const choice = await dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: APP_NAME,
type: 'info',
buttons: [
getTranslation('updater.download'),
getTranslation('updater.later')
],
cancelId: 1,
message: getTranslation('updater.message').replace('{version}', latestVersion),
detail: getTranslation('updater.detail'),
checkboxLabel: getTranslation('updater.ignore'),
checkboxChecked: false
});
if (choice.response === 0) {
shell.openExternal(getUpdateURL(version, latestVersion));
} else if (choice.checkboxChecked) {
set(IGNORE_UPDATE_KEY, latestVersion);
}
}
Example #7
Source File: update-checker.js From desktop with GNU General Public License v3.0 | 6 votes |
urgentUpdateAvailable = (latestVersion) => {
const choice = dialog.showMessageBoxSync(BrowserWindow.getFocusedWindow(), {
title: APP_NAME,
type: 'warning',
buttons: [
getTranslation('updater.download'),
getTranslation('updater.later')
],
cancelId: 1,
message: getTranslation('updater.security.message').replace('{version}', latestVersion),
detail: getTranslation('updater.security.detail')
});
if (choice === 0) {
shell.openExternal(getUpdateURL(version, latestVersion));
}
}
Example #8
Source File: index.js From zengm-legacy with Apache License 2.0 | 5 votes |
createWindow = () => {
// Rewrite URLs to handle host-relative URLs, which begin with a slash.
protocol.registerBufferProtocol(scheme, (req, callback) => {
let reqUrl = url.parse(req.url);
let pathname = reqUrl.pathname;
if (pathname.endsWith('/')) pathname += 'index.html';
if (reqUrl.hostname === hostname) {
let filePath = path.normalize(pathname);
if (startsWith(filePath, prefixesStaticWithHtml)) {
filePath += '.html';
}
filePath = path.join(webroot, filePath);
fs.access(filePath, fs.constants.R_OK, (err) => {
if (err) {
console.error(err);
callback(404);
} else {
callback({
mimeType: mimeType(pathname), charset: 'UTF-8',
data: fs.readFileSync(filePath)
});
}
});
} else {
serveLocalMirror(reqUrl, callback);
}
}, (err) => {
if (err) console.error('ERROR: failed to register protocol', scheme);
});
protocol.registerServiceWorkerSchemes([scheme]);
// Create the browser window.
// https://electron.atom.io/docs/api/browser-window/
mainWindow = new BrowserWindow({
width: 1024, height: 768, backgroundColor: '#203C64',
center:true, fullscreen:false,
title: app.getName(),
webPreferences: {
nodeIntegration:false,
preload: path.join(__dirname, 'preload.js')
}
});
// and load the index.html of the app.
mainWindow.loadURL(`${scheme}://${hostname}/`);
// Open external URLs in the browser:
mainWindow.webContents.on('will-navigate', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});
// Open the DevTools.
process.argv.some((arg) => {
if (arg === '--dev') {
mainWindow.webContents.openDevTools();
return true;
}
return false;
});
// Implement window.prompt() and window.confirm() which are used by ZenGM:
ipcMain.on('prompt', prompt);
ipcMain.on('prompt-response', promptResponse);
ipcMain.on('confirm', confirm);
ipcMain.on('confirm-response', confirmResponse);
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
}
Example #9
Source File: index.js From clipcc-desktop with GNU Affero General Public License v3.0 | 5 votes |
createWindow = ({search = null, url = 'index.html', ...browserWindowOptions}) => {
const window = new BrowserWindow({
useContentSize: true,
show: false,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
contextIsolation: false,
preload: path.resolve(path.join(__dirname, 'preload.js'))
},
...browserWindowOptions
});
const webContents = window.webContents;
remoteMain.enable(window.webContents);
webContents.session.setPermissionRequestHandler(handlePermissionRequest);
webContents.on('before-input-event', (event, input) => {
if (input.code === devToolKey.code &&
input.alt === devToolKey.alt &&
input.control === devToolKey.control &&
input.meta === devToolKey.meta &&
input.shift === devToolKey.shift &&
input.type === 'keyDown' &&
!input.isAutoRepeat &&
!input.isComposing) {
event.preventDefault();
webContents.openDevTools({mode: 'detach', activate: true});
}
});
webContents.on('new-window', (event, newWindowUrl) => {
shell.openExternal(newWindowUrl);
event.preventDefault();
});
const fullUrl = makeFullUrl(url, search);
window.loadURL(fullUrl);
window.once('ready-to-show', () => {
webContents.send('ready-to-show');
});
return window;
}
Example #10
Source File: Attachment.jsx From thinkord-desktop with GNU General Public License v3.0 | 5 votes |
openFileButton(upname, e) {
this.props.paths.map((path) => {
if (path.split('\\').includes(upname)) {
shell.openItem(path)
}
})
}
Example #11
Source File: AlfwCommon.js From ntfstool with MIT License | 5 votes |
/**
* checkUpdate
*/
export function checkUpdate() {
var cur_version = process.env.NODE_ENV === 'development' ? process.env.npm_package_version : app.getVersion()
// console.warn(this.$http,"this.$http")
try {
get('https://ntfstool.com/version.json').asString(function (err, ret) {
if (err) {
saveLog.error("get api update version.json error",err);
return;
}
var data = {
"version": "",
"url": "https://ntfstool.com/",
"title": "New Version Found",
"detail": "update"
};
try {
var getData = JSON.parse(ret);
if (!getData || typeof getData.version == "undefined" || !getData.version) {
saveLog.error("not found version!")
return;
}
if (typeof getData.version != "undefined") {
data.version = getData.version;
}
if (typeof getData.url != "undefined") {
data.url = getData.url;
}
if (typeof getData.title != "undefined") {
data.title = getData.title;
}
if (typeof getData.detail != "undefined") {
data.detail = getData.detail;
}
} catch (e) {
saveLog.warn("check version format error!",e)
}
if (typeof data.version != "undefined" && data.version) {
saveLog.warn({
cur_version: cur_version,
check_version: data.version
})
if (cur_version != data.version && versionStringCompare(cur_version,data.version) < 0) {
const dialogOpts = {
type: 'info',
buttons: ['Cancel', "OK"],
title: 'Application Update',
message: data.title + "("+cur_version+"->"+data.version+")",
detail: data.detail
}
dialog.showMessageBox(dialogOpts).then((diaret) => {
if (typeof diaret.response != "undefined" && diaret.response == 1) {
shell.openExternal(data.url);
}
});
}
} else {
saveLog.warn("check version format error!")
}
});
} catch (e) {
saveLog.error("get update error!", e);
}
}
Example #12
Source File: AlfwCommon.js From ntfstool with MIT License | 5 votes |
/**
* notice the system error
* @param _error
* @param setOption
*/
export function noticeTheSystemError(_error, setOption) {
var errorMap = {
system: 10000,
dialog: 10010,
dialog_save_err: 10011,
savePassword: 10020,
savePassword2: 10021,
getSudoPwdError: 10031,
checkSudoPasswordError: 10041,
opendevmod: 10030,
FEEDBACK_ERROR: 10040,
UNCLEANERROR:10050
};
var error = (typeof _error != "undefined") ? _error : "system";
console.warn(error, "error")
var errorNo = (typeof errorMap[error] != "undefined") ? errorMap[error] : 1000;
var option = {
title: "System Error: " + errorNo,
body: "please contact official technical support",
href: 'https://www.ntfstool.com'
};
if (typeof setOption == "object") {
option = setOption;
}
if (typeof setOption == "string") {
option.body = setOption;
}
saveLog.error({name: _error, text: JSON.stringify(option)}, "noticeTheSystemError");
new window.Notification(option.title, option).onclick = function () {
shell.openExternal(option.href)
}
}
Example #13
Source File: index.js From lyswhut-lx-music-desktop with Apache License 2.0 | 5 votes |
openUrl = url => {
shell.openExternal(url)
}
Example #14
Source File: index.js From lyswhut-lx-music-desktop with Apache License 2.0 | 5 votes |
openDirInExplorer = dir => {
shell.showItemInFolder(dir)
}
Example #15
Source File: api.js From dev-sidecar with Mozilla Public License 2.0 | 5 votes |
export function apiInit (app) {
const invoke = (api, args) => {
return ipcRenderer.invoke('apiInvoke', [api, args]).catch(e => {
app.$notification.error({
message: 'Api invoke error',
description: e.message
})
})
}
const send = (channel, message) => {
console.log('do send,', channel, message)
return ipcRenderer.send(channel, message)
}
apiObj = {
ipc: {
on (channel, callback) {
ipcRenderer.on(channel, callback)
},
removeAllListeners (channel) {
ipcRenderer.removeAllListeners(channel)
},
invoke,
send,
openExternal (href) {
shell.openExternal(href)
},
openPath (file) {
shell.openPath(file)
}
}
}
const bindApi = (api, param1) => {
lodash.set(apiObj, api, (param2) => {
return invoke(api, param2 || param1)
})
}
if (!inited) {
return invoke('getApiList').then(list => {
inited = true
for (const item of list) {
bindApi(item)
}
console.log('api inited:', apiObj)
return apiObj
})
}
return new Promise(resolve => {
resolve(apiObj)
})
}
Example #16
Source File: index.js From desktop with GNU General Public License v3.0 | 5 votes |
ipcMain.on('open-user-data', () => {
shell.showItemInFolder(app.getPath('userData'));
});
Example #17
Source File: theme-manager.js From Memocast with MIT License | 5 votes |
openThemeFolderHandler () {
shell.showItemInFolder(this.themePath)
}
Example #18
Source File: App.js From ciphora with MIT License | 5 votes |
// Render the App UI
render () {
const activeChat =
this.state.activeChatId && this.state.chats[this.state.activeChatId]
return (
<div className='App'>
<SetupIdentityModal
open={this.state.setupIdentity}
onImportIdentityClick={() => this.openModal('importIdentity')}
onCreateIdentityClick={() => this.openModal('createIdentity')}
/>
<ImportIdentityModal
open={this.state.importIdentity}
onClose={() => this.openModal('setupIdentity')}
onImportClick={this.importIdentityHandler}
message={this.state.modalMessage}
/>
<CreateIdentityModal
open={this.state.createIdentity}
onClose={() => this.openModal('setupIdentity')}
onCreateClick={this.createIdentityHandler}
message={this.state.modalMessage}
/>
<Messenger
sidebar={
<ChatList
profile={this.state.profile}
chats={Object.values(this.state.chats)}
activeChatId={this.state.activeChatId}
onChatClick={this.activateChat}
onComposeChatClick={this.createComposeChat}
onDeleteClick={this.deleteChatHandler}
onCopyIdClick={() => clipboard.writeText(this.state.profile.id)}
onCopyPGPClick={() => ipcRenderer.send('copy-pgp')}
/>
}
content={
<MessageList
composing={this.state.composing}
onComposeChat={this.composeChatHandler}
activeChatId={this.state.activeChatId}
chat={activeChat}
onComposeMessage={this.composeMessageHandler}
onSendFileClick={this.sendFileHandler}
onFileClick={filePath => shell.openItem(filePath)}
onLinkClick={url => shell.openExternal(url)}
onDeleteClick={this.deleteChatHandler}
onCopyIdClick={() => clipboard.writeText(this.state.activeChatId)}
onCopyPGPClick={() =>
ipcRenderer.send('copy-pgp', this.state.activeChatId)
}
/>
}
/>
</div>
)
}
Example #19
Source File: index.js From desktop with GNU General Public License v3.0 | 4 votes |
app.on('web-contents-created', (event, webContents) => {
webContents.on('context-menu', (event, params) => {
const text = params.selectionText;
const hasText = !!text;
const menuItems = [];
if (params.misspelledWord && params.dictionarySuggestions.length > 0) {
for (const word of params.dictionarySuggestions) {
menuItems.push({
label: word,
click: () => {
webContents.replaceMisspelling(word);
}
});
}
menuItems.push({
type: 'separator'
});
}
const url = params.linkURL;
if (params.linkURL) {
menuItems.push({
id: 'openLink',
label: getTranslation('context.open-link'),
enabled: !url.startsWith('blob:'),
click() {
if (isSafeOpenExternal(url)) {
shell.openExternal(url);
}
}
});
menuItems.push({
type: 'separator'
});
}
if (params.isEditable) {
menuItems.push({
id: 'cut',
label: getTranslation('context.cut'),
enabled: hasText,
click: () => {
clipboard.writeText(text);
webContents.cut();
}
});
}
if (hasText || params.isEditable) {
menuItems.push({
id: 'copy',
label: getTranslation('context.copy'),
enabled: hasText,
click: () => {
clipboard.writeText(text);
}
});
}
if (params.isEditable) {
menuItems.push({
id: 'Paste',
label: getTranslation('context.paste'),
click: () => {
webContents.paste();
}
});
}
if (menuItems.length > 0) {
const menu = Menu.buildFromTemplate(menuItems);
menu.popup();
}
});
if (!isMac) {
// On Mac, shortcuts are handled by the menu bar.
webContents.on('before-input-event', (e, input) => {
if (input.isAutoRepeat || input.isComposing || input.type !== 'keyDown' || input.meta) {
return;
}
const window = BrowserWindow.fromWebContents(webContents);
// Ctrl+Shift+I to open dev tools
if (
input.control &&
input.shift &&
input.key.toLowerCase() === 'i' &&
!input.alt
) {
e.preventDefault();
webContents.toggleDevTools();
}
// Ctrl+N to open new window
if (
input.control &&
input.key.toLowerCase() === 'n'
) {
e.preventDefault();
createEditorWindow();
}
// Ctrl+Equals/Plus to zoom in
if (
input.control &&
input.key === '='
) {
e.preventDefault();
webContents.setZoomLevel(webContents.getZoomLevel() + 1);
}
// Ctrl+Minus/Underscore to zoom out
if (
input.control &&
input.key === '-'
) {
e.preventDefault();
webContents.setZoomLevel(webContents.getZoomLevel() - 1);
}
// Ctrl+0 to reset zoom
if (
input.control &&
input.key === '0'
) {
e.preventDefault();
webContents.setZoomLevel(0);
}
// F11 and alt+enter to toggle fullscreen
if (
input.key === 'F11' ||
(input.key === 'Enter' && input.alt)
) {
e.preventDefault();
window.setFullScreen(!window.isFullScreen());
}
// Escape to exit fullscreen
if (
input.key === 'Escape' &&
window.isFullScreen()
) {
e.preventDefault();
// used by closeWindowWhenPressEscape
e.didJustLeaveFullScreen = true;
window.setFullScreen(false);
}
// Ctrl+R and Ctrl+Shift+R to reload
if (
input.control &&
input.key.toLowerCase() === 'r'
) {
e.preventDefault();
if (input.shift) {
webContents.reloadIgnoringCache();
} else {
webContents.reload();
}
}
});
}
webContents.setWindowOpenHandler(defaultWindowOpenHandler);
webContents.on('will-navigate', (e, url) => {
if (url === 'mailto:[email protected]') {
// If clicking on the contact email address, we'll let the OS figure out how to open it
return;
}
try {
const newURL = new URL(url);
const baseURL = new URL(getURL(''));
if (newURL.href.startsWith(baseURL.href)) {
// Let the editor reload itself
// For example, reloading to apply settings
} else {
e.preventDefault();
if (isSafeOpenExternal(url)) {
shell.openExternal(url);
}
}
} catch (e) {
e.preventDefault();
}
});
});
Example #20
Source File: electron-main.js From Memocast with MIT License | 4 votes |
function createWindow () {
const mainWindowState = windowStateKeeper({
defaultWidth: 900,
defaultHeight: 600
})
/**
* Initial window options
*/
mainWindow = new BrowserWindow({
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width < 600 ? 600 : mainWindowState.width,
height: mainWindowState.height < 400 ? 400 : mainWindowState.height,
useContentSize: true,
// transparent: true,
vibrancy: ThemeManager.colorMode, // 'light', 'medium-light' etc
webPreferences: {
// Change from /quasar.conf.js > electron > nodeIntegration;
// More info: https://quasar.dev/quasar-cli/developing-electron-apps/node-integration
nodeIntegration: true,
contextIsolation: false,
nodeIntegrationInWorker: process.env.QUASAR_NODE_INTEGRATION,
webSecurity: false,
experimentalFeatures: false,
enableRemoteModule: true
// More info: /quasar-cli/developing-electron-apps/electron-preload-script
// preload: path.resolve(__dirname, 'electron-preload.js')
},
frame: false,
titleBarStyle: 'hiddenInset'
})
protocol.interceptFileProtocol('file', (req, callback) => {
const url = req.url.substr(8)
callback(decodeURI(url))
}, (error) => {
if (error) {
console.error('Failed to register protocol')
}
})
registerMemocastProtocol()
if (!process.env.PROD) {
mainWindow.webContents.openDevTools()
}
const menu = Menu.buildFromTemplate(configureMenu(new KeyBindings(), mainWindow))
Menu.setApplicationMenu(menu)
mainWindow.isMainWindow = true
mainWindowState.manage(mainWindow)
mainWindow.loadURL(process.env.APP_URL).then()
// mainWindow.on('closed', () => {
// mainWindow = null
// })
mainWindow.on('close', (event) => {
if (!forceQuit) {
event.preventDefault() // This will cancel the close
mainWindow.hide()
}
})
mainWindow.on('closed', () => {
mainWindow = null
})
mainWindow.webContents.on('new-window', (event, linkUrl) => {
event.preventDefault()
if (linkUrl.startsWith('http://localhost:') || linkUrl.startsWith('file://')) {
// dialog.showErrorBox('Unsupported Url Protocol', `Memocast cannot resolve this protocol: ${linkUrl}, please copy it to browser manually!`)
return
}
dialog.showMessageBox(mainWindow, {
type: 'question',
title: i18n.t('openLinkHint'),
message: i18n.t('openLinkHint'),
detail: linkUrl,
buttons: [i18n.t('confirm'), i18n.t('cancel')]
}).then((res) => {
if (!res.response) {
shell.openExternal(linkUrl).then()
}
})
})
registerApiHandler()
global.themeManager = ThemeManager
if (isMac) {
enforceMacOSAppLocation()
}
require('@electron/remote/main').initialize()
require('@electron/remote/main').enable(mainWindow.webContents)
}
Example #21
Source File: menu.js From NoteMaster with GNU General Public License v3.0 | 4 votes |
buildDefaultTemplate() {
const templateDefault = [
{
label: '&File',
submenu: [
{
label: '&Open',
accelerator: 'Ctrl+O'
},
{
label: '&Close',
accelerator: 'Ctrl+W',
click: () => {
this.mainWindow.close();
}
}
]
},
{
label: '&View',
submenu:
process.env.NODE_ENV === 'development'
? [
{
label: '&Reload',
accelerator: 'Ctrl+R',
click: () => {
this.mainWindow.webContents.reload();
}
},
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(
!this.mainWindow.isFullScreen()
);
}
},
{
label: 'Toggle &Developer Tools',
accelerator: 'Alt+Ctrl+I',
click: () => {
this.mainWindow.toggleDevTools();
}
}
]
: [
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(
!this.mainWindow.isFullScreen()
);
}
}
]
},
{
label: 'Help',
submenu: [
{
label: 'Learn More',
click() {
shell.openExternal('http://electron.atom.io');
}
},
{
label: 'Documentation',
click() {
shell.openExternal(
'https://github.com/atom/electron/tree/master/docs#readme'
);
}
},
{
label: 'Community Discussions',
click() {
shell.openExternal('https://discuss.atom.io/c/electron');
}
},
{
label: 'Search Issues',
click() {
shell.openExternal('https://github.com/atom/electron/issues');
}
}
]
}
];
return templateDefault;
}
Example #22
Source File: electron-main.js From loa-details with GNU General Public License v3.0 | 4 votes |
ipcFunctions = {
"reset-session": (event, arg) => {
logParser.softReset();
},
"cancel-reset-session": (event, arg) => {
if (logParser.resetTimer) {
logParser.cancelReset();
}
},
"save-settings": (event, arg) => {
appSettings = JSON.parse(arg.value);
saveSettings(arg.value);
updateShortcuts(appSettings);
mainWindow.webContents.send("on-settings-change", appSettings);
damageMeterWindow.webContents.send("on-settings-change", appSettings);
logParser.dontResetOnZoneChange =
appSettings.damageMeter.functionality.dontResetOnZoneChange;
logParser.removeOverkillDamage =
appSettings.damageMeter.functionality.removeOverkillDamage;
logParser.resetAfterPhaseTransition =
appSettings?.damageMeter?.functionality?.resetAfterPhaseTransition;
damageMeterWindow.setOpacity(appSettings.damageMeter.design.opacity);
},
"get-settings": (event, arg) => {
event.reply("on-settings-change", appSettings);
},
"parse-logs": async (event, arg) => {
await parseLogs(event, appSettings?.logs?.splitOnPhaseTransition);
},
"get-parsed-logs": async (event, arg) => {
const parsedLogs = await getParsedLogs();
await event.reply("parsed-logs-list", parsedLogs);
},
"get-parsed-log": async (event, arg) => {
const logData = await getLogData(arg.value);
await event.reply("parsed-log", logData);
},
"wipe-parsed-logs": async (event, args) => {
await wipeParsedLogs();
},
"open-log-directory": (event, arg) => {
shell.openPath(mainFolder);
},
"check-for-updates": (event, arg) => {
checkForUpdates();
},
"quit-and-install": (event, arg) => {
quitAndInstall();
},
"open-link": (event, arg) => {
shell.openExternal(arg.value);
},
"save-screenshot": async (event, arg) => {
await saveScreenshot(arg.value);
},
"select-log-path-folder": async (event, arg) => {
const res = await dialog.showOpenDialog({ properties: ["openDirectory"] });
if (res.canceled || !res.filePaths || !res.filePaths[0]) return;
event.reply("selected-log-path-folder", res.filePaths[0]);
},
"toggle-damage-meter-minimized-state": (event, arg) => {
if (appSettings.damageMeter.functionality.minimizeToTaskbar) {
if (arg.value) damageMeterWindow.minimize();
else damageMeterWindow.restore();
} else {
if (arg.value) {
let newW = 160,
newH = 64;
damageMeterWindowOldSize = damageMeterWindow.getSize();
damageMeterWindowOldMinimumSize = damageMeterWindow.getMinimumSize();
damageMeterWindowOldPosition = damageMeterWindow.getPosition();
damageMeterPositionDifference = [
damageMeterWindowOldPosition[0] + damageMeterWindowOldSize[0] - newW,
damageMeterWindowOldPosition[1] + damageMeterWindowOldSize[1] - newH,
];
damageMeterWindow.setResizable(false);
damageMeterWindow.setMinimumSize(newW, newH);
damageMeterWindow.setSize(newW, newH);
damageMeterWindow.setPosition(
damageMeterPositionDifference[0],
damageMeterPositionDifference[1]
);
} else {
damageMeterWindow.setResizable(true);
damageMeterWindow.setMinimumSize(
damageMeterWindowOldMinimumSize[0],
damageMeterWindowOldMinimumSize[1]
);
damageMeterWindow.setSize(
damageMeterWindowOldSize[0],
damageMeterWindowOldSize[1]
);
damageMeterWindow.setPosition(
damageMeterWindowOldPosition[0],
damageMeterWindowOldPosition[1]
);
}
}
},
}
Example #23
Source File: menu.js From NoteMaster with GNU General Public License v3.0 | 4 votes |
buildDarwinTemplate() {
const subMenuAbout = {
label: 'Electron',
submenu: [
{
label: 'About ElectronReact',
selector: 'orderFrontStandardAboutPanel:'
},
{ type: 'separator' },
{ label: 'Services', submenu: [] },
{ type: 'separator' },
{
label: 'Hide ElectronReact',
accelerator: 'Command+H',
selector: 'hide:'
},
{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:'
},
{ label: 'Show All', selector: 'unhideAllApplications:' },
{ type: 'separator' },
{
label: 'Quit',
accelerator: 'Command+Q',
click: () => {
app.quit();
}
}
]
};
const subMenuEdit = {
label: 'Edit',
submenu: [
{ label: 'Undo', accelerator: 'Command+Z', selector: 'undo:' },
{ label: 'Redo', accelerator: 'Shift+Command+Z', selector: 'redo:' },
{ type: 'separator' },
{ label: 'Cut', accelerator: 'Command+X', selector: 'cut:' },
{ label: 'Copy', accelerator: 'Command+C', selector: 'copy:' },
{ label: 'Paste', accelerator: 'Command+V', selector: 'paste:' },
{
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:'
}
]
};
const subMenuViewDev = {
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: () => {
this.mainWindow.webContents.reload();
}
},
{
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
}
},
{
label: 'Toggle Developer Tools',
accelerator: 'Alt+Command+I',
click: () => {
this.mainWindow.toggleDevTools();
}
}
]
};
const subMenuViewProd = {
label: 'View',
submenu: [
{
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
}
}
]
};
const subMenuWindow = {
label: 'Window',
submenu: [
{
label: 'Minimize',
accelerator: 'Command+M',
selector: 'performMiniaturize:'
},
{ label: 'Close', accelerator: 'Command+W', selector: 'performClose:' },
{ type: 'separator' },
{ label: 'Bring All to Front', selector: 'arrangeInFront:' }
]
};
const subMenuHelp = {
label: 'Help',
submenu: [
{
label: 'Learn More',
click() {
shell.openExternal('http://electron.atom.io');
}
},
{
label: 'Documentation',
click() {
shell.openExternal(
'https://github.com/atom/electron/tree/master/docs#readme'
);
}
},
{
label: 'Community Discussions',
click() {
shell.openExternal('https://discuss.atom.io/c/electron');
}
},
{
label: 'Search Issues',
click() {
shell.openExternal('https://github.com/atom/electron/issues');
}
}
]
};
const subMenuView =
process.env.NODE_ENV === 'development' ? subMenuViewDev : subMenuViewProd;
return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp];
}
Example #24
Source File: MonacoEditorComponent.js From NoteMaster with GNU General Public License v3.0 | 4 votes |
function MonacoEditorComponent({
// eslint-disable-next-line no-unused-vars
window,
preferences,
// contextEvaluation,
autosaveContent
}) {
// eslint-disable-next-line no-unused-vars
const [isEditorReady, setIsEditorReady] = useState(false);
const monacoEditor = useRef(null);
const valueGetter = useRef(null);
// eslint-disable-next-line no-use-before-define
const viewZoneObserver = new MutationObserver(hookEditorResize);
// LR: Monaco editor has mounted
function handleEditorDidMount(_valueGetter, editor) {
setIsEditorReady(true);
monacoEditor.current = editor;
valueGetter.current = _valueGetter;
// We can hook monaco's viewZone here
viewZoneObserver.observe(editor._modelData.view.viewLines.domNode.domNode, {
attributes: true
});
// LR: Auto Save debounce 300ms
const onDidChangeModelContentAutoSaveDebounced = debounce((e, content) => {
autosaveContent(content);
}, 300);
// Listen to model (content) changes from monaco
const onDidChangeModelContent = e => {
const content = valueGetter.current();
// LR: Debounce the auto save
onDidChangeModelContentAutoSaveDebounced(e, content);
// LR: Pass the event to the ContextEvaluationService.
if (preferences.nmlEnabled)
contextEvaluationService.onDidChangeModelContent(e, content);
};
editor.onDidChangeModelContent(onDidChangeModelContent);
// LR: Register Actions to context menu
editor.addAction({
id: 'search-on-google',
label: 'Search with Google',
precondition: null,
keybindingContext: null,
keybindings: [],
contextMenuGroupId: 'navigation',
contextMenuOrder: 1.5,
run: ed => {
const searchUrl = 'https://www.google.com/search?q=';
const selection = ed.getSelection();
const selectionValue = ed.getModel().getValueInRange(selection);
const searchQuery = encodeURIComponent(selectionValue);
if (searchQuery.length > 0) {
shell.openExternal(`${searchUrl}${searchQuery}`);
}
return null;
}
});
editor.addAction({
id: 'export-note',
label: 'Export Note',
precondition: null,
keybindingContext: null,
keybindings: [],
contextMenuGroupId: 'navigation',
contextMenuOrder: 1.6,
run: ed => {
const noteContent = ed.getModel().getValue();
dialog
.showSaveDialog({
title: 'Export Note',
filters: [
{
name: 'Text File',
extensions: ['txt']
}
]
})
.then(result => {
// eslint-disable-next-line promise/always-return
if (result.canceled) return;
fs.writeFileSync(result.filePath, noteContent, 'utf8');
})
.catch(err => {
throw err;
});
return null;
}
});
// LR: Trigger parse on intial render
contextEvaluationService.onDidChangeModelContent(
null,
valueGetter.current()
);
}
function hookEditorResize(e) {
// LR: Manage content widgets only if nml is enabled
if (preferences.nmlEnabled) {
contextEvaluationService.manageContentWidgets(monacoEditor.current);
}
// LR: Get the line width - used for results
document.documentElement.style.setProperty(
'--nm-var-linewidth',
`${e[0].target.clientWidth}px`
);
}
const {
editorTheme,
fontFamily,
fontSize,
fontWeight,
// fontLigatures,
lineHeight,
lineNumbers,
nmlEnabled,
wrappingIndent
} = preferences;
// HACK: LR - Fixes an issue when the preferences are loaded from the disk and the editor does not resize.
// Window Updates will not cause the editor to layout.
if (monacoEditor.current) {
monacoEditor.current.layout();
// LR: Manage content widgets only if nml is enabled
if (nmlEnabled) {
// LR: Add the content widgets
contextEvaluationService.manageContentWidgets(monacoEditor.current);
}
// LR: Setup CSS vars
document.documentElement.style.setProperty(
'--nm-var-fontsize',
`${fontSize}px`
);
document.documentElement.style.setProperty(
'--nm-var-lineheight',
`${lineHeight}px`
);
document.documentElement.style.setProperty(
'--nm-var-fontfamily',
`'${fontFamily}'`
);
}
const hiddenResultsSeperator = 'nm-editor-results-seperator hidden';
return (
<div className="nm-editor-wrapper">
<div
className={
nmlEnabled ? 'nm-editor-results-seperator' : hiddenResultsSeperator
}
/>
<Editor
className="nm-editor"
height="100%"
width="100%"
language="notemaster"
theme={nmlEnabled ? editorTheme : 'notemaster-dark-nml-disabled'}
value={preferences.editorContent}
editorDidMount={handleEditorDidMount}
automaticLayout
options={{
automaticLayout: true,
scrollbar: {
verticalSliderSize: 0,
vertical: 'hidden',
horizontal: 'hidden'
},
minimap: {
enabled: false
},
// Font
fontFamily,
fontWeight,
fontSize,
fontLigatures: false, // BUG: when enabled - monaco-editor does not calculate text wrapping properly
lineHeight,
overviewRulerBorder: false,
hideCursorInOverviewRuler: true,
codeLens: false,
renderLineHighlight: 'all',
// Word Wrapping
wordWrap: nmlEnabled ? 'wordWrapColumn' : 'on',
wrappingStratergy: 'advanced',
wrappingIndent,
// Disable Suggestions
quickSuggestions: false,
snippetSuggestions: false,
// Hide Line Numbers Gutter
glyphMargin: false,
folding: lineNumbers !== 'off',
lineNumbers, // Default: 'off'
lineDecorationsWidth: lineNumbers !== 'off' ? 5 : 0, // Default: 5
lineNumbersMinChars: 3 // Default: 3
}}
/>
</div>
);
}
Example #25
Source File: menu.js From juggernaut-desktop with MIT License | 4 votes |
buildDefaultTemplate() {
const templateDefault = [
{
label: '&File',
submenu: [
{
label: '&Open',
accelerator: 'Ctrl+O'
},
{
label: '&Close',
accelerator: 'Ctrl+W',
click: () => {
this.mainWindow.close();
}
}
]
},
{
label: '&View',
submenu:
process.env.NODE_ENV === 'development'
? [
{
label: '&Reload',
accelerator: 'Ctrl+R',
click: () => {
this.mainWindow.webContents.reload();
}
},
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(
!this.mainWindow.isFullScreen()
);
}
},
{
label: 'Toggle &Developer Tools',
accelerator: 'Alt+Ctrl+I',
click: () => {
this.mainWindow.toggleDevTools();
}
}
]
: [
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(
!this.mainWindow.isFullScreen()
);
}
}
]
},
{
label: 'Help',
submenu: [
{
label: 'Learn More',
click() {
shell.openExternal('https://www.getjuggernaut.com');
}
},
{
label: 'Documentation',
click() {
shell.openExternal(
'https://github.com/LN-Juggernaut/juggernaut-desktop'
);
}
},
{
label: 'Community Discussions',
click() {
shell.openExternal('https://t.me/beajuggernaut');
}
},
{
label: 'Search Issues',
click() {
shell.openExternal(
'https://github.com/LN-Juggernaut/juggernaut-desktop/issues'
);
}
}
]
}
];
return templateDefault;
}
Example #26
Source File: menu.js From juggernaut-desktop with MIT License | 4 votes |
buildDarwinTemplate() {
const subMenuAbout = {
label: 'Juggernaut',
submenu: [
{
label: 'About Juggernaut',
selector: 'orderFrontStandardAboutPanel:'
},
{ type: 'separator' },
{
label: 'Hide Juggernaut',
accelerator: 'Command+H',
selector: 'hide:'
},
{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:'
},
{ label: 'Show All', selector: 'unhideAllApplications:' },
{ type: 'separator' },
{
label: 'Quit',
accelerator: 'Command+Q',
click: () => {
app.quit();
}
}
]
};
const subMenuEdit = {
label: 'Edit',
submenu: [
{ label: 'Undo', accelerator: 'Command+Z', selector: 'undo:' },
{ label: 'Redo', accelerator: 'Shift+Command+Z', selector: 'redo:' },
{ type: 'separator' },
{ label: 'Cut', accelerator: 'Command+X', selector: 'cut:' },
{ label: 'Copy', accelerator: 'Command+C', selector: 'copy:' },
{ label: 'Paste', accelerator: 'Command+V', selector: 'paste:' },
{
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:'
}
]
};
const subMenuViewDev = {
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: () => {
this.mainWindow.webContents.reload();
}
},
{
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
}
},
{
label: 'Toggle Developer Tools',
accelerator: 'Alt+Command+I',
click: () => {
this.mainWindow.toggleDevTools();
}
}
]
};
const subMenuViewProd = {
label: 'View',
submenu: [
{
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
}
}
]
};
const subMenuWindow = {
label: 'Window',
submenu: [
{
label: 'Minimize',
accelerator: 'Command+M',
selector: 'performMiniaturize:'
},
{ label: 'Close', accelerator: 'Command+W', selector: 'performClose:' },
{ type: 'separator' },
{ label: 'Bring All to Front', selector: 'arrangeInFront:' }
]
};
const subMenuHelp = {
label: 'Help',
submenu: [
{
label: 'Learn More',
click() {
shell.openExternal('https://www.getjuggernaut.com');
}
},
{
label: 'Documentation',
click() {
shell.openExternal(
'https://github.com/LN-Juggernaut/juggernaut-desktop'
);
}
},
{
label: 'Community Discussions',
click() {
shell.openExternal('https://t.me/beajuggernaut');
}
},
{
label: 'Search Issues',
click() {
shell.openExternal(
'https://github.com/LN-Juggernaut/juggernaut-desktop/issues'
);
}
}
]
};
const subMenuView =
process.env.NODE_ENV === 'development' ? subMenuViewDev : subMenuViewProd;
return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp];
}
Example #27
Source File: menu.js From brisque-2.0-desktop with MIT License | 4 votes |
buildDarwinTemplate() {
const subMenuAbout = {
label: 'Brisque IO',
submenu: [
{
label: 'About Brisque IO',
selector: 'orderFrontStandardAboutPanel:'
},
{ type: 'separator' },
{ label: 'Services', submenu: [] },
{ type: 'separator' },
{
label: 'Hide Brisque IO',
accelerator: 'Command+H',
selector: 'hide:'
},
{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:'
},
{ label: 'Show All', selector: 'unhideAllApplications:' },
{ type: 'separator' },
{
label: 'Quit',
accelerator: 'Command+Q',
click: () => {
app.quit()
}
}
]
}
const subMenuEdit = {
label: 'Edit',
submenu: [
{ label: 'Undo', accelerator: 'Command+Z', selector: 'undo:' },
{ label: 'Redo', accelerator: 'Shift+Command+Z', selector: 'redo:' },
{ type: 'separator' },
{ label: 'Cut', accelerator: 'Command+X', selector: 'cut:' },
{ label: 'Copy', accelerator: 'Command+C', selector: 'copy:' },
{ label: 'Paste', accelerator: 'Command+V', selector: 'paste:' },
{
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:'
}
]
}
const subMenuViewDev = {
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: () => {
this.mainWindow.webContents.reload()
}
},
{
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen())
}
},
{
label: 'Toggle Developer Tools',
accelerator: 'Alt+Command+I',
click: () => {
this.mainWindow.toggleDevTools()
}
}
]
}
const subMenuViewProd = {
label: 'View',
submenu: [
{
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen())
}
}
]
}
const subMenuWindow = {
label: 'Window',
submenu: [
{
label: 'Minimize',
accelerator: 'Command+M',
selector: 'performMiniaturize:'
},
{ label: 'Close', accelerator: 'Command+W', selector: 'performClose:' },
{ type: 'separator' },
{ label: 'Bring All to Front', selector: 'arrangeInFront:' }
]
}
const subMenuHelp = {
label: 'Help',
submenu: [
{
label: 'Learn More',
click() {
shell.openExternal('http://brisque.io')
}
},
{
label: 'Our Twitter',
click() {
shell.openExternal('https://twitter.com/brisqueio')
}
}
]
}
const subMenuView =
process.env.NODE_ENV === 'production' ? subMenuViewDev : subMenuViewProd
return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp]
}