From bec143445298a49505ea7ef8588d2c590d936427 Mon Sep 17 00:00:00 2001 From: Maigo Erit Date: Wed, 23 Aug 2017 20:38:46 +0300 Subject: [PATCH] hide dock icon. --- electron/app/window-manager.ts | 208 ++++++++++++++++----------------- 1 file changed, 100 insertions(+), 108 deletions(-) diff --git a/electron/app/window-manager.ts b/electron/app/window-manager.ts index c0fa3433..7c6465a0 100644 --- a/electron/app/window-manager.ts +++ b/electron/app/window-manager.ts @@ -1,121 +1,113 @@ import * as menubar from 'menubar'; -import MenuBuilder from "./menu-builder"; +import MenuBuilder from './menu-builder'; -import { app, ipcMain, BrowserWindow } from "electron"; -import config from "./config"; -import * as path from "path"; -import * as os from "os"; -import { sequelize } from "./models/index"; +import { app, ipcMain, BrowserWindow } from 'electron'; +import config from './config'; +import * as path from 'path'; +import * as os from 'os'; +import { sequelize } from './models/index'; -import { logManager } from "./log-manager"; +import { logManager } from './log-manager'; let logger = logManager.getLogger('WindowManager'); export default class WindowManager { - static mainWindow; - static menubar; - - constructor() { - - } - static initMenus() { - const menuBuilder = new MenuBuilder(this.mainWindow); - menuBuilder.buildMenu(); - } - - static setMainWindow() { - logger.info("Creating main window."); - this.mainWindow = new BrowserWindow({ - width: 1200, - height: 1000, - show: true, - title: 'Tockler', - icon: config.iconBig - }); - - this.mainWindow.maximize(); - this.mainWindow.loadURL('file://' + config.client + '/index.html'); - - this.mainWindow.on('closed', () => { - this.mainWindow = null; - console.log('Main window closed'); - }); - - this.mainWindow.on('focus', () => { - let sendEventName = 'main-window-focus'; - console.log("Sending focus event: " + sendEventName); - this.mainWindow.webContents.send(sendEventName, 'ping'); - }); - - this.mainWindow.webContents.on('did-finish-load', () => { - console.log("did-finish-load'"); - this.mainWindow.show(); - this.mainWindow.focus(); - }); - - this.mainWindow.on('close', () => { - if (this.mainWindow) { - console.log("Closing window"); - this.mainWindow = null; - } - }); - - } - - - static initMainWindowEvents() { - logger.info("Init main window events."); - ipcMain.on('toggle-main-window', (ev, name) => { - if (!this.mainWindow) { - console.log("MainWindow closed, opening"); - WindowManager.setMainWindow(); - } - - console.log("Toggling main window"); - if (this.mainWindow.isVisible()) { - console.log("Show main window"); - this.mainWindow.show(); - } else if (this.mainWindow.isMinimized()) { - console.log("Restore main window"); - this.mainWindow.restore(); - } else { - console.log("Hide main window"); - this.mainWindow.hide(); - } - - }); - } - - static setTrayWindow() { - logger.info("Creating tray window."); - /** + static mainWindow; + static menubar; + + constructor() {} + static initMenus() { + const menuBuilder = new MenuBuilder(this.mainWindow); + menuBuilder.buildMenu(); + } + + static setMainWindow() { + logger.info('Creating main window.'); + this.mainWindow = new BrowserWindow({ + width: 1200, + height: 1000, + show: true, + title: 'Tockler', + icon: config.iconBig, + }); + + this.mainWindow.maximize(); + this.mainWindow.loadURL('file://' + config.client + '/index.html'); + + this.mainWindow.on('closed', () => { + this.mainWindow = null; + console.log('Main window closed'); + }); + + this.mainWindow.on('focus', () => { + let sendEventName = 'main-window-focus'; + console.log('Sending focus event: ' + sendEventName); + this.mainWindow.webContents.send(sendEventName, 'ping'); + }); + + this.mainWindow.webContents.on('did-finish-load', () => { + console.log("did-finish-load'"); + this.mainWindow.show(); + this.mainWindow.focus(); + }); + + this.mainWindow.on('close', () => { + if (this.mainWindow) { + console.log('Closing window'); + this.mainWindow = null; + } + }); + } + + static initMainWindowEvents() { + logger.info('Init main window events.'); + ipcMain.on('toggle-main-window', (ev, name) => { + if (!this.mainWindow) { + console.log('MainWindow closed, opening'); + WindowManager.setMainWindow(); + } + + console.log('Toggling main window'); + if (this.mainWindow.isVisible()) { + console.log('Show main window'); + this.mainWindow.show(); + } else if (this.mainWindow.isMinimized()) { + console.log('Restore main window'); + this.mainWindow.restore(); + } else { + console.log('Hide main window'); + this.mainWindow.hide(); + } + }); + } + + static setTrayWindow() { + logger.info('Creating tray window.'); + /** * Docs: * https://github.com/maxogden/menubar */ - let icon = (os.platform() == 'darwin') ? config.icon : config.iconBig; - this.menubar = menubar({ - index: 'file://' + config.client + '/index.html', - icon: icon, - preloadWindow: true, - showDockIcon: true, - width: 400, - height: 500 - }); - - this.menubar.on('after-create-window', () => { - - }); - this.menubar.on('after-show', () => { - console.log('Show tray'); - this.menubar.window.webContents.send('focus-tray', 'ping'); - - if (config.isDev) { - console.log('Open menubar dev tools'); - this.menubar.window.openDevTools(); - } - }); - } + let icon = os.platform() == 'darwin' ? config.icon : config.iconBig; + this.menubar = menubar({ + index: 'file://' + config.client + '/index.html', + icon: icon, + preloadWindow: true, + showDockIcon: false, + width: 400, + height: 500, + }); + + this.menubar.on('after-create-window', () => {}); + this.menubar.on('after-show', () => { + console.log('Show tray'); + this.menubar.window.webContents.send('focus-tray', 'ping'); + + if (config.isDev) { + console.log('Open menubar dev tools'); + this.menubar.window.openDevTools(); + } + }); + } } export const windowManager = new WindowManager(); -