Add minimize when copying to clipboard option (#390)

* Add minimize when copying to clipboard option

* Change minimizeOnCopyToClipboardKey constant reference and fix whitespace

* Extend feature to context menus and view component

* Cleanup and refactor methods

* Refactor copy method and add minimizeOnCopyToClipboardKey constant to electronConstants.ts

* Use window.main subclass and fix formatting

* Revert "Use window.main subclass and fix formatting"

This reverts commit 0159613751a54bc886fac0b34bd09d3a26498924.

* Reimplement part of 0159613751a54bc886fac0b34bd09d3a26498924

* Add null check to VaultComponent::copyValue

* Remove unused import
This commit is contained in:
Elias Papavasileiou 2020-04-14 23:11:41 +03:00 committed by GitHub
parent 0faa987f41
commit a84af15c93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 1 deletions

View File

@ -59,6 +59,16 @@
</select>
<small class="help-block">{{'clearClipboardDesc' | i18n}}</small>
</div>
<div class="form-group">
<div class="checkbox">
<label for="minimizeOnCopyToClipboard">
<input id="minimizeOnCopyToClipboard" type="checkbox" name="MinimizeOnCopyToClipboard"
[(ngModel)]="minimizeOnCopyToClipboard" (change)="saveMinOnCopyToClipboard()">
{{'minimizeOnCopyToClipboard' | i18n}}
</label>
</div>
<small class="help-block">{{'minimizeOnCopyToClipboardDesc' | i18n}}</small>
</div>
<div class="form-group">
<div class="checkbox">
<label for="disableFavicons">

View File

@ -38,6 +38,7 @@ export class SettingsComponent implements OnInit {
enableTray: boolean = false;
showMinToTray: boolean = false;
startToTray: boolean = false;
minimizeOnCopyToClipboard: boolean = false;
locale: string;
vaultTimeouts: any[];
localeOptions: any[];
@ -122,6 +123,8 @@ export class SettingsComponent implements OnInit {
this.locale = await this.storageService.get<string>(ConstantsService.localeKey);
this.theme = await this.storageService.get<string>(ConstantsService.themeKey);
this.clearClipboard = await this.storageService.get<number>(ConstantsService.clearClipboardKey);
this.minimizeOnCopyToClipboard = await this.storageService.get<boolean>(
ElectronConstants.minimizeOnCopyToClipboardKey);
}
async saveVaultTimeoutOptions() {
@ -227,6 +230,11 @@ export class SettingsComponent implements OnInit {
window.setTimeout(() => window.location.reload(), 200);
}
async saveMinOnCopyToClipboard() {
await this.storageService.save(ElectronConstants.minimizeOnCopyToClipboardKey, this.minimizeOnCopyToClipboard);
this.callAnalytics('MinOnCopyToClipboard', this.minimizeOnCopyToClipboard);
}
async saveClearClipboard() {
await this.storageService.save(ConstantsService.clearClipboardKey, this.clearClipboard);
this.analytics.eventTrack.next({

View File

@ -660,6 +660,9 @@ export class VaultComponent implements OnInit, OnDestroy {
this.platformUtilsService.copyToClipboard(value);
this.toasterService.popAsync('info', null,
this.i18nService.t('valueCopied', this.i18nService.t(labelI18nKey)));
if (this.viewComponent != null && this.action === 'view') {
this.viewComponent.minimizeIfNeeded();
}
});
}

View File

@ -12,7 +12,9 @@ import { CipherService } from 'jslib/abstractions/cipher.service';
import { CryptoService } from 'jslib/abstractions/crypto.service';
import { EventService } from 'jslib/abstractions/event.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { StorageService } from 'jslib/abstractions/storage.service';
import { TokenService } from 'jslib/abstractions/token.service';
import { TotpService } from 'jslib/abstractions/totp.service';
import { UserService } from 'jslib/abstractions/user.service';
@ -23,6 +25,8 @@ import { ViewComponent as BaseViewComponent } from 'jslib/angular/components/vie
import { CipherView } from 'jslib/models/view/cipherView';
import { ElectronConstants } from 'jslib/electron/electronConstants';
@Component({
selector: 'app-vault-view',
templateUrl: 'view.component.html',
@ -35,7 +39,8 @@ export class ViewComponent extends BaseViewComponent implements OnChanges {
cryptoService: CryptoService, platformUtilsService: PlatformUtilsService,
auditService: AuditService, broadcasterService: BroadcasterService,
ngZone: NgZone, changeDetectorRef: ChangeDetectorRef,
userService: UserService, eventService: EventService) {
userService: UserService, eventService: EventService,
private messagingService: MessagingService, private storageService: StorageService) {
super(cipherService, totpService, tokenService, i18nService, cryptoService, platformUtilsService,
auditService, window, broadcasterService, ngZone, changeDetectorRef, userService, eventService);
}
@ -48,4 +53,17 @@ export class ViewComponent extends BaseViewComponent implements OnChanges {
this.platformUtilsService.eventTrack('View Password History');
this.onViewCipherPasswordHistory.emit(this.cipher);
}
copy(value: string, typeI18nKey: string, aType: string) {
super.copy(value, typeI18nKey, aType);
this.minimizeIfNeeded();
}
async minimizeIfNeeded(): Promise<void> {
const shouldMinimize = await this.storageService.get<boolean>(
ElectronConstants.minimizeOnCopyToClipboardKey);
if (shouldMinimize) {
this.messagingService.send('minimize');
}
}
}

View File

@ -112,6 +112,12 @@
"message": "Copy Value",
"description": "Copy value to clipboard"
},
"minimizeOnCopyToClipboard": {
"message": "Minimize when copying to clipboard"
},
"minimizeOnCopyToClipboardDesc": {
"message": "Bitwarden will minimize when credentials are copied to clipboard."
},
"toggleVisibility": {
"message": "Toggle Visibility"
},

View File

@ -23,6 +23,11 @@ export class MessagingMain {
this.main.menuMain.updateApplicationMenuState(message.isAuthenticated, message.isLocked);
this.updateTrayMenu(message.isAuthenticated, message.isLocked);
break;
case 'minimize':
if (this.main.windowMain.win != null) {
this.main.windowMain.win.minimize();
}
break;
case 'showTray':
this.main.trayMain.showTray();
break;