Skip to content

Commit

Permalink
fix: root directory run error
Browse files Browse the repository at this point in the history
  • Loading branch information
scarqin committed Jun 30, 2022
1 parent 53656b7 commit 90466fe
Showing 1 changed file with 84 additions and 84 deletions.
168 changes: 84 additions & 84 deletions src/app/electron-browser/IndexedDB/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
import { ipcRenderer, app } from 'electron';
import { isNotEmpty } from 'eo/shared/common/common';
import * as fs from 'fs';
import * as path from 'path';
import {
StorageRes,
StorageResStatus,
StorageHandleArgs,
StorageProcessType,
} from '../../../../workbench/browser/src/app/shared/services/storage/index.model';
import { IndexedDBStorage } from '../../../../workbench/browser/src/app/shared/services/storage/IndexedDB/lib/index';
// import { ipcRenderer, app } from 'electron';
// import { isNotEmpty } from 'eo/shared/common/common';
// import * as fs from 'fs';
// import * as path from 'path';
// import {
// StorageRes,
// StorageResStatus,
// StorageHandleArgs,
// StorageProcessType,
// } from '../../../../workbench/browser/src/app/shared/services/storage/index.model';
// import { IndexedDBStorage } from '../../../../workbench/browser/src/app/shared/services/storage/IndexedDB/lib/index';

class StorageService {
private ipcRenderer: typeof ipcRenderer;
private app: typeof app;
private fs: typeof fs;
private path: typeof path;
constructor() {
this.ipcRenderer = window.require('electron').ipcRenderer;
this.app = window.require('electron').app;
this.fs = window.require('fs');
this.path = window.require('path');
this.storageListen();
}
// class StorageService {
// private ipcRenderer: typeof ipcRenderer;
// private app: typeof app;
// private fs: typeof fs;
// private path: typeof path;
// constructor() {
// this.ipcRenderer = window.require('electron').ipcRenderer;
// this.app = window.require('electron').app;
// this.fs = window.require('fs');
// this.path = window.require('path');
// this.storageListen();
// }

/**
* 存储监听处理
* @param args
*/
private storageListenHandle(args: StorageHandleArgs): void {
const action: string = args.action || undefined;
const handleResult: StorageRes = {
status: StorageResStatus.invalid,
data: undefined,
callback: args.callback || null,
};
if (IndexedDBStorage && IndexedDBStorage[action] && typeof IndexedDBStorage[action] === 'function') {
IndexedDBStorage[action](...args.params).subscribe(
(result: any) => {
handleResult.data = result;
if (isNotEmpty(result)) {
handleResult.status = StorageResStatus.success;
} else {
handleResult.status = StorageResStatus.empty;
}
this.storageListenHandleNotify(args.type, handleResult);
},
(error: any) => {
handleResult.status = StorageResStatus.error;
this.storageListenHandleNotify(args.type, handleResult);
}
);
} else {
this.storageListenHandleNotify(args.type, handleResult);
}
}
// /**
// * 存储监听处理
// * @param args
// */
// private storageListenHandle(args: StorageHandleArgs): void {
// const action: string = args.action || undefined;
// const handleResult: StorageRes = {
// status: StorageResStatus.invalid,
// data: undefined,
// callback: args.callback || null,
// };
// if (IndexedDBStorage && IndexedDBStorage[action] && typeof IndexedDBStorage[action] === 'function') {
// IndexedDBStorage[action](...args.params).subscribe(
// (result: any) => {
// handleResult.data = result;
// if (isNotEmpty(result)) {
// handleResult.status = StorageResStatus.success;
// } else {
// handleResult.status = StorageResStatus.empty;
// }
// this.storageListenHandleNotify(args.type, handleResult);
// },
// (error: any) => {
// handleResult.status = StorageResStatus.error;
// this.storageListenHandleNotify(args.type, handleResult);
// }
// );
// } else {
// this.storageListenHandleNotify(args.type, handleResult);
// }
// }

/**
* 数据存储监听通知返回
* @param type
* @param result
*/
private storageListenHandleNotify(type: string, result: StorageRes): void {
try {
if (StorageProcessType.default === type) {
this.ipcRenderer.send('eo-storage', { type: 'result', result: result });
} else if (StorageProcessType.sync === type) {
const storageTemp = this.path.join(this.app.getPath('home'), '.eo', 'tmp.storage');
this.fs.writeFileSync(storageTemp, JSON.stringify(result));
} else if (StorageProcessType.remote === type) {
window.require('@electron/remote').getGlobal('shareObject').storageResult = result;
}
} catch (e) {
console.log(e);
}
}
// /**
// * 数据存储监听通知返回
// * @param type
// * @param result
// */
// private storageListenHandleNotify(type: string, result: StorageRes): void {
// try {
// if (StorageProcessType.default === type) {
// this.ipcRenderer.send('eo-storage', { type: 'result', result: result });
// } else if (StorageProcessType.sync === type) {
// const storageTemp = this.path.join(this.app.getPath('home'), '.eo', 'tmp.storage');
// this.fs.writeFileSync(storageTemp, JSON.stringify(result));
// } else if (StorageProcessType.remote === type) {
// window.require('@electron/remote').getGlobal('shareObject').storageResult = result;
// }
// } catch (e) {
// console.log(e);
// }
// }

/**
* 开启数据存储监听
* @returns
*/
private storageListen(): void {
this.ipcRenderer.on('eo-storage', (event, args: StorageHandleArgs) => this.storageListenHandle(args));
}
// /**
// * 开启数据存储监听
// * @returns
// */
// private storageListen(): void {
// this.ipcRenderer.on('eo-storage', (event, args: StorageHandleArgs) => this.storageListenHandle(args));
// }

isElectron(): boolean {
return !!(window && window.process && window.process.type);
}
}
// isElectron(): boolean {
// return !!(window && window.process && window.process.type);
// }
// }

0 comments on commit 90466fe

Please sign in to comment.