import { app, BrowserWindow } from 'electron' let mainWindow const winURL = process.env.NODE_ENV === 'development' ? `http://localhost:9080` : `file://${__dirname}/index.html` function createWindow(){ mainWindow = new BrowserWindow({ height: 563, useContentSize: true, titleBarStyle : 'hidden', width: 1000 }) mainWindow.loadURL(winURL) mainWindow.on('closed', () => { mainWindow = null }) } app.on('ready', createWindow) app.on('activate', () => { if (mainWindow === null) { createWindow() } })
const { app, BrowserWindow } = require('electron') let mainWindow = null app.on('ready', () => { mainWindow = new BrowserWindow({ height: 600, width: 600 }) mainWindow.loadFile('index.html') try { mainWindow.webContents.debugger.attach('1.1') } catch (err) { console.log('Debugger attach failed: ', err) } mainWindow.webContents.debugger.on('detach', (event, reason) => { console.log('Debugger detached due to: ', reason) }) mainWindow.webContents.debugger.on('message', (event, method, params) => { if (method === 'Network.requestWillBeSent') { if (params.request.url === 'https://www.github.com') { mainWindow.webContents.debugger.detach() } } }) mainWindow.webContents.debugger.sendCommand('Network.enable') })
client.once('end', () => { app.exit(0) })
// Open the DevTools. mainWindow.webContents.openDevTools() // 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 }) } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', createWindow) // Quit when all windows are closed. app.on('window-all-closed', () => { // On OS X it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit() } }) app.on('activate', () => { // On OS X it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (mainWindow === null) { createWindow()
// window from here. import { app, Menu } from 'electron'; import { devMenuTemplate } from './helpers/dev_menu_template'; import { editMenuTemplate } from './helpers/edit_menu_template'; import createWindow from './helpers/window'; // Special module holding environment variables which you declared // in config/env_xxx.json file. import env from './env'; var ipcMain = require('electron').ipcMain; var uuid = require('node-uuid'); // App-specific deps var keyListener = require('./backgroundServices/keyComboListener')(); var localState = require('./backgroundServices/localState')(app.getAppPath()); var currentCreationWindow; var currentCreationWindowMsgPending; var msgIdsToRenderers = {}; // Local background cache var cachedCategoryTreeData; // Setup listening of rendener msgs ipcMain.on('msg', function(event, arg) { var msgID = arg.msgID; // We need this to send response back if (msgID) { // Save sending window to renderers map so we can use
const app = require('electron').app; module.exports = app.getName() + ' v' + app.getVersion();
'use strict'; const {app, BrowserWindow} = require('electron'); const path = require('path'); const url = require('url'); // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let win; function openApp() { win = new BrowserWindow( { width: 900, height: 800, icon: path.join(__dirname, 'images/icon.png') }); win.loadFile('index.html'); win.on('closed', () => { win = null; }); } app.on('ready', openApp); app.on('window-all-closed', () => { app.quit(); });
app.on('will-finish-launching', function () { app.on('open-url', onOpenUrl); });
global.getOpenUrls = function () { app.removeListener('open-url', onOpenUrl); return openUrls; };
'use strict' const fs = require('fs') const electron = require('electron') const path = require('path') const dataFilePath = path.join(electron.app.getPath('userData'), 'data.json') function readData() { try { return JSON.parse(fs.readFileSync(dataFilePath, 'utf8')) } catch (err) { return {} } } exports.set = (key, val) => { const data = readData() data[key] = val fs.writeFileSync(dataFilePath, JSON.stringify(data)) } exports.get = key => readData()[key]
resolve(dir); } }); }); } // Because Spectron doesn't allow us to pass a custom user-data-dir, // Code receives two of them. Let's just take the first one. var userDataDir = args['user-data-dir']; if (userDataDir) { userDataDir = typeof userDataDir === 'string' ? userDataDir : userDataDir[0]; } // Set userData path before app 'ready' event and call to process.chdir var userData = path.resolve(userDataDir || paths.getDefaultUserDataPath(process.platform)); app.setPath('userData', userData); // Update cwd based on environment and platform try { if (process.platform === 'win32') { process.env['VSCODE_CWD'] = process.cwd(); // remember as environment variable process.chdir(path.dirname(app.getPath('exe'))); // always set application folder as cwd } else if (process.env['VSCODE_CWD']) { process.chdir(process.env['VSCODE_CWD']); } } catch (err) { console.error(err); } // Mac: when someone drops a file to the not-yet running VSCode, the open-file event fires even before // the app-ready event. We listen very early for open-file and remember this upon startup as path to open.
function fullInit(storeFile) { if (app.dock) app.dock.hide(); protocol.interceptHttpProtocol('http', (request, callback) => { shell.openExternal(request.url); }, (error) => { if (error) console.error('Failed to register http protocol'); }); protocol.interceptHttpProtocol('https', (request, callback) => { shell.openExternal(request.url); }, (error) => { if (error) console.error('Failed to register https protocol'); }); const view = 'file://' + path.join(__dirname, '..', '..', 'static', 'index.html'); const iconPath = path.join(__dirname, '..', '..', 'static', 'notepad.png'); const tray = new Tray(iconPath); tray.setToolTip('Just some nice markdown notes ...'); const win = new BrowserWindow({ width: 600, height: 800, show: false, frame: false }); win.on('blur', () => hideWindow()); win.setVisibleOnAllWorkspaces(true); win.loadURL(view); win.webContents.on('did-finish-load', () => { readFile(storeFile, data => { win.webContents.send('lifecycle-event', { event: 'init', initalText: data }); }) }); const positioner = new Positioner(win); const contextMenu = Menu.buildFromTemplate([ { label: 'Reload', accelerator: 'CmdOrCtrl+R', click(item, focusedWindow) { if (focusedWindow) focusedWindow.reload(); } }, { label: 'Toogle DevTools', accelerator: 'CmdOrCtrl+D', click(item, focusedWindow) { if (focusedWindow) focusedWindow.toggleDevTools(); } }, { type: 'separator' }, { label: 'Quit', accelerator: 'CmdOrCtrl+Q', click(item, focusedWindow) { app.quit(); } } ]); function hideWindow() { win.hide(); } function showWindow(trayPos) { let noBoundsPosition = (process.platform === 'win32') ? 'bottomRight' : 'trayCenter'; let position = positioner.calculate(noBoundsPosition, trayPos); win.setPosition(position.x, position.y); win.show(); } function clicked(e, bounds) { if (e.altKey || e.shiftKey || e.ctrlKey || e.metaKey) return hideWindow(); if (win && win.isVisible()) return hideWindow(); showWindow(bounds); } function logAllArgs(evt, ...params) { console.log(...params); } tray.on('click', (e, bounds) => { clicked(e, bounds); }); tray.on('right-click', (e, bounds) => { tray.popUpContextMenu(contextMenu); }); tray.on('double-click', clicked); ipcMain.on('console.log', logAllArgs); ipcMain.on('save-content-to-file', (evt, payload) => { writeFile(storeFile, payload.text, () => ''); }); }
'use strict'; const {app, Menu} = require('electron'); const template = require('./scripts/menu'); const mainWindow = require('./app/main'); // require('crash-reporter').start({ // productName: 'macPq', // companyName: 'lanzz.org', // submitURL: 'http://macpq.lanzz.org/crash' // }); // adds debug features like hotkeys for triggering dev tools and reload require('electron-debug')(); app.on('window-all-closed', () => { app.quit(); }); app.on('activate-with-no-open-windows', () => { mainWindow.open(); }); app.on('ready', () => { var menu = Menu.buildFromTemplate(template); if (menu) { Menu.setApplicationMenu(menu); menu = null; } mainWindow.open();
const listenOpenURL = getWindow => app.on('open-url', (e, path) => { handleURL(getWindow, path); });
const isLinux = (process.platform === 'linux'); const isWindows = (process.platform === 'win32'); */ const autoStart = new AutoLaunch({ name: 'TodoElectron', path: process.execPath.match(/.*?\.app/)[0] }); if (isDevelopment) { require('electron-debug')(); // eslint-disable-line global-require } app.on('window-all-closed', () => { if (isDarwin) app.quit(); }); const installExtensions = async () => { if (isDevelopment) { const installer = require('electron-devtools-installer'); // eslint-disable-line global-require const extensions = [ 'REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS' ]; for (const name of extensions) { try { await installer.default(installer[name]); // eslint-disable-line babel/no-await-in-loop } catch (e) {} // eslint-disable-line }
function getNLSConfiguration() { var locale = args['locale']; if (!locale) { var userData = app.getPath('userData'); var localeConfig = path.join(userData, 'User', 'locale.json'); if (fs.existsSync(localeConfig)) { try { var content = stripComments(fs.readFileSync(localeConfig, 'utf8')); var value = JSON.parse(content).locale; if (value && typeof value === 'string') { locale = value; } } catch (e) { // noop } } } var appLocale = app.getLocale(); locale = locale || appLocale; // Language tags are case insensitve however an amd loader is case sensitive // To make this work on case preserving & insensitive FS we do the following: // the language bundles have lower case language tags and we always lower case // the locale we receive from the user or OS. locale = locale ? locale.toLowerCase() : locale; if (locale === 'pseudo') { return { locale: locale, availableLanguages: {}, pseudo: true }; } var initialLocale = locale; if (process.env['VSCODE_DEV']) { return { locale: locale, availableLanguages: {} }; } // We have a built version so we have extracted nls file. Try to find // the right file to use. // Check if we have an English locale. If so fall to default since that is our // English translation (we don't ship *.nls.en.json files) if (locale && (locale == 'en' || locale.startsWith('en-'))) { return { locale: locale, availableLanguages: {} }; } function resolveLocale(locale) { while (locale) { var candidate = path.join(__dirname, 'vs', 'code', 'electron-main', 'main.nls.') + locale + '.js'; if (fs.existsSync(candidate)) { return { locale: initialLocale, availableLanguages: { '*': locale } }; } else { var index = locale.lastIndexOf('-'); if (index > 0) { locale = locale.substring(0, index); } else { locale = null; } } } return null; } var resolvedLocale = resolveLocale(locale); if (!resolvedLocale && appLocale && appLocale !== locale) { resolvedLocale = resolveLocale(appLocale); } return resolvedLocale ? resolvedLocale : { locale: initialLocale, availableLanguages: {} }; }
app.on('window-all-closed', () => { if (isDarwin) app.quit(); });
* Initial window options */ mainWindow = new BrowserWindow({ height: 600, width: 800 }); mainWindow.loadURL(winURL); mainWindow.on('closed', () => { mainWindow = null; }); // eslint-disable-next-line no-console console.log('mainWindow opened'); } app.on('ready', createWindow); app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); app.on('activate', () => { if (mainWindow === null) { createWindow(); } });
click: () => { app.quit() }
let mainWindow; app.on("ready", () => { // 画像情報取得 const mainImagePath = path.join(__dirname, "image", "myicon.png"); const mainImage = NativeImage.createFromPath(mainImagePath); const mainImageSize = mainImage.getSize(); // Rendere プロセスから 'getMainImagePath' で問い合わせがあったら、ファイルパスを返却する const Ipc = require("electron").ipcMain; Ipc.on('getMainImagePath', function (event, arg) { event.returnValue = mainImagePath; }); // メインウィンドウ作成 const mainWindow = new BrowserWindow({ width: mainImageSize.width + 50, height: mainImageSize.height + 150 }); // index.html ロード mainWindow.loadURL(url.format({ pathname: path.join(__dirname, "index.html"), protocol: "file:", slashes: true })); }); // すべてのウィンドウが閉じたらアプリケーションを終了する // darwin は例外(Dock に常駐するからアプリを終了する必要がない???
app.on('window-all-closed', () => { app.quit(); });
app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } })
global.cleanUp = { proxy: null }; app.on('ready', function() { mainWindow = new BrowserWindow({ 'width': 750 + (process.platform === 'win32' ? 20 : 0), 'height': 550 + (process.platform === 'win32' ? 30 : 0), 'resizable': false, 'icon': __dirname + '/images/app_icon.png', 'show': false }); mainWindow.loadURL('file://' + __dirname + '/app.html'); mainWindow.webContents.on('did-finish-load', function() { setTimeout(function() { mainWindow.show(); }, 40); }); if (env.name !== 'production') { setAppMenu(false); mainWindow.openDevTools(); } else { setAppMenu(false); } mainWindow.setMenuBarVisibility(false); }); app.on('window-all-closed', function() { app.quit(); });
getShortcutExeName () { return path.basename(app.getPath('exe')); }
app.on('window-all-closed', function () { app.quit(); });
exitApp (exitCode = 0) { app.exit(exitCode); }
const {app} = require('electron') const net = require('net') const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch' process.on('uncaughtException', () => { app.exit(1) }) app.once('ready', () => { let lastArg = process.argv[process.argv.length - 1] const client = net.connect(socketPath) client.once('connect', () => { client.end(String(lastArg === '--second')) }) client.once('end', () => { app.exit(0) }) if (lastArg !== '--second') { app.relaunch({args: process.argv.slice(1).concat('--second')}) } })
async teardownLeftoverUserData () { const userDataPath = app.getPath('userData'); log('removing user data folder', userDataPath); await del(path.join(userDataPath, '**'), {force: true}) .then((files) => log('deleted', JSON.stringify(files))); }
process.on('uncaughtException', () => { app.exit(1) })
import { app } from 'electron'; import './darkMode'; app.on('activate', () => { const mainWindow = WindowManager.getAll('main')[0]; if (mainWindow) { mainWindow.show(); } else { // Something went wrong app.quit(); } }); if (Settings.get('fullscreen')) WindowManager.getAll('main')[0].setFullScreen(true);