tray: function() { appIcon = new Tray('resources/icon.png'); var trayContextMenu = Menu.buildFromTemplate([ { label: 'Start/Pause', type: 'checkbox', checked: false, click: watcher.toggleWatching }, { label: 'Preferences', click: watcher.openConfig }, { label: 'About GitLab App', selector: 'orderFrontStandardAboutPanel:' }, { label: 'Quit', accelerator: 'Command+Q', click: function() { app.quit(); } } ]); appIcon.setToolTip('I am watching GitLab for you!'); appIcon.setContextMenu(trayContextMenu); },
app.on('ready', function() { var myScreen = require('screen'); var size = myScreen.getPrimaryDisplay().workAreaSize; mainWindow = new BrowserWindow({ width: size.width, height: size.height/2, frame: false, "skip-taskbar": true, resizable: false, transparent: true }); mainWindow.loadUrl('file://' + __dirname + '/main.html'); mainWindow.show(); mainWindow.openDevTools(); mainWindow.on('closed', function() { mainWindow = null; }); var icon = NativeImage.createFromPath(__dirname.slice(2) + '/css/tray.png'); mainTray = new Tray(icon); var contextMenu = Menu.buildFromTemplate([ { label: 'Quit', type: 'normal', click: function() {mainWindow.close();} } ]); mainTray.setToolTip('This is my application.'); mainTray.setContextMenu(contextMenu); });
app.on('ready', function() { tray = new Tray(__dirname + '/tray-icon.png'); tray.setPressedImage(__dirname + '/tray-icon-alt.png'); tray.setToolTip('invoker-app'); updateTrayMenu(); });
var module = function(label, icons_path, controlPanelCallback, quitCallback) { idleIcon = { normal: icons_path + '/tray.png', pressed: icons_path + '/tray_pressed.png' }; processIcon = { normal: icons_path + '/tray_process.png', pressed: icons_path + '/tray_process_pressed.png' }; tray = new Tray(idleIcon.normal); tray.setToolTip(label); tray.setPressedImage(idleIcon.pressed); tray.setContextMenu(Menu.buildFromTemplate( [ { label: label, enabled: false }, { type: 'separator' }, { label: 'Open control panel', click: function() { controlPanelCallback(); } }, { type: 'separator' }, { label: 'About...', selector: 'orderFrontStandardAboutPanel:' }, { label: 'Quit', accelerator: 'Command+Q', click: function() { quitCallback(); } } ] )); this.setIdle = function() { tray.setImage(idleIcon.normal); tray.setPressedImage(idleIcon.pressed); }; this.setProcessing = function() { tray.setImage(processIcon.normal); tray.setPressedImage(processIcon.pressed); }; };
function createWindow () { console.log("createWindow?"); //create server playcanvas //stand alone game appIcon = new Tray( __dirname + './public/favicon.ico'); var contextMenu = Menu.buildFromTemplate([ //{ label: 'Start Up Window', click: function() {ipcRenderer.send('start-up', 't' ); console.log('start-up');}}, { label: 'Database', click: function() { displaywindowid('database'); console.log('item database'); }}, { label: 'Server', click: function() {displaywindowid('server'); console.log('item server'); }}, { label: 'Client', click: function() {displaywindowid('client'); console.log('item client'); }}, { label: 'Game', click: function() { displaywindowid('game'); console.log('item game'); }}, { label: 'Settings', click: function() { displaywindowid('settings'); console.log('item settings');}} ]); appIcon.setToolTip('This is my application.'); appIcon.setContextMenu(contextMenu); appIcon.on('clicked',function(event){ //console.log(event); //console.log('click'); if(mainWindow !=null){ console.log(mainWindow); if(mainWindow.isVisible()){ mainWindow.hide(); }else{ mainWindow.show(); } } }); ipcMain.on('window-display', function(event, windowid) { console.log('windowid:'+windowid); displaywindowid(windowid); }); setTimeout(function(){ // Create the browser window. mainWindow = new BrowserWindow({width: 800, height: 600}); // and load the index.html of the app. mainWindow.loadURL('file://' + __dirname + '/index.html'); //mainWindow.loadURL('http://127.0.0.1:3000/'); var webContents = mainWindow.webContents; webContents.on("did-finish-load", function() { //console.log("Write PDF successfully."); //console.log(mainWindow); }); //console.log("hello world"); // Open the DevTools. mainWindow.webContents.openDevTools(); // Emitted when the window is closed. mainWindow.on('closed', function() { // 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; }); },2000); }
app.minimizeApp = function() { if (process.platform !== 'darwin') { mainWindow.minimize(); mainWindow.setSkipTaskbar(true); appIcon = new Tray(path.join(__dirname, 'icon.png')); appIcon.on('click', restoreMainWindow); var contextMenu = Menu.buildFromTemplate([ { label: 'Open KeeWeb', click: restoreMainWindow }, { label: 'Quit KeeWeb', click: closeMainWindow } ]); appIcon.setContextMenu(contextMenu); appIcon.setToolTip('KeeWeb'); } };
fs.access(settingsFile, fs.F_OK, err => { // Create settings file if it doesn't exist. if (!err) { // Extend the settings object and save it, so we can add new settings in newer versions without issues. // TODO: Need to clean out old settings variables somehow. const file = fs.readFileSync(settingsFile, 'utf8'); settings = Object.assign(settings, JSON.parse(file)); } // After merging settings, save it down again. fs.writeFileSync(settingsFile, JSON.stringify(settings), 'utf8'); console.log('Settings used:'); console.dir(settings); openAllTeamWindows(settings); ipc.on('notification-shim', (e, msg) => { const win = BrowserWindow.fromWebContents(e.sender); if (win.isFocused()) { return; } const content = msg.options.body || ''; showBalloon(msg.title, content); showToast(win, msg.title, content); showBadge(win); bounceIcon(); // Doesn't seem possible to pass extra info to balloon, and we want this window to open when the balloon is clicked. lastActiveWindow = win; }); // Electron doesn't support notifications in Windows yet. https://github.com/atom/electron/issues/262 // So we create our own Windows notification visualizations. if (process.platform === 'win32') { if (settings.win32.balloons) { tray = new Tray(iconPath); tray.setToolTip('HipsterChat notifications'); tray.on('balloon-clicked', e => { console.log(e); lastActiveWindow.focus(); }); } } });
this.initTray = function(){ appIcon = new Tray(null); // appIcon.setImage('../resources/win/app.ico', false); // disable the behavior // appIcon = new Tray("./resources/win/app.ico"); // appIcon.setPressedImage(path.join(__dirname, "./menu-bar-white.png")); var contextMenu = Menu.buildFromTemplate([ { label: 'Save from Clippord', type: 'radio' }, { label: 'Item2', type: 'radio' }, { label: 'Item3', type: 'radio', checked: true }, { label: 'Item4', type: 'radio' }, ]); appIcon.setToolTip('Clip Noted!'); appIcon.setContextMenu(contextMenu); return this; };
app.on('ready', function () { if (app.dock) app.dock.hide(); appIcon = new Tray(__dirname + '/IconTemplate.png'); appIcon.setToolTip('SPARC – Keep track of your Diffs'); var contextMenu = Menu.buildFromTemplate([ { label: 'Loading...', enabled: false }, { label: 'Exit', click: app.quit } ]); appIcon.setContextMenu(contextMenu); startPhabricatorPoll(); app.on('closed', function () { stopPhabricatorPoll(); }); });
module.exports = exports = function (app){ icon = new Tray(path.join(__dirname,'../img/icon.png')); var menus = [{ label: '发微博', type: 'normal', click: function (){ app.emit('sendWeibo'); } },{ label: '退出', type: 'normal', click: function (){ app.emit('quitRequest'); } }]; var contextMenu = menu.buildFromTemplate(menus); icon.setToolTip('发微博'); icon.setContextMenu(contextMenu); };
function createWindow() { mainWindow = new BrowserWindow({ title: 'AlertTest', width: 490, height: 300, skipTaskbar: true, resizable: false, titleBarStyle: 'hidden', frame: false, show: false, alwaysOnTop: true }); mainWindow.loadURL('file://' + __dirname + '/index.html'); // mainWindow.webContents.openDevTools(); mainWindow.on('closed', () => { mainWindow = null; }); mainWindow.on('show', () => { console.log('show'); }); mainWindow.on('hide', () => { console.log('hide'); }); timer = setInterval(showMessage, 20 * 1000); var Tray = require('tray'); var trayIcon = new Tray(__dirname + "/icon.png"); var Menu = require('menu'); var contextMenu = Menu.buildFromTemplate([ { label: 'Cose', click: () => { mainWindow.close(); } } ]); trayIcon.setToolTip('AlertTest'); trayIcon.setContextMenu(contextMenu); trayIcon.on('click', () => { mainWindow.show(); mainWindow.focus(); }); }
app.on('ready', function() { var mainWindow = new BrowserWindow({ width: 600, height: 300, center: true, title: "Remote Demo だぎゃあ", }); var menu = Menu.buildFromTemplate([ { label: "おっす", submenu: [{ label: 'やるぞ!', accelerator: 'Shift+CmdOrCtrl+D', click: function() { BrowserWindow.getFocusedWindow().toggleDevTools(); } }] } ]); Menu.setApplicationMenu(menu); var contextMenu = Menu.buildFromTemplate([ { label: 'Item1', type: 'radio' }, { label: 'Item2', type: 'radio' }, { label: 'Item3', type: 'radio', checked: true }, { label: 'Item4', type: 'radio' } ]); var icon = new Tray(__dirname + '/images/udzura.jpg'); icon.setToolTip("テスト"); icon.setContextMenu(contextMenu); mainWindow.loadURL('file://' + __dirname + '/index.html'); //mainWindow.webContents.openDevTools(); mainWindow.on('closed', function() { mainWindow = null; }); });
app.on('ready', function () { mainWindow = new BrowserWindow({ width: 400, height: 600 }) mainWindow.loadUrl('file://' + __dirname + '/index.html') mainWindow.on('closed', function () { mainWindow = null }) // tray var iconPath = path.join(__dirname, 'IconTemplate.png') appIcon = new Tray(iconPath); // var contextMenu = Menu.buildFromTemplate([ // { label: 'Item1', type: 'radio' }, // { label: 'Item2', type: 'radio' }, // { label: 'Item3', type: 'radio', checked: true }, // { label: 'Item4', type: 'radio' }, // ]); appIcon.setToolTip('Open/ Close'); // appIcon.setContextMenu(contextMenu); })
app.on("ready", function() { //Update wallpaper every 10 minutes. setInterval(function() { updateWallpaper(); }, 600000); updateWallpaper(); appIcon = new Tray(__dirname + "/tray.png"); var contextMenu = Menu.buildFromTemplate([ { label: "PrettyWall", type: "normal" }, { type: "separator" }, { label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); } } ]); appIcon.setToolTip("PrettyWall"); appIcon.setContextMenu(contextMenu); //Support right clicking the tray icon. appIcon.on("right-clicked", function(event, bounds) { appIcon.popUpContextMenu(); }); });
app.on('ready', function(){ win = new BrowserWindow({show: false}); appIcon = new Tray(iconPath); var contextMenu = Menu.buildFromTemplate([ { label: 'Item1', type: 'radio', icon: iconPath }, { label: 'Item2', submenu: [ { label: 'submenu1' }, { label: 'submenu2' } ] }, { label: 'Item3', type: 'radio', checked: true }, { label: 'Toggle DevTools', accelerator: 'Alt+Command+I', click: function() { win.show(); win.toggleDevTools(); } }, { label: 'Quit', accelerator: 'Command+Q', selector: 'terminate:', } ]); appIcon.setToolTip('This is my application.'); appIcon.setContextMenu(contextMenu); });
app.on('ready', function() { updateWindow = new BrowserWindow({width: 300, height: 300, icon: __dirname + '/icon.png', title: "Discord", 'auto-hide-menu-bar': true, frame: false}); updateWindow.setResizable(false); updateWindow.setAlwaysOnTop(true); updateWindow.setSkipTaskbar(true); updateWindow.loadURL('file://' + __dirname + '/update.html'); //When no updates //mainWindow = new BrowserWindow((data && data.bounds) ? data.bounds : {width: 1200, height: 900}); mainWindow = new BrowserWindow({width: 900, height: 750, icon: __dirname + '/icon.png', title: "Discord", 'auto-hide-menu-bar': true}); mainWindow.setBounds(data.bounds); webContents = mainWindow.webContents; updateWindow.close(); mainWindow.setTitle("Discord"); mainWindow.setMenuBarVisibility(false); mainWindow.loadURL('file://' + __dirname + '/index.html'); //Nullify any closed windows. mainWindow.on('closed', function() { //updateWindow.close(); mainWindow = null; }); updateWindow.on('closed', function(){ updateWindow = null; }); //Save settings when app is closed. mainWindow.on('close', function(){ var data = { bounds: mainWindow.getBounds(), minTray: minToTray, useCSS: useCustomCSS }; fs.writeFileSync(initPath, JSON.stringify(data)); }); var showButton = new MenuItem({ label: 'Show Discord', type: 'normal', click: function() { mainWindow.setSkipTaskbar(false); mainWindow.show(); } }); //Minimize to tray. (Only works on some OSs) var disMinButton = new MenuItem({ label: 'Disable Minimize to Tray', type: 'checkbox', checked: !minToTray, click: function() { if(disMinButton.checked == true){ minToTray = false; console.log("Disabled MinToTray"); } else if (disMinButton.checked == false) { minToTray = true; console.log("Enabled MinToTray"); } disMinButton.checked = !minToTray; } }); //Toggle CSS (Only works on some OSs?) var toggleCSS = new MenuItem({ label: 'Use Custom CSS', type: 'checkbox', checked: useCustomCSS, click: function() { if(toggleCSS.checked == true){ useCustomCSS = true; console.log("Disabled useCustomCSS"); } else if (toggleCSS.checked == false) { useCustomCSS = false; console.log("Enabled useCustomCSS"); } toggleCSS.checked = useCustomCSS; } }); mainWindow.on('close', function(event) { if(minToTray && !quitForReal){ event.preventDefault(); data.bounds = mainWindow.getBounds(); mainWindow.hide(); mainWindow.setSkipTaskbar(true); } }); //Tray Menu //menu.append(new MenuItem({ label: 'Show Discord', type: 'normal', click: function() { mainWindow.restore(); mainWindow.setSkipTaskbar(false); } })); //menu.append(showButton); - Depricated. Doesn't work in Ubuntu Unity menu.append(new MenuItem({label: 'Show Discord', type: 'normal', click: function(){ mainWindow.setSkipTaskbar(false); mainWindow.show(); } })); menu.append(new MenuItem({ type: 'separator' })); menu.append(new MenuItem({ label: 'Refresh Discord', type: 'normal', click: function(){ mainWindow.reload(); } })); menu.append(new MenuItem({ type: 'separator' })); menu.append(disMinButton); menu.append(toggleCSS); menu.append(new MenuItem({ type: 'separator' })); menu.append(new MenuItem({ label: 'Quit Discord', type: 'normal', click: function() { quitForReal = true; app.quit(); } })); appIcon = new Tray(__dirname + '/tray.png'); appIcon.setToolTip('Discord'); appIcon.setContextMenu(menu); appIcon.on('click', function(event){ mainWindow.setSkipTaskbar(false); mainWindow.show(); }); //Link fix webContents.on('new-window', function(event, urlToOpen) { event.preventDefault(); shell.openExternal(urlToOpen); }); //Allow refreshing and Show Window mainWindow.on('focus', function(){ //showButton.enabled = false; globalShortcut.register('ctrl+r', function () { mainWindow.reload(); }); }); //Disable refresh when not in focus. mainWindow.on('blur', function(){ //showButton.enabled = true; globalShortcut.unregister('ctrl+r'); }); mainWindow.webContents.on('will-navigate', function(event){ event.preventDefault(); }); });
app.on('ready', function(){ var appIcon = new Tray(iconIdle); initWindow(); appIcon.on('clicked', function clicked (e, bounds) { if (appIcon.window && appIcon.window.isVisible()) { return hideWindow(); } else { showWindow(bounds); } }); function initWindow () { var defaults = { width: 400, height: 350, show: false, frame: false, resizable: false, 'standard-window': false }; appIcon.window = new BrowserWindow(defaults); appIcon.window.loadUrl('file://' + __dirname + '/index.html'); appIcon.window.on('blur', hideWindow); initMenu(); } function showWindow (bounds) { var options = { x: bounds.x - 200 + (bounds.width / 2), y: bounds.y, index: path.join('./', 'index.html') }; appIcon.window.setPosition(options.x, options.y); appIcon.window.show(); } function initMenu () { var template = [{ label: 'Edit', submenu: [ { label: 'Copy', accelerator: 'Command+C', selector: 'copy:' }, { label: 'Paste', accelerator: 'Command+V', selector: 'paste:' }, { label: 'Select All', accelerator: 'Command+A', selector: 'selectAll:' } ] }]; var menu = Menu.buildFromTemplate(template); Menu.setApplicationMenu(menu); } function hideWindow () { if (!appIcon.window) { return; } appIcon.window.hide(); } ipc.on('reopen-window', function() { appIcon.window.show(); }); ipc.on('update-icon', function(event, arg) { if (arg === "TrayActive") { appIcon.setImage(iconActive); } else { appIcon.setImage(iconIdle); } }); ipc.on('app-quit', function() { app.quit(); }); app.dock.hide(); appIcon.setToolTip('GitHub Notifications on your menu bar.'); });
app.on('ready', function() { var cachedBounds; var appIcon = new Tray(iconIdle); var windowPosition = (isWindows) ? 'trayBottomCenter' : 'trayCenter'; initWindow(); appIcon.on('click', function (e, bounds) { if (e.altKey || e.shiftKey || e.ctrlKey || e.metaKey) return hideWindow(); if (appIcon.window && appIcon.window.isVisible()) return hideWindow(); bounds = bounds || cachedBounds; cachedBounds = bounds; showWindow(cachedBounds); }); function initWindow () { var defaults = { width: 600, height: 500, show: false, frame: false, resizable: true, webPreferences: { overlayScrollbars: true } }; appIcon.window = new BrowserWindow(defaults); appIcon.positioner = new Positioner(appIcon.window); appIcon.window.loadURL('file://' + __dirname + '/index.html'); appIcon.window.on('blur', hideWindow); appIcon.window.setVisibleOnAllWorkspaces(true); initMenu(); checkAutoUpdate(false); } function showWindow (trayPos) { var noBoundsPosition; if (!isDarwin && trayPos !== undefined) { var displaySize = electron.screen.getPrimaryDisplay().workAreaSize; var trayPosX = trayPos.x; var trayPosY = trayPos.y; if (isLinux) { var cursorPointer = electron.screen.getCursorScreenPoint(); trayPosX = cursorPointer.x; trayPosY = cursorPointer.y; } var x = (trayPosX < (displaySize.width / 2)) ? 'left' : 'right'; var y = (trayPosY < (displaySize.height / 2)) ? 'top' : 'bottom'; if (x === 'right' && y === 'bottom') { noBoundsPosition = (isWindows) ? 'trayBottomCenter' : 'bottomRight'; } else if (x === 'left' && y === 'bottom') { noBoundsPosition = 'bottomLeft'; } else if (y === 'top') { noBoundsPosition = (isWindows) ? 'trayCenter' : 'topRight'; } } else if (trayPos === undefined) { noBoundsPosition = (isWindows) ? 'bottomRight' : 'topRight'; } var position = appIcon.positioner.calculate(noBoundsPosition || windowPosition, trayPos); appIcon.window.setPosition(position.x, position.y); appIcon.window.show(); } function initMenu () { var template = [{ label: 'Edit', submenu: [ { label: 'Copy', accelerator: 'Command+C', selector: 'copy:' }, { label: 'Paste', accelerator: 'Command+V', selector: 'paste:' }, { label: 'Select All', accelerator: 'Command+A', selector: 'selectAll:' } ] }]; var menu = Menu.buildFromTemplate(template); Menu.setApplicationMenu(menu); } function hideWindow () { if (!appIcon.window) return; appIcon.window.hide(); } function checkAutoUpdate(showAlert) { var autoUpdateOptions = { repo: 'zalmoxisus/social-expert', currentVersion: app.getVersion() }; var update = new ghReleases(autoUpdateOptions, function (autoUpdater) { autoUpdater .on('error', function(event, message) { console.log('ERRORED.'); console.log('Event: ' + JSON.stringify(event) + '. MESSAGE: ' + message); }) .on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) { console.log('Update downloaded'); confirmAutoUpdate(quitAndUpdate); }); }); // Check for updates update.check(function (err, status) { if (err || !status) { if (showAlert) { dialog.showMessageBox({ type: 'info', buttons: ['Close'], title: 'No update available', message: 'You are currently running the latest version of Social Expert.' }); } app.dock.hide(); } if (!err && status) { update.download(); } }); } function confirmAutoUpdate(quitAndUpdate) { dialog.showMessageBox({ type: 'question', buttons: ['Update & Restart', 'Cancel'], title: 'Update Available', cancelId: 99, message: 'There is an update available. Would you like to update Social Expert now?' }, function (response) { console.log('Exit: ' + response); app.dock.hide(); if (response === 0) { quitAndUpdate(); } } ); } ipc.on('reopen-window', function() { showWindow(cachedBounds); }); ipc.on('update-icon', function(event, arg) { if (arg === 'TrayActive') { appIcon.setImage(iconActive); } else { appIcon.setImage(iconIdle); } }); ipc.on('startup-enable', function() { autoStart.enable(); }); ipc.on('startup-disable', function() { autoStart.disable(); }); ipc.on('check-updates', function() { checkAutoUpdate(true); }); ipc.on('app-quit', function() { app.quit(); }); appIcon.setToolTip('Social Expert'); });
app.on('ready', function() { appIcon = new Tray('/Users/kiichi/work/node/prj/blockme/src/tray.png'); var contextMenu = Menu.buildFromTemplate([ { label: '1 Hour', type: 'radio' }, { label: 'Until Noon', type: 'radio' }, { label: 'Until 5pm', type: 'radio', checked: true }, { label: 'Settings', type: 'radio' }, ]); appIcon.setToolTip('This is my application.'); appIcon.setContextMenu(contextMenu); // Create the browser window. // mainWindow = new BrowserWindow({width: 800, height: 600, "node-integration": false}); mainWindow = new BrowserWindow({width: 800, height: 600}); // and load the index.html of the app. mainWindow.loadUrl('file://' + __dirname + '/index.html'); // File open dialog test //var dialog = require('dialog'); //console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]})); ipc.on('load', function(event, arg) { console.log("load called"); console.log(arg); // prints some fs.readFile('/etc/hosts', 'utf8', function (err,data) { if (err) { return console.log(err); } console.log(data); event.returnValue = data; }); }); ipc.on('save', function(event, arg) { console.log("save called"); console.log(arg); // prints something fs.writeFile('test.txt', arg, function (err) { console.log('saved test...'); }); fs.writeFile('/etc/hosts', arg, function (err) { if (err) { return console.log(err); } console.log('saved hosts...'); }); event.returnValue = 'success'; }); ipc.on('online-status-changed', function(event, status) { console.log(status); }); // Emitted when the window is closed. mainWindow.on('closed', function() { // 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; }); });
ipc.on('vpn.disconnected', function handleDisconnected() { tray.setContextMenu(trayMenuDisconnected); tray.setImage(__dirname + '/tray.png'); tray.setToolTip('Disconnected'); });
app.on('ready', function () { var screen = require('screen') var size = screen.getPrimaryDisplay().workAreaSize var width = 500 var height = 600 var defaultX = isMac ? size.width / 2 - width/2 : size.width - width - 10 var defaultY = isMac ? 20 : size.height - height - 10 win = new BrowserWindow({ "x": defaultX, "y": defaultY, "width": width, "height": height, "frame": false, "resizable": false, "center": false, "skip-taskbar" : true, "show": false }) win.loadUrl('file://' + app.getAppPath() + '/pages/index.html') tray = new Tray(app.getAppPath() + (isMac ? '/assets/images/mac-tray.png' : '/assets/images/win-tray.png')) tray.setToolTip('fewords app') tray.on('clicked', function (e, bound) { var x = bound.x + bound.width / 2 - win.getBounds().width / 2 var y = bound.y + bound.height - 1 if(isWindows) { x = Math.min(x, defaultX) y = defaultY } win.setPosition(x, y) win.isVisible() ? win.hide() : win.show() }) //win.openDevTools() //win下点击tary会触发blur win.on('blur', function () { if(alwaysOnTop) return setTimeout(function() { win.hide() }, isMac ? 0 : 200) }) win.on('closed', function () { win = null }) ipc.on('quit', function () { tray && tray.destroy() tray = null win.close() app.quit() }) ipc.on('toggleView', function () { win.isVisible() ? win.hide() : win.show() }) ipc.on('alwaysOnTop', function() { alwaysOnTop = !alwaysOnTop win.setAlwaysOnTop(alwaysOnTop) }) //解决不能剪贴板操作的问题 var template = [{ label: "Application", submenu: [ { label: "About Application", selector: "orderFrontStandardAboutPanel:" }, { type: "separator" }, { label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); }} ]}, { label: "Edit", submenu: [ { label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" }, { label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" }, { type: "separator" }, { label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" }, { label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" }, { label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" }, { label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" } ]} ]; Menu.setApplicationMenu(Menu.buildFromTemplate(template)); })
app.on('ready', function() { var icon = path.join(__dirname, 'assets', 'icon.png'); mainWindow = new BrowserWindow({ width: 1000, height: 710, "web-preferences": { "web-security": false, "direct-write": true, "overlay-scrollbars": false }, icon: icon }); mainWindow.loadUrl('https://wx.qq.com/?lang=zh_CN'); if(debug){ mainWindow.toggleDevTools(); //测试:打开调试窗口 } mainWindow.on('close', function(event){ var canClose = !config.items.hideOnClose; if(canClose){ return true; } if(mainWindow.isVisible()){ mainWindow.hide(); event.preventDefault(); } }); mainWindow.on('closed', function() { app.exit(); //主窗口关闭,直接退出 }); var showHide = function(){ var isVisible = mainWindow.isVisible(); if(isVisible){ mainWindow.hide(); }else{ mainWindow.show(); mainWindow.focus(); } }; //写入托盘图标 var trayMenu = Menu.buildFromTemplate([{ label: '显示/隐藏', click: showHide },{ label: '设置', click: function(){ if(cfgWindow){ cfgWindow.focus(); return; } cfgWindow = new BrowserWindow({ height: 400, width: 600, resizable: false, icon: icon }); cfgWindow.loadUrl('file://' + __dirname + '/browser/config/index.html'); cfgWindow.on('closed', function() { cfgWindow = null; //GC }); if(debug){ cfgWindow.openDevTools(); //测试:打开调试窗口 } cfgWindow.webContents.executeJavaScript('vm.setValue('+ JSON.stringify(config.items) +')'); } },{ label: '退出', click: function(){ app.exit(); } }]); var trayIcon = new Tray(icon); trayIcon.setToolTip('SeiChat'); trayIcon.setContextMenu(trayMenu); trayIcon.on('clicked', showHide); //写入初始化脚本 var initJs = path.join(__dirname, 'browser', 'init.js'); var web = mainWindow.webContents; web.on('did-finish-load', function(){ fs.readFile(initJs, function(err, data){ var js = data.toString(); web.executeJavaScript(js); }); }); //监听接口 var msgWidth = 320, msgHeight = 80; var closeTimeoutID = null; var setDelayClose = function(){ if(closeTimeoutID){ clearTimeout(closeTimeoutID); } if(config.items.hideTimeout <= 0){ return false; } closeTimeoutID = setTimeout(function(){ if(msgWindow){ msgWindow.close(); } }, config.items.hideTimeout); } ipc.on('new-message', function(event, arg){ if(arg.isSend || !arg.unread){ return; } if(!mainWindow.isFocused()){ //焦点不在时才闪烁,否则超级鬼畜的,不信你试试? mainWindow.flashFrame(true); } //检查配置 var canShow = config.items.tipWinCondition == 'always' || (config.items.tipWinCondition == 'auto' && !mainWindow.isVisible()); if(!canShow){ return; } //检查是否已经有了消息接口 if(closeTimeoutID){ clearTimeout(closeTimeoutID); } if(msgWindow){ var size = msgWindow.getSize(); msgWindow.setSize(size[0], size[1] + msgHeight); var pos = msgWindow.getPosition(); msgWindow.setPosition(pos[0], pos[1] - msgHeight); msgWindow.webContents.executeJavaScript("vm.$data.messages.push("+JSON.stringify(arg)+");"); }else{ //创建消息窗口 msgWindow = new BrowserWindow({ x: workAreaSize.width - msgWidth, y: workAreaSize.height - msgHeight, height: msgHeight, width: msgWidth, resizable: false, 'always-on-top': true, 'skip-taskbar': true, frame: false, icon: icon }); //不给焦点 msgWindow.blurWebView(); msgWindow.loadUrl('file://' + __dirname + '/browser/tip/index.html'); setTimeout(function(){ msgWindow.webContents.executeJavaScript("vm.$data.messages.push("+JSON.stringify(arg)+");"); }, 100); msgWindow.on('closed', function() { msgWindow = null; //GC closeTimeoutID = null; }); } setDelayClose(); }); ipc.on('message-close', function(event, remainMessages){ if(remainMessages == 0){ if(msgWindow){ msgWindow.close(); } }else{ var size = msgWindow.getSize(); msgWindow.setSize(size[0], size[1] - msgHeight); var pos = msgWindow.getPosition(); msgWindow.setPosition(pos[0], pos[1] + msgHeight); } }); ipc.on('message-delay', function(){ setDelayClose(); }); ipc.on('message-do-not-close', function(){ clearTimeout(closeTimeoutID); }); ipc.on('close-config-window', function(event){ cfgWindow.close(); }); ipc.on('save-config', function(event, data){ config.save(data); }); ipc.on('call-webmm', function(event, data){ //执行WebMM的逻辑js //data:{ // call: 'logic', // sub: 'sendMsg', // method: 'sendText' // data: { // Msg: { // FromUserName: "", // ToUserName: "", // Type: 1, // Content: "the quick brown fox jumps over the lazy dog" // } // } //} mainWindow.webContents.executeJavaScript("WebMM." + data.call + "('" + data.sub + "')." + data.method + "(" + JSON.stringify(data.data) + ",{});" ); }); });
app.on('ready', function () { mainWindow = new BrowserWindow({ title: 'BarSoundz', width: 1024, height: 768, titleBarStyle: 'hidden', nodeIntegration: true }); var contextMenu = Menu.buildFromTemplate([ { label: 'Radius Search...', type: 'normal', click: function () { mainWindow.webContents.send('navigateTo', 'RadiusSearch'); } }, { label: 'Quit', accelerator: 'Command+Q', selector: 'terminate:' } ]); trayApp = new Tray(trayIconPath); trayApp.setToolTip('BoardZ2'); trayApp.setContextMenu(contextMenu); globalShortcut.register('CmdOrCtrl+Shift+d', function () { mainWindow.webContents.toggleDevTools(); }); mainWindow.loadURL('file://' + __dirname + '/index.html'); mainWindow.setTitle(app.getName()); mainWindow.on('closed', function () { mainWindow = null; }); if (client) { client.create(mainWindow); } if (process.platform == 'darwin') { var template = [{ label: "Application", submenu: [ { label: "About Application", selector: "orderFrontStandardAboutPanel:" }, { type: "separator" }, { label: "Reload", accelerator: "CmdOrCtrl+R", click: function () { mainWindow.loadURL('file://' + __dirname + '/index.html'); } }, { label: "Quit", accelerator: "Command+Q", click: function () { app.quit(); } } ] }, { label: "Edit", submenu: [ { label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" }, { label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" }, { type: "separator" }, { label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" }, { label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" }, { label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" }, { label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" } ] } ]; Menu.setApplicationMenu(Menu.buildFromTemplate(template)); } });
app.on("ready", function() { // Create the browser window. mainWindow = new BrowserWindow({ height : 640, width : 1024, "min-height" : 520, "min-width" : 980, show : false, title : APP_NAME, }); // Open the DevTools. //mainWindow.openDevTools(); // Make sure we don't get multiple app windows on Windows singleInstance.ensureSingleInstance("parrot-messaging", mainWindow); // and load the index.html of the app. mainWindow.loadUrl("file://" + __dirname + "/index.html"); mainWindow.show(); // Create/set the main menu menu = Menu.buildFromTemplate(menuTemplate); Menu.setApplicationMenu(menu); // Allow the window to get garbage collected after it's closed mainWindow.on("closed", function() { mainWindow = null; }); // Prevent BrowserWindow from navigating when user drags/drops files mainWindow.webContents.on("will-navigate", function(event) { event.preventDefault(); }); // Handle external URLs mainWindow.webContents.on("new-window", function(event, url) { shell.openExternal(url); event.preventDefault(); }); mainWindow.webContents.session.setDownloadPath(pathHelpers.getDownloadPath()); // // OS X-specific config // if (process.platform === "darwin") { // Hide the window on close rather than quitting the app, // and make sure to really close the window when quitting. mainWindow.on("close", function(event) { if (mainWindow.forceClose) return; event.preventDefault(); mainWindow.hide(); }); app.on("before-quit", function(event) { mainWindow.forceClose = true; }); ipc.on("notification-clicked", function(event) { mainWindow.show(); }); app.on("activate-with-no-open-windows", function(event) { mainWindow.show(); }); } // // Windows-specific config // if (process.platform === "win32") { var notificationInfo = null; trayIcon = new Tray(__dirname + "/assets/tray-icon.png"); trayIcon.setToolTip("Parrot"); trayIcon.on("balloon-clicked", function(event) { mainWindow.restore(); mainWindow.webContents.send("message", "balloon-clicked", notificationInfo.networkId, notificationInfo.conversationId, notificationInfo.messageId ); }); trayIcon.on("balloon-closed", function(event) { mainWindow.webContents.send("message", "balloon-closed"); notificationInfo = null; }); ipc.on("show-balloon", function(event, icon, title, body, networkId, conversationId, messageId) { trayIcon.displayBalloon({ // TODO: NativeImage can't create an image from a URL //icon : NativeImage.createFromPath(icon), title : title, content : body, }); notificationInfo = { networkId : networkId, conversationId : conversationId, messageId : messageId, }; }); app.on("window-all-closed", function() { app.quit(); }); } });
ipc.on('vpn.connecting', function handleConnecting() { tray.setContextMenu(trayMenuConnecting); tray.setImage(__dirname + '/tray_connecting.png'); tray.setToolTip('Connecting...'); });