some fixes for tray icon

This commit is contained in:
Kyle Spearrin 2018-05-04 13:16:12 -04:00
parent 0f2d1e73b4
commit db0986e95f
9 changed files with 55 additions and 47 deletions

2
jslib

@ -1 +1 @@
Subproject commit c29b53cdd62369de59f6ae483b78b9bcc67d9238 Subproject commit c3dad8fd1ae862476ccc417b4d33eecd3edd61a9

View File

@ -22,16 +22,6 @@
{{'options' | i18n}} {{'options' | i18n}}
</div> </div>
<div class="box-content box-content-padded"> <div class="box-content box-content-padded">
<div class="form-group">
<div class="checkbox">
<label for="disableGa">
<input id="disableGa" type="checkbox" name="DisableAnalytics"
[(ngModel)]="disableGa" (change)="saveGa()">
{{'disableGa' | i18n}}
</label>
</div>
<small class="help-block">{{'gaDesc' | i18n}}</small>
</div>
<div class="form-group"> <div class="form-group">
<div class="checkbox"> <div class="checkbox">
<label for="disableFavicons"> <label for="disableFavicons">
@ -44,13 +34,23 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="checkbox"> <div class="checkbox">
<label for="enableHideInTray"> <label for="enableMinToTray">
<input id="enableHideInTray" type="checkbox" name="EnableHideInTray" <input id="enableMinToTray" type="checkbox" name="EnableMinToTray"
[(ngModel)]="enableHideInTray" (change)="saveHideInTray()"> [(ngModel)]="enableMinToTray" (change)="saveMinToTray()">
{{'enableHideInTray' | i18n}} {{'enableMinToTray' | i18n}}
</label> </label>
</div> </div>
<small class="help-block">{{'enableHideInTrayDesc' | i18n}}</small> <small class="help-block">{{'enableMinToTrayDesc' | i18n}}</small>
</div>
<div class="form-group">
<div class="checkbox">
<label for="disableGa">
<input id="disableGa" type="checkbox" name="DisableAnalytics"
[(ngModel)]="disableGa" (change)="saveGa()">
{{'disableGa' | i18n}}
</label>
</div>
<small class="help-block">{{'gaDesc' | i18n}}</small>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="locale">{{'language' | i18n}}</label> <label for="locale">{{'language' | i18n}}</label>

View File

@ -14,7 +14,8 @@ import { StateService } from 'jslib/abstractions/state.service';
import { StorageService } from 'jslib/abstractions/storage.service'; import { StorageService } from 'jslib/abstractions/storage.service';
import { ConstantsService } from 'jslib/services/constants.service'; import { ConstantsService } from 'jslib/services/constants.service';
import { DesktopConstantsService } from '../../services/desktopconstants.service';
import { DesktopConstants } from '../../desktopConstants';
@Component({ @Component({
selector: 'app-settings', selector: 'app-settings',
@ -24,7 +25,7 @@ export class SettingsComponent implements OnInit {
lockOption: number = null; lockOption: number = null;
disableGa: boolean = false; disableGa: boolean = false;
disableFavicons: boolean = false; disableFavicons: boolean = false;
enableHideInTray: boolean = false; enableMinToTray: boolean = false;
locale: string; locale: string;
lockOptions: any[]; lockOptions: any[];
localeOptions: any[]; localeOptions: any[];
@ -57,7 +58,7 @@ export class SettingsComponent implements OnInit {
async ngOnInit() { async ngOnInit() {
this.lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey); this.lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
this.disableFavicons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey); this.disableFavicons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey);
this.enableHideInTray = await this.storageService.get<boolean>(DesktopConstantsService.enableHideInTrayKey); this.enableMinToTray = await this.storageService.get<boolean>(DesktopConstants.enableMinimizeToTrayKey);
this.locale = await this.storageService.get<string>(ConstantsService.localeKey); this.locale = await this.storageService.get<string>(ConstantsService.localeKey);
const disableGa = await this.storageService.get<boolean>(ConstantsService.disableGaKey); const disableGa = await this.storageService.get<boolean>(ConstantsService.disableGaKey);
@ -86,9 +87,9 @@ export class SettingsComponent implements OnInit {
this.callAnalytics('Favicons', !this.disableFavicons); this.callAnalytics('Favicons', !this.disableFavicons);
} }
async saveHideInTray() { async saveMinToTray() {
await this.storageService.save(DesktopConstantsService.enableHideInTrayKey, this.enableHideInTray); await this.storageService.save(DesktopConstants.enableMinimizeToTrayKey, this.enableMinToTray);
this.callAnalytics('HideInTray', this.enableHideInTray); this.callAnalytics('MinimizeToTray', this.enableMinToTray);
} }
async saveLocale() { async saveLocale() {

3
src/desktopConstants.ts Normal file
View File

@ -0,0 +1,3 @@
export class DesktopConstants {
static readonly enableMinimizeToTrayKey: string = 'enableMinimizeToTray';
}

BIN
src/images/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -770,11 +770,11 @@
"disableFaviconDesc": { "disableFaviconDesc": {
"message": "Website Icons provide a recognizable image next to each login item in your vault." "message": "Website Icons provide a recognizable image next to each login item in your vault."
}, },
"enableHideInTray": { "enableMinToTray": {
"message": "Hide Bitwarden in tray" "message": "Minimize to Tray"
}, },
"enableHideInTrayDesc": { "enableMinToTrayDesc": {
"message": "Bitwarden will stay in your system tray when minimizing the window." "message": "When minimizing the window, run Bitwarden as a system tray icon."
}, },
"language": { "language": {
"message": "Language" "message": "Language"

View File

@ -16,6 +16,7 @@ import { ElectronLogService } from 'jslib/electron/services/electronLog.service'
import { ElectronMainMessagingService } from 'jslib/electron/services/electronMainMessaging.service'; import { ElectronMainMessagingService } from 'jslib/electron/services/electronMainMessaging.service';
import { ElectronStorageService } from 'jslib/electron/services/electronStorage.service'; import { ElectronStorageService } from 'jslib/electron/services/electronStorage.service';
import { WindowMain } from 'jslib/electron/window.main'; import { WindowMain } from 'jslib/electron/window.main';
import { DesktopConstants } from './desktopConstants';
export class Main { export class Main {
logService: ElectronLogService; logService: ElectronLogService;
@ -68,7 +69,9 @@ export class Main {
this.updaterMain = new UpdaterMain(this); this.updaterMain = new UpdaterMain(this);
this.menuMain = new MenuMain(this); this.menuMain = new MenuMain(this);
this.powerMonitorMain = new PowerMonitorMain(this); this.powerMonitorMain = new PowerMonitorMain(this);
this.trayMain = new TrayMain(this); this.trayMain = new TrayMain(this.windowMain, 'Bitwarden', async () => {
return await this.storageService.get<boolean>(DesktopConstants.enableMinimizeToTrayKey);
});
this.messagingService = new ElectronMainMessagingService(this.windowMain, (message) => { this.messagingService = new ElectronMainMessagingService(this.windowMain, (message) => {
this.messagingMain.onMessage(message); this.messagingMain.onMessage(message);

View File

@ -1,34 +1,37 @@
import { Tray } from 'electron'; import { Tray } from 'electron';
import * as Path from 'path'; import * as path from 'path';
import { Main } from '../main';
import { DesktopConstantsService } from '../services/desktopconstants.service'; import { WindowMain } from 'jslib/electron/window.main';
import { DesktopConstants } from '../desktopConstants';
export class TrayMain { export class TrayMain {
private tray: Tray; private tray: Tray;
private iconPath: string; private iconPath: string;
constructor(private main: Main) { constructor(private windowMain: WindowMain, private appName: string, private minToTray: () => Promise<boolean>) {
if (process.platform === 'win32') { if (process.platform === 'win32') {
this.iconPath = Path.join(__dirname, '../resources/icon.ico'); this.iconPath = path.join(__dirname, '/images/icon.ico');
} else { } else {
this.iconPath = Path.join(__dirname, '../resources/icon.png'); this.iconPath = path.join(__dirname, '/images/icon.png');
} }
} }
init() { init() {
this.main.windowMain.win.on('minimize', async (event: Event) => { this.windowMain.win.on('minimize', async (e: Event) => {
if (await this.main.storageService.get<boolean>(DesktopConstantsService.enableHideInTrayKey)) { if (await this.minToTray()) {
event.preventDefault(); e.preventDefault();
await this.handleHideEvent(); await this.handleHideEvent();
} }
}); });
this.main.windowMain.win.on('show', async (event: Event) => {
this.windowMain.win.on('show', async (e: Event) => {
await this.handleShowEvent(); await this.handleShowEvent();
}); });
} }
private handleShowEvent() { private handleShowEvent() {
if (this.tray) { if (this.tray != null) {
this.tray.destroy(); this.tray.destroy();
this.tray = null; this.tray = null;
} }
@ -36,13 +39,16 @@ export class TrayMain {
private handleHideEvent() { private handleHideEvent() {
this.tray = new Tray(this.iconPath); this.tray = new Tray(this.iconPath);
this.tray.setToolTip(this.appName);
this.tray.on('click', () => { this.tray.on('click', () => {
if (this.main.windowMain.win.isVisible()) { if (this.windowMain.win.isVisible()) {
this.main.windowMain.win.hide(); this.windowMain.win.hide();
} else { } else {
this.main.windowMain.win.show(); this.windowMain.win.show();
} }
}); });
this.main.windowMain.win.hide();
this.windowMain.win.hide();
} }
} }

View File

@ -1,5 +0,0 @@
export class DesktopConstantsService {
static readonly enableHideInTrayKey: string = 'enableHideInTray';
readonly enableHideInTrayKey: string = DesktopConstantsService.enableHideInTrayKey;
}