mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 21:05:59 +00:00
small refactor
This commit is contained in:
@@ -152,8 +152,7 @@ function buildMenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on('update-menu', async (event, arg) => {
|
ipcMain.on('update-menu', async (event, arg) => {
|
||||||
const commands = await mainWindow.webContents.executeJavaScript(`getCurrentTabCommands()`);
|
const commands = await mainWindow.webContents.executeJavaScript(`dbgate_getCurrentTabCommands()`);
|
||||||
console.log('getCurrentTabCommands', commands);
|
|
||||||
mainMenu.getMenuItemById('save').enabled = !!commands.save;
|
mainMenu.getMenuItemById('save').enabled = !!commands.save;
|
||||||
mainMenu.getMenuItemById('saveAs').enabled = !!commands.saveAs;
|
mainMenu.getMenuItemById('saveAs').enabled = !!commands.saveAs;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ export default function TabsPanel() {
|
|||||||
if (electron) {
|
if (electron) {
|
||||||
const { ipcRenderer } = electron;
|
const { ipcRenderer } = electron;
|
||||||
const activeTab = tabs.find(x => x.selected);
|
const activeTab = tabs.find(x => x.selected);
|
||||||
window['activeTabId'] = activeTab ? activeTab.tabid : null;
|
window['dbgate_activeTabId'] = activeTab ? activeTab.tabid : null;
|
||||||
ipcRenderer.send('update-menu');
|
ipcRenderer.send('update-menu');
|
||||||
}
|
}
|
||||||
}, [tabs]);
|
}, [tabs]);
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ import localStorageGarbageCollector from './utility/localStorageGarbageCollector
|
|||||||
// import 'ace-builds/src-noconflict/snippets/mysql';
|
// import 'ace-builds/src-noconflict/snippets/mysql';
|
||||||
|
|
||||||
localStorageGarbageCollector();
|
localStorageGarbageCollector();
|
||||||
window['tabExports'] = {};
|
window['dbgate_tabExports'] = {};
|
||||||
window['getCurrentTabCommands'] = () => {
|
window['dbgate_getCurrentTabCommands'] = () => {
|
||||||
const tabid = window['activeTabId'];
|
const tabid = window['dbgate_activeTabId'];
|
||||||
return _.mapValues(window['tabExports'][tabid] || {}, v => !!v);
|
return _.mapValues(window['dbgate_tabExports'][tabid] || {}, v => !!v);
|
||||||
};
|
};
|
||||||
window['dbgate_tabCommand'] = cmd => {
|
window['dbgate_tabCommand'] = cmd => {
|
||||||
const tabid = window['activeTabId'];
|
const tabid = window['dbgate_activeTabId'];
|
||||||
const commands = window['tabExports'][tabid];
|
const commands = window['dbgate_tabExports'][tabid];
|
||||||
const func = (commands || {})[cmd];
|
const func = (commands || {})[cmd];
|
||||||
if (func) func();
|
if (func) func();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -77,14 +77,14 @@ export default function SaveTabModal({
|
|||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
if (electron) {
|
if (electron) {
|
||||||
const { ipcRenderer } = electron;
|
const { ipcRenderer } = electron;
|
||||||
window['tabExports'][tabid] = {
|
window['dbgate_tabExports'][tabid] = {
|
||||||
save: handleSaveRef.current,
|
save: handleSaveRef.current,
|
||||||
saveAs: saveFileModalState.open,
|
saveAs: saveFileModalState.open,
|
||||||
};
|
};
|
||||||
ipcRenderer.send('update-menu');
|
ipcRenderer.send('update-menu');
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
delete window['tabExports'][tabid];
|
delete window['dbgate_tabExports'][tabid];
|
||||||
ipcRenderer.send('update-menu');
|
ipcRenderer.send('update-menu');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user