mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 23:03:32 +00:00
sweet alert dialog implementation
This commit is contained in:
@@ -2,11 +2,12 @@ import * as tldjs from 'tldjs';
|
||||
|
||||
import { BrowserApi } from '../browser/browserApi';
|
||||
|
||||
import { DeviceType } from 'jslib/enums';
|
||||
import { DeviceType } from 'jslib/enums/deviceType';
|
||||
|
||||
import { PlatformUtilsService } from 'jslib/abstractions';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||
|
||||
import { UtilsService } from 'jslib/services';
|
||||
import { UtilsService } from 'jslib/services/utils.service';
|
||||
|
||||
const AnalyticsIds = {
|
||||
[DeviceType.Chrome]: 'UA-81915606-6',
|
||||
@@ -17,6 +18,8 @@ const AnalyticsIds = {
|
||||
[DeviceType.Safari]: 'UA-81915606-16',
|
||||
};
|
||||
|
||||
const DialogPromiseExpiration = 3600000; // 1 hour
|
||||
|
||||
export default class BrowserPlatformUtilsService implements PlatformUtilsService {
|
||||
static getDomain(uriString: string): string {
|
||||
if (uriString == null) {
|
||||
@@ -57,9 +60,12 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
||||
|
||||
identityClientId: string = 'browser';
|
||||
|
||||
private showDialogResolves = new Map<number, { resolve: (value: boolean) => void, date: Date }>();
|
||||
private deviceCache: DeviceType = null;
|
||||
private analyticsIdCache: string = null;
|
||||
|
||||
constructor(private messagingService: MessagingService) { }
|
||||
|
||||
getDevice(): DeviceType {
|
||||
if (this.deviceCache) {
|
||||
return this.deviceCache;
|
||||
@@ -169,8 +175,18 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
||||
}
|
||||
|
||||
showDialog(text: string, title?: string, confirmText?: string, cancelText?: string, type?: string) {
|
||||
// TODO
|
||||
return Promise.resolve(true);
|
||||
const dialogId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
|
||||
this.messagingService.send('showDialog', {
|
||||
text: text,
|
||||
title: title,
|
||||
confirmText: confirmText,
|
||||
cancelText: cancelText,
|
||||
type: type,
|
||||
dialogId: dialogId,
|
||||
});
|
||||
return new Promise<boolean>((resolve) => {
|
||||
this.showDialogResolves.set(dialogId, { resolve: resolve, date: new Date() });
|
||||
});
|
||||
}
|
||||
|
||||
isDev(): boolean {
|
||||
@@ -183,6 +199,26 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
||||
UtilsService.copyToClipboard(text, doc);
|
||||
}
|
||||
|
||||
resolveDialogPromise(dialogId: number, confirmed: boolean) {
|
||||
if (this.showDialogResolves.has(dialogId)) {
|
||||
const resolveObj = this.showDialogResolves.get(dialogId);
|
||||
resolveObj.resolve(confirmed);
|
||||
this.showDialogResolves.delete(dialogId);
|
||||
}
|
||||
|
||||
// Clean up old promises
|
||||
const deleteIds: number[] = [];
|
||||
this.showDialogResolves.forEach((val, key) => {
|
||||
const age = new Date().getTime() - val.date.getTime();
|
||||
if (age > DialogPromiseExpiration) {
|
||||
deleteIds.push(key);
|
||||
}
|
||||
});
|
||||
deleteIds.forEach((id) => {
|
||||
this.showDialogResolves.delete(id);
|
||||
});
|
||||
}
|
||||
|
||||
private sidebarViewName(): string {
|
||||
if ((window as any).chrome.sidebarAction && this.isFirefox()) {
|
||||
return 'sidebar';
|
||||
|
||||
Reference in New Issue
Block a user