mirror of
https://github.com/bitwarden/browser
synced 2025-12-29 06:33:40 +00:00
pack main and renderer
This commit is contained in:
11
src/services/desktopMessaging.service.ts
Normal file
11
src/services/desktopMessaging.service.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import {
|
||||
MessagingService,
|
||||
PlatformUtilsService,
|
||||
} from 'jslib/abstractions';
|
||||
|
||||
export class DesktopMessagingService implements MessagingService {
|
||||
send(subscriber: string, arg: any = {}) {
|
||||
const message = Object.assign({}, { command: subscriber }, arg);
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
81
src/services/desktopPlatformUtils.service.ts
Normal file
81
src/services/desktopPlatformUtils.service.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { DeviceType } from 'jslib/enums';
|
||||
|
||||
import { PlatformUtilsService } from 'jslib/abstractions';
|
||||
|
||||
const AnalyticsIds = {
|
||||
[DeviceType.Windows]: 'UA-81915606-17',
|
||||
[DeviceType.Linux]: 'UA-81915606-19',
|
||||
[DeviceType.MacOs]: 'UA-81915606-18',
|
||||
};
|
||||
|
||||
export class DesktopPlatformUtilsService implements PlatformUtilsService {
|
||||
private deviceCache: DeviceType = null;
|
||||
private analyticsIdCache: string = null;
|
||||
|
||||
getDevice(): DeviceType {
|
||||
if (!this.deviceCache) {
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
this.deviceCache = DeviceType.Windows;
|
||||
break;
|
||||
case 'darwin':
|
||||
this.deviceCache = DeviceType.MacOs;
|
||||
break;
|
||||
case 'linux':
|
||||
this.deviceCache = DeviceType.Linux;
|
||||
break;
|
||||
default:
|
||||
this.deviceCache = DeviceType.Linux;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return this.deviceCache;
|
||||
}
|
||||
|
||||
getDeviceString(): string {
|
||||
return DeviceType[this.getDevice()].toLowerCase();
|
||||
}
|
||||
|
||||
isFirefox(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
isChrome(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
isEdge(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
isOpera(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
isVivaldi(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
isSafari(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
analyticsId(): string {
|
||||
if (this.analyticsIdCache) {
|
||||
return this.analyticsIdCache;
|
||||
}
|
||||
|
||||
// FIX?
|
||||
// this.analyticsIdCache = AnalyticsIds[this.getDevice() as DeviceType];
|
||||
return this.analyticsIdCache;
|
||||
}
|
||||
|
||||
getDomain(uriString: string): string {
|
||||
return uriString;
|
||||
}
|
||||
|
||||
isViewOpen(): boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
18
src/services/desktopSecureStorage.service.ts
Normal file
18
src/services/desktopSecureStorage.service.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { getPassword, setPassword, deletePassword } from 'keytar';
|
||||
|
||||
import { StorageService } from 'jslib/abstractions';
|
||||
|
||||
export class DesktopSecureStorageService implements StorageService {
|
||||
async get<T>(key: string): Promise<T> {
|
||||
const val: string = await getPassword('bitwarden', key);
|
||||
return val ? JSON.parse(val) as T : null
|
||||
}
|
||||
|
||||
async save(key: string, obj: any): Promise<any> {
|
||||
await setPassword('bitwarden', key, JSON.stringify(obj));
|
||||
}
|
||||
|
||||
async remove(key: string): Promise<any> {
|
||||
await deletePassword('bitwarden', key);
|
||||
}
|
||||
}
|
||||
21
src/services/desktopStorage.service.ts
Normal file
21
src/services/desktopStorage.service.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { StorageService } from 'jslib/abstractions';
|
||||
|
||||
const Store = require('electron-store');
|
||||
const store = new Store();
|
||||
|
||||
export class DesktopStorageService implements StorageService {
|
||||
get<T>(key: string): Promise<T> {
|
||||
const val = store.get(key) as T;
|
||||
return Promise.resolve(val ? val : null);
|
||||
}
|
||||
|
||||
save(key: string, obj: any): Promise<any> {
|
||||
store.set(key, obj);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
remove(key: string): Promise<any> {
|
||||
store.delete(key);
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user