-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify "keepass-request" component
- Loading branch information
Showing
12 changed files
with
120 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...pp/+shared/keepass-request.component.html → .../+accounts/keepass-request.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
<div class="progress"> | ||
<div>KeePass: {{ message || "Requesting..." }}</div> | ||
<div class="progress-bar bg-success" role="progressbar" [style.width.%]="tick"></div> | ||
<div class="progress-bar bg-success" role="progressbar" [style.width.%]="progressTick"></div> | ||
</div> | ||
|
||
<div (click)="!locked && toggle()" class="control" [ngClass]="{locked: locked}"> | ||
<div (click)="!locked && togglePause()" class="control" [ngClass]="{locked: locked}"> | ||
<i class="fa" [ngClass]="{ | ||
'fa-ban text-danger': locked, | ||
'fa-pause text-warning': (counter$ | async | async), | ||
'fa-play text-success': !(counter$ | async | async) | ||
'fa-play text-success': paused && !locked, | ||
'fa-pause text-warning': !paused && !locked | ||
}"></i> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import {BehaviorSubject, EMPTY, interval, Observable, Subject} from "rxjs"; | ||
import {Component, EventEmitter, Input, OnDestroy, OnInit, Output} from "@angular/core"; | ||
import {distinctUntilChanged, scan, switchMap, takeUntil, tap, withLatestFrom} from "rxjs/operators"; | ||
import {Store} from "@ngrx/store"; | ||
|
||
import {CORE_ACTIONS} from "_@web/src/app/store/actions"; | ||
import {ElectronService} from "../+core/electron.service"; | ||
import {KeePassClientConf, KeePassRef} from "_@shared/model/keepasshttp"; | ||
import {State} from "_@web/src/app/store/reducers/root"; | ||
|
||
@Component({ | ||
selector: `protonmail-desktop-app-keepass-request`, | ||
templateUrl: "./keepass-request.component.html", | ||
styleUrls: ["./keepass-request.component.scss"], | ||
}) | ||
export class KeePassRequestComponent implements OnInit, OnDestroy { | ||
paused = false; | ||
locked = false; | ||
message?: string; | ||
wait = 10; | ||
progressTick = 0; | ||
passwodRequestTick = 0; | ||
|
||
@Input() | ||
keePassRef$: Observable<KeePassRef | undefined>; | ||
@Input() | ||
keePassClientConf$: Observable<KeePassClientConf>; | ||
@Input() | ||
locked$: Observable<boolean> = new BehaviorSubject(false); | ||
@Output() | ||
passwordHandler = new EventEmitter<string>(); | ||
|
||
unSubscribe$ = new Subject(); | ||
|
||
constructor(private store: Store<State>, | ||
private electronService: ElectronService) {} | ||
|
||
ngOnInit() { | ||
this.keePassRef$ | ||
.pipe( | ||
distinctUntilChanged(), | ||
withLatestFrom(this.keePassClientConf$), | ||
switchMap(([keePassRef, keePassClientConf]) => { | ||
if (!keePassRef) { | ||
return EMPTY; | ||
} | ||
|
||
return interval(1000).pipe( | ||
scan((remaining) => remaining ? remaining - (this.paused ? 0 : 1) : this.wait, this.wait), | ||
distinctUntilChanged(), | ||
switchMap((remaining) => { | ||
this.progressTick = (this.wait - remaining) * (100 / this.wait); | ||
if (remaining) { | ||
return EMPTY; | ||
} | ||
this.wait = this.wait < 30 ? 30 : 60; | ||
this.passwodRequestTick++; | ||
if (this.passwodRequestTick % 5 === 0) { | ||
this.paused = true; | ||
} | ||
return this.electronService.keePassPassword(keePassClientConf, keePassRef, true); | ||
}), | ||
); | ||
}), | ||
takeUntil(this.unSubscribe$), | ||
) | ||
.subscribe( | ||
({password, message}) => { | ||
if (password) { | ||
this.passwordHandler.emit(password); | ||
this.message = "Password received"; | ||
} else { | ||
this.message = message; | ||
} | ||
}, | ||
(err) => { | ||
this.store.dispatch(CORE_ACTIONS.Fail(err)); | ||
}, | ||
); | ||
|
||
this.locked$ | ||
.pipe(takeUntil(this.unSubscribe$)) | ||
.subscribe((locked) => { | ||
this.locked = locked; | ||
this.togglePause(locked); | ||
}); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.unSubscribe$.next(); | ||
this.unSubscribe$.complete(); | ||
} | ||
|
||
togglePause(forcedValue?: boolean) { | ||
this.paused = typeof forcedValue !== "undefined" ? forcedValue : !this.paused; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.