2018-04-24 22:00:20 +02:00
|
|
|
import {
|
|
|
|
clipboard,
|
2020-07-23 19:32:20 +02:00
|
|
|
ipcRenderer,
|
2018-04-24 22:00:20 +02:00
|
|
|
shell,
|
|
|
|
} from 'electron';
|
|
|
|
|
|
|
|
import {
|
|
|
|
isDev,
|
|
|
|
isMacAppStore,
|
|
|
|
} from '../utils';
|
|
|
|
|
|
|
|
import { DeviceType } from '../../enums/deviceType';
|
|
|
|
|
|
|
|
import { I18nService } from '../../abstractions/i18n.service';
|
2018-10-03 15:41:41 +02:00
|
|
|
import { MessagingService } from '../../abstractions/messaging.service';
|
2018-04-24 22:00:20 +02:00
|
|
|
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
|
2020-07-23 19:32:20 +02:00
|
|
|
import { StorageService } from '../../abstractions/storage.service';
|
2018-04-24 22:00:20 +02:00
|
|
|
|
2020-07-23 19:32:20 +02:00
|
|
|
import { ElectronConstants } from '../electronConstants';
|
2018-04-24 22:00:20 +02:00
|
|
|
|
|
|
|
export class ElectronPlatformUtilsService implements PlatformUtilsService {
|
|
|
|
identityClientId: string;
|
|
|
|
|
|
|
|
private deviceCache: DeviceType = null;
|
|
|
|
|
2021-04-21 20:49:18 +02:00
|
|
|
constructor(private i18nService: I18nService, private messagingService: MessagingService,
|
2020-07-23 19:32:20 +02:00
|
|
|
private isDesktopApp: boolean, private storageService: StorageService) {
|
2018-04-24 22:00:20 +02:00
|
|
|
this.identityClientId = isDesktopApp ? 'desktop' : 'connector';
|
|
|
|
}
|
|
|
|
|
|
|
|
getDevice(): DeviceType {
|
|
|
|
if (!this.deviceCache) {
|
|
|
|
switch (process.platform) {
|
|
|
|
case 'win32':
|
2018-07-09 15:04:47 +02:00
|
|
|
this.deviceCache = DeviceType.WindowsDesktop;
|
2018-04-24 22:00:20 +02:00
|
|
|
break;
|
|
|
|
case 'darwin':
|
2018-07-09 15:04:47 +02:00
|
|
|
this.deviceCache = DeviceType.MacOsDesktop;
|
2018-04-24 22:00:20 +02:00
|
|
|
break;
|
|
|
|
case 'linux':
|
|
|
|
default:
|
2018-07-09 15:04:47 +02:00
|
|
|
this.deviceCache = DeviceType.LinuxDesktop;
|
2018-04-24 22:00:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.deviceCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
getDeviceString(): string {
|
2018-07-09 15:30:15 +02:00
|
|
|
const device = DeviceType[this.getDevice()].toLowerCase();
|
|
|
|
return device.replace('desktop', '');
|
2018-04-24 22:00:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
isFirefox(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
isChrome(): boolean {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
isEdge(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
isOpera(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
isVivaldi(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
isSafari(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-08 05:36:39 +02:00
|
|
|
isIE(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-24 22:00:20 +02:00
|
|
|
isMacAppStore(): boolean {
|
|
|
|
return isMacAppStore();
|
|
|
|
}
|
|
|
|
|
2019-08-20 19:47:15 +02:00
|
|
|
isViewOpen(): Promise<boolean> {
|
|
|
|
return Promise.resolve(false);
|
2018-04-24 22:00:20 +02:00
|
|
|
}
|
|
|
|
|
2018-06-09 20:50:18 +02:00
|
|
|
lockTimeout(): number {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-04-24 22:00:20 +02:00
|
|
|
launchUri(uri: string, options?: any): void {
|
|
|
|
shell.openExternal(uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
saveFile(win: Window, blobData: any, blobOptions: any, fileName: string): void {
|
2021-04-07 19:42:06 +02:00
|
|
|
ipcRenderer.invoke('saveFile', {
|
|
|
|
fileName: fileName,
|
|
|
|
buffer: Buffer.from(blobData),
|
2018-08-18 05:57:42 +02:00
|
|
|
});
|
2018-04-24 22:00:20 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 19:42:06 +02:00
|
|
|
getApplicationVersion(): Promise<string> {
|
|
|
|
return ipcRenderer.invoke('appVersion');
|
2018-04-24 22:00:20 +02:00
|
|
|
}
|
|
|
|
|
2021-04-05 22:38:45 +02:00
|
|
|
// Temporarily restricted to only Windows until https://github.com/electron/electron/pull/28349
|
|
|
|
// has been merged and an updated electron build is available.
|
2021-03-15 16:16:51 +01:00
|
|
|
supportsWebAuthn(win: Window): boolean {
|
2021-04-05 22:38:45 +02:00
|
|
|
return process.platform === 'win32';
|
2018-04-24 22:00:20 +02:00
|
|
|
}
|
|
|
|
|
2018-05-16 21:30:28 +02:00
|
|
|
supportsDuo(): boolean {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-03 05:09:19 +02:00
|
|
|
showToast(type: 'error' | 'success' | 'warning' | 'info', title: string, text: string | string[],
|
|
|
|
options?: any): void {
|
2018-10-03 15:41:41 +02:00
|
|
|
this.messagingService.send('showToast', {
|
|
|
|
text: text,
|
|
|
|
title: title,
|
|
|
|
type: type,
|
|
|
|
options: options,
|
|
|
|
});
|
2018-05-31 20:40:01 +02:00
|
|
|
}
|
|
|
|
|
2020-01-27 15:46:42 +01:00
|
|
|
async showDialog(text: string, title?: string, confirmText?: string, cancelText?: string, type?: string):
|
2018-04-24 22:00:20 +02:00
|
|
|
Promise<boolean> {
|
|
|
|
const buttons = [confirmText == null ? this.i18nService.t('ok') : confirmText];
|
|
|
|
if (cancelText != null) {
|
|
|
|
buttons.push(cancelText);
|
|
|
|
}
|
|
|
|
|
2021-04-07 19:42:06 +02:00
|
|
|
const result = await ipcRenderer.invoke('showMessageBox', {
|
2018-04-24 22:00:20 +02:00
|
|
|
type: type,
|
|
|
|
title: title,
|
|
|
|
message: title,
|
|
|
|
detail: text,
|
|
|
|
buttons: buttons,
|
|
|
|
cancelId: buttons.length === 2 ? 1 : null,
|
|
|
|
defaultId: 0,
|
|
|
|
noLink: true,
|
|
|
|
});
|
|
|
|
|
2020-01-27 15:46:42 +01:00
|
|
|
return Promise.resolve(result.response === 0);
|
2018-04-24 22:00:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
isDev(): boolean {
|
|
|
|
return isDev();
|
|
|
|
}
|
|
|
|
|
2018-06-30 19:51:09 +02:00
|
|
|
isSelfHost(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-24 22:00:20 +02:00
|
|
|
copyToClipboard(text: string, options?: any): void {
|
|
|
|
const type = options ? options.type : null;
|
2019-05-30 15:37:02 +02:00
|
|
|
const clearing = options ? !!options.clearing : false;
|
2019-02-27 17:26:35 +01:00
|
|
|
const clearMs: number = options && options.clearMs ? options.clearMs : null;
|
2018-04-24 22:00:20 +02:00
|
|
|
clipboard.writeText(text, type);
|
2019-05-30 15:37:02 +02:00
|
|
|
if (!clearing) {
|
|
|
|
this.messagingService.send('copiedToClipboard', {
|
|
|
|
clipboardValue: text,
|
|
|
|
clearMs: clearMs,
|
|
|
|
type: type,
|
|
|
|
clearing: clearing,
|
|
|
|
});
|
|
|
|
}
|
2018-04-24 22:00:20 +02:00
|
|
|
}
|
2019-02-27 04:40:53 +01:00
|
|
|
|
|
|
|
readFromClipboard(options?: any): Promise<string> {
|
|
|
|
const type = options ? options.type : null;
|
|
|
|
return Promise.resolve(clipboard.readText(type));
|
|
|
|
}
|
2020-07-23 19:32:20 +02:00
|
|
|
|
|
|
|
supportsBiometric(): Promise<boolean> {
|
|
|
|
return this.storageService.get(ElectronConstants.enableBiometric);
|
|
|
|
}
|
|
|
|
|
|
|
|
authenticateBiometric(): Promise<boolean> {
|
2021-02-04 16:49:23 +01:00
|
|
|
return new Promise(resolve => {
|
2020-07-23 19:32:20 +02:00
|
|
|
const val = ipcRenderer.sendSync('biometric', {
|
|
|
|
action: 'authenticate',
|
|
|
|
});
|
|
|
|
resolve(val);
|
|
|
|
});
|
|
|
|
}
|
2020-11-18 22:10:57 +01:00
|
|
|
|
2020-12-15 23:22:24 +01:00
|
|
|
getDefaultSystemTheme() {
|
2021-04-07 19:42:06 +02:00
|
|
|
return ipcRenderer.invoke('systemTheme');
|
2020-12-15 23:22:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onDefaultSystemThemeChange(callback: ((theme: 'light' | 'dark') => unknown)) {
|
2021-04-07 19:42:06 +02:00
|
|
|
ipcRenderer.on('systemThemeUpdated', (event, theme: 'light' | 'dark') => callback(theme));
|
2020-12-15 23:22:24 +01:00
|
|
|
}
|
|
|
|
|
2020-11-18 22:10:57 +01:00
|
|
|
supportsSecureStorage(): boolean {
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-24 22:00:20 +02:00
|
|
|
}
|