Created
February 27, 2020 17:12
-
-
Save IgorDePaula/21f982c57c2408b7e7e49e586c9bb307 to your computer and use it in GitHub Desktop.
Tray.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { app, BrowserWindow, nativeTheme, Menu, Tray, nativeImage } from 'electron' | |
const path = require('path') | |
let tray = null | |
try { | |
if (process.platform === 'win32' && nativeTheme.shouldUseDarkColors === true) { | |
require('fs').unlinkSync(require('path').join(app.getPath('userData'), 'DevTools Extensions')) | |
} | |
} catch (_) { } | |
/** | |
* Set `__statics` path to static files in production; | |
* The reason we are setting it here is that the path needs to be evaluated at runtime | |
*/ | |
if (process.env.PROD) { | |
global.__statics = require('path').join(__dirname, 'statics').replace(/\\/g, '\\\\') | |
} | |
let mainWindow | |
function createWindow () { | |
/** | |
* Initial window options | |
*/ | |
mainWindow = new BrowserWindow({ | |
width: 1000, | |
height: 600, | |
useContentSize: true, | |
webPreferences: { | |
// Change from /quasar.conf.js > electron > nodeIntegration; | |
// More info: https://quasar.dev/quasar-cli/developing-electron-apps/node-integration | |
nodeIntegration: QUASAR_NODE_INTEGRATION, | |
// More info: /quasar-cli/developing-electron-apps/electron-preload-script | |
// preload: path.resolve(__dirname, 'electron-preload.js') | |
} | |
}) | |
mainWindow.loadURL(process.env.APP_URL) | |
mainWindow.on('closed', () => { | |
mainWindow = null | |
}) | |
} | |
app.on('ready', () => { | |
createWindow() | |
const icon = path.resolve(__dirname, '../icons/linux-512x512.png') | |
console.log(icon) | |
const trayIcon = nativeImage.createFromPath(icon); | |
tray = new Tray(trayIcon) | |
const contextMenu = Menu.buildFromTemplate([ | |
{ label: 'Item1', type: 'radio', click: () => alert('trouxa') }, | |
{ label: 'Item2', type: 'radio' }, | |
{ label: 'Item3', type: 'radio', checked: true }, | |
{ label: 'Item4', type: 'radio' } | |
]) | |
tray.setToolTip('This is my application.') | |
tray.setContextMenu(contextMenu) | |
// mainWindow.minimize() | |
//mainWindow.hide() | |
}) | |
app.on('window-all-closed', () => { | |
if (process.platform !== 'darwin') { | |
app.quit() | |
} | |
}) | |
app.on('activate', () => { | |
if (mainWindow === null) { | |
createWindow() | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment