mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 14:16:01 +00:00
electron initialization without remote
This commit is contained in:
@@ -1,7 +1,57 @@
|
||||
export default function getElectron() {
|
||||
class ElectronApi {
|
||||
public port?: number;
|
||||
public authorization?: string;
|
||||
private ipcRenderer = getIpcRenderer();
|
||||
|
||||
constructor(args) {
|
||||
this.port = args.port;
|
||||
this.authorization = args.authorization;
|
||||
}
|
||||
|
||||
send(msg, args) {
|
||||
this.ipcRenderer.send(msg, args);
|
||||
}
|
||||
}
|
||||
|
||||
let apiInstance = null;
|
||||
|
||||
function initializeElectron(args) {
|
||||
// console.log('Initialize electron with args:', args);
|
||||
|
||||
apiInstance = new ElectronApi(args);
|
||||
if (window['dbgate_recreateAxiosInstance']) {
|
||||
// console.log('Recreating axios instance');
|
||||
|
||||
window['dbgate_recreateAxiosInstance']();
|
||||
}
|
||||
}
|
||||
|
||||
window['dbgate_initializeElectron'] = initializeElectron;
|
||||
|
||||
function getIpcRenderer() {
|
||||
if (window['require']) {
|
||||
const electron = window['require']('electron');
|
||||
return electron;
|
||||
return electron?.ipcRenderer;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function shouldWaitForElectronInitialize() {
|
||||
return !!getIpcRenderer() && !apiInstance;
|
||||
}
|
||||
|
||||
export default function getElectron(): ElectronApi {
|
||||
return apiInstance;
|
||||
// try {
|
||||
// // @ts-ignore
|
||||
// return ipcRenderer;
|
||||
// } catch (e) {
|
||||
// return null;
|
||||
// }
|
||||
// if (window['require']) {
|
||||
// const electron = window['require']('electron');
|
||||
// console.log('electron?.ipcRenderer', electron?.ipcRenderer);
|
||||
// return electron?.ipcRenderer;
|
||||
// }
|
||||
// return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user