replaced executeJavaScript with IPC event

This commit is contained in:
Jan Prochazka
2021-12-25 11:29:46 +01:00
parent 0e95082be6
commit ab4aef6c7e
5 changed files with 11 additions and 73 deletions

View File

@@ -38,7 +38,7 @@ function commandItem(id) {
accelerator: command ? command.keyText : undefined,
enabled: command ? command.enabled : false,
click() {
mainWindow.webContents.executeJavaScript(`dbgate_runCommand('${id}')`);
mainWindow.webContents.send('run-command', id);
},
};
}
@@ -179,11 +179,9 @@ function createWindow() {
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
// enableRemoteModule: true,
},
});
mainWindow.webContents.openDevTools();
// require('@electron/remote/main').enable(mainWindow.webContents);
if (store.get('winIsMaximized')) {
mainWindow.maximize();
}
@@ -199,18 +197,6 @@ function createWindow() {
protocol: 'file:',
slashes: true,
});
// mainWindow.webContents.on('did-finish-load', function () {
// mainWindow.webContents.executeJavaScript(
// `runInit=()=>{
// try{
// dbgate_initializeElectron(${JSON.stringify(initArgs)});
// }catch(e){
// setTimeout(runInit,100)
// }
// };
// runInit()`
// );
// });
mainWindow.on('close', () => {
store.set('winBounds', mainWindow.getBounds());
store.set('winIsMaximized', mainWindow.isMaximized());
@@ -232,34 +218,6 @@ function createWindow() {
loadMainWindow();
// if (process.env.ELECTRON_START_URL) {
// loadMainWindow({});
// } else {
// const apiProcess = fork(path.join(__dirname, '../packages/api/dist/bundle.js'), [
// '--dynport',
// '--is-electron-bundle',
// '--native-modules',
// path.join(__dirname, 'nativeModules'),
// // '../../../src/nativeModules'
// ]);
// apiProcess.on('message', msg => {
// if (msg.msgtype == 'listening') {
// const { port, authorization } = msg;
// loadMainWindow({
// port,
// authorization,
// });
// }
// });
// }
// and load the index.html of the app.
// mainWindow.loadURL('http://localhost:3000');
// Open the DevTools.
// mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows

View File

@@ -121,19 +121,7 @@ function start() {
}
}
if (processArgs.dynport) {
childProcessChecker();
authorization = crypto.randomBytes(32).toString('hex');
getPort().then(port => {
checkLocalhostOrigin = `localhost:${port}`;
server.listen(port, () => {
console.log(`DbGate API listening on port ${port}`);
process.send({ msgtype: 'listening', port, authorization });
});
});
} else if (platformInfo.isNpmDist) {
if (platformInfo.isNpmDist) {
app.use(express.static(path.join(__dirname, '../../dbgate-web/public')));
getPort({ port: 5000 }).then(port => {
server.listen(port, () => {
@@ -141,7 +129,7 @@ function start() {
});
});
} else {
server.listen(3000);
server.listen(process.env.PORT || 3000);
}
}

View File

@@ -18,8 +18,6 @@ export default function runCommand(id) {
}
}
window['dbgate_runCommand'] = runCommand;
export function runGroupCommand(group) {
const commandsValue = getCommands();
const values = Object.values(commandsValue) as GlobalCommand[];
@@ -32,3 +30,4 @@ export function findCommand(id) {
const command = commandsValue[id];
return command;
}

View File

@@ -25,6 +25,7 @@ import InputTextModal from '../modals/InputTextModal.svelte';
import { removeLocalStorage } from '../utility/storageCache';
import { showSnackbarSuccess } from '../utility/snackbar';
import { apiCall } from '../utility/api';
import runCommand from './runCommand';
function themeCommand(theme: ThemeDefinition) {
return {
@@ -533,3 +534,8 @@ export function registerFileCommands({
});
}
}
const electron = getElectron();
if (electron) {
electron.addEventListener('run-command', (e, commandId) => runCommand(commandId));
}

View File

@@ -45,15 +45,6 @@ class ElectronApi {
}
}
// function initializeElectron(args) {
// apiInstance = new ElectronApi(args);
// if (window['dbgate_recreateSocket']) {
// window['dbgate_recreateSocket']();
// }
// }
// window['dbgate_initializeElectron'] = initializeElectron;
function getIpcRenderer() {
if (window['require']) {
const electron = window['require']('electron');
@@ -62,10 +53,6 @@ function getIpcRenderer() {
return null;
}
// export function shouldWaitForElectronInitialize() {
// return !!getIpcRenderer() && !apiInstance;
// }
export function isElectronAvailable() {
return !!getIpcRenderer();
}