1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-28 12:35:40 +01:00

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}}
</div>
<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="checkbox">
<label for="disableFavicons">
@ -44,13 +34,23 @@
</div>
<div class="form-group">
<div class="checkbox">
<label for="enableHideInTray">
<input id="enableHideInTray" type="checkbox" name="EnableHideInTray"
[(ngModel)]="enableHideInTray" (change)="saveHideInTray()">
{{'enableHideInTray' | i18n}}
<label for="enableMinToTray">
<input id="enableMinToTray" type="checkbox" name="EnableMinToTray"
[(ngModel)]="enableMinToTray" (change)="saveMinToTray()">
{{'enableMinToTray' | i18n}}
</label>
</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 class="form-group">
<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 { ConstantsService } from 'jslib/services/constants.service';
import { DesktopConstantsService } from '../../services/desktopconstants.service';
import { DesktopConstants } from '../../desktopConstants';
@Component({
selector: 'app-settings',
@ -24,7 +25,7 @@ export class SettingsComponent implements OnInit {
lockOption: number = null;
disableGa: boolean = false;
disableFavicons: boolean = false;
enableHideInTray: boolean = false;
enableMinToTray: boolean = false;
locale: string;
lockOptions: any[];
localeOptions: any[];
@ -57,7 +58,7 @@ export class SettingsComponent implements OnInit {
async ngOnInit() {
this.lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
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);
const disableGa = await this.storageService.get<boolean>(ConstantsService.disableGaKey);
@ -86,9 +87,9 @@ export class SettingsComponent implements OnInit {
this.callAnalytics('Favicons', !this.disableFavicons);
}
async saveHideInTray() {
await this.storageService.save(DesktopConstantsService.enableHideInTrayKey, this.enableHideInTray);
this.callAnalytics('HideInTray', this.enableHideInTray);
async saveMinToTray() {
await this.storageService.save(DesktopConstants.enableMinimizeToTrayKey, this.enableMinToTray);
this.callAnalytics('MinimizeToTray', this.enableMinToTray);
}
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": {
"message": "Website Icons provide a recognizable image next to each login item in your vault."
},
"enableHideInTray": {
"message": "Hide Bitwarden in tray"
"enableMinToTray": {
"message": "Minimize to Tray"
},
"enableHideInTrayDesc": {
"message": "Bitwarden will stay in your system tray when minimizing the window."
"enableMinToTrayDesc": {
"message": "When minimizing the window, run Bitwarden as a system tray icon."
},
"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 { ElectronStorageService } from 'jslib/electron/services/electronStorage.service';
import { WindowMain } from 'jslib/electron/window.main';
import { DesktopConstants } from './desktopConstants';
export class Main {
logService: ElectronLogService;
@ -68,7 +69,9 @@ export class Main {
this.updaterMain = new UpdaterMain(this);
this.menuMain = new MenuMain(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.messagingMain.onMessage(message);

View File

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