Merge pull request #690 from ente-io/add-electron-types
Add electron APIs types
This commit is contained in:
commit
7fb1e6fbfa
|
@ -5,7 +5,8 @@
|
|||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"albums": "next dev -p 3002",
|
||||
"prebuild": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
|
||||
"lint":"eslint \"src/**/*.{js,jsx,ts,tsx}\"",
|
||||
"prebuild": "yarn lint",
|
||||
"build": "next build",
|
||||
"build-analyze": "ANALYZE=true next build",
|
||||
"postbuild": "next export",
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { ElectronAPIs } from 'types/electron';
|
||||
import { runningInBrowser } from 'utils/common';
|
||||
|
||||
class ElectronCacheService {
|
||||
private ElectronAPIs: any;
|
||||
private ElectronAPIs: ElectronAPIs;
|
||||
private allElectronAPIsExist: boolean = false;
|
||||
|
||||
constructor() {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import isElectron from 'is-electron';
|
||||
import { ElectronAPIs } from 'types/electron';
|
||||
import { runningInBrowser } from 'utils/common';
|
||||
|
||||
class ElectronService {
|
||||
private ElectronAPIs: any;
|
||||
private ElectronAPIs: ElectronAPIs;
|
||||
private isBundledApp: boolean = false;
|
||||
|
||||
constructor() {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { ElectronAPIs } from 'types/electron';
|
||||
import { runningInBrowser } from 'utils/common';
|
||||
import { logError } from 'utils/sentry';
|
||||
|
||||
class SafeStorageService {
|
||||
private ElectronAPIs: any;
|
||||
private ElectronAPIs: ElectronAPIs;
|
||||
private allElectronAPIsExist: boolean = false;
|
||||
constructor() {
|
||||
this.ElectronAPIs = runningInBrowser() && window['ElectronAPIs'];
|
||||
|
@ -32,7 +33,7 @@ class SafeStorageService {
|
|||
async clearElectronStore() {
|
||||
try {
|
||||
if (this.allElectronAPIsExist) {
|
||||
return await this.ElectronAPIs.clearElectronStore();
|
||||
return this.ElectronAPIs.clearElectronStore();
|
||||
}
|
||||
} catch (e) {
|
||||
logError(e, 'clearElectronStore failed');
|
||||
|
|
|
@ -50,12 +50,13 @@ import {
|
|||
import { User } from 'types/user';
|
||||
import { FILE_TYPE, TYPE_JPEG, TYPE_JPG } from 'constants/file';
|
||||
import { ExportType, ExportNotification, RecordType } from 'constants/export';
|
||||
import { ElectronAPIs } from 'types/electron';
|
||||
|
||||
const LATEST_EXPORT_VERSION = 1;
|
||||
const EXPORT_RECORD_FILE_NAME = 'export_status.json';
|
||||
|
||||
class ExportService {
|
||||
ElectronAPIs: any;
|
||||
ElectronAPIs: ElectronAPIs;
|
||||
|
||||
private exportInProgress: Promise<{ paused: boolean }> = null;
|
||||
private exportRecordUpdater = new QueueProcessor<void>(1);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { UPLOAD_TYPE } from 'components/Upload/Uploader';
|
||||
import { Collection } from 'types/collection';
|
||||
import { ElectronAPIs } from 'types/electron';
|
||||
import { ElectronFile, FileWithCollection } from 'types/upload';
|
||||
import { runningInBrowser } from 'utils/common';
|
||||
import { logError } from 'utils/sentry';
|
||||
|
@ -15,7 +16,7 @@ interface selectZipResult {
|
|||
zipPaths: string[];
|
||||
}
|
||||
class ImportService {
|
||||
ElectronAPIs: any;
|
||||
ElectronAPIs: ElectronAPIs;
|
||||
private allElectronAPIsExist: boolean = false;
|
||||
|
||||
constructor() {
|
||||
|
|
42
src/types/electron/index.ts
Normal file
42
src/types/electron/index.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { ElectronFile } from 'types/upload';
|
||||
|
||||
export interface ElectronAPIs {
|
||||
exists: (path: string) => boolean;
|
||||
checkExistsAndCreateCollectionDir: (dirPath: string) => Promise<void>;
|
||||
checkExistsAndRename: (
|
||||
oldDirPath: string,
|
||||
newDirPath: string
|
||||
) => Promise<void>;
|
||||
saveStreamToDisk: (path: string, fileStream: ReadableStream<any>) => void;
|
||||
saveFileToDisk: (path: string, file: any) => Promise<void>;
|
||||
selectRootDirectory: () => Promise<string>;
|
||||
sendNotification: (content: string) => void;
|
||||
showOnTray: (content?: any) => void;
|
||||
registerResumeExportListener: (resumeExport: () => void) => void;
|
||||
registerStopExportListener: (abortExport: () => void) => void;
|
||||
registerPauseExportListener: (pauseExport: () => void) => void;
|
||||
registerRetryFailedExportListener: (retryFailedExport: () => void) => void;
|
||||
getExportRecord: (filePath: string) => Promise<string>;
|
||||
setExportRecord: (filePath: string, data: string) => Promise<void>;
|
||||
showUploadFilesDialog: () => Promise<ElectronFile[]>;
|
||||
showUploadDirsDialog: () => Promise<ElectronFile[]>;
|
||||
getPendingUploads: () => Promise<{
|
||||
files: ElectronFile[];
|
||||
collectionName: string;
|
||||
type: string;
|
||||
}>;
|
||||
setToUploadFiles: (type: string, filePaths: string[]) => void;
|
||||
showUploadZipDialog: () => Promise<{
|
||||
zipPaths: string[];
|
||||
files: ElectronFile[];
|
||||
}>;
|
||||
getElectronFilesFromGoogleZip: (
|
||||
filePath: string
|
||||
) => Promise<ElectronFile[]>;
|
||||
setToUploadCollection: (collectionName: string) => void;
|
||||
clearElectronStore: () => void;
|
||||
setEncryptionKey: (encryptionKey: string) => Promise<void>;
|
||||
getEncryptionKey: () => Promise<string>;
|
||||
openDiskCache: (cacheName: string) => Promise<Cache>;
|
||||
deleteDiskCache: (cacheName: string) => Promise<boolean>;
|
||||
}
|
Loading…
Reference in a new issue