mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 00:06:01 +00:00
app exit - mac
This commit is contained in:
@@ -20,6 +20,7 @@ const { settings } = require('cluster');
|
|||||||
|
|
||||||
const configRootPath = path.join(app.getPath('userData'), 'config-root.json');
|
const configRootPath = path.join(app.getPath('userData'), 'config-root.json');
|
||||||
let initialConfig = {};
|
let initialConfig = {};
|
||||||
|
let apiLoaded = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
initialConfig = JSON.parse(fs.readFileSync(configRootPath, { encoding: 'utf-8' }));
|
initialConfig = JSON.parse(fs.readFileSync(configRootPath, { encoding: 'utf-8' }));
|
||||||
@@ -41,6 +42,7 @@ try {
|
|||||||
// be closed automatically when the JavaScript object is garbage collected.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
let mainMenu;
|
let mainMenu;
|
||||||
|
let runCommandOnLoad = null;
|
||||||
|
|
||||||
log.transports.file.level = 'debug';
|
log.transports.file.level = 'debug';
|
||||||
autoUpdater.logger = log;
|
autoUpdater.logger = log;
|
||||||
@@ -59,15 +61,24 @@ function formatKeyText(keyText) {
|
|||||||
return keyText.replace('CtrlOrCommand+', 'Ctrl+');
|
return keyText.replace('CtrlOrCommand+', 'Ctrl+');
|
||||||
}
|
}
|
||||||
|
|
||||||
function commandItem(id) {
|
function commandItem(item) {
|
||||||
|
const id = item.command;
|
||||||
const command = commands[id];
|
const command = commands[id];
|
||||||
|
if (item.skipInApp) {
|
||||||
|
return { skip: true };
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
label: command ? command.menuName || command.toolbarName || command.name : id,
|
label: command ? command.menuName || command.toolbarName || command.name : id,
|
||||||
accelerator: formatKeyText(command ? command.keyText : undefined),
|
accelerator: formatKeyText(command ? command.keyText : undefined),
|
||||||
enabled: command ? command.enabled : false,
|
enabled: command ? command.enabled : false,
|
||||||
click() {
|
click() {
|
||||||
|
if (mainWindow) {
|
||||||
mainWindow.webContents.send('run-command', id);
|
mainWindow.webContents.send('run-command', id);
|
||||||
|
} else {
|
||||||
|
runCommandOnLoad = id;
|
||||||
|
createWindow();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -79,11 +90,17 @@ function buildMenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (item.command) {
|
if (item.command) {
|
||||||
return commandItem(item.command);
|
return commandItem(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return Menu.buildFromTemplate(template);
|
const templateFiltered = _cloneDeepWith(template, item => {
|
||||||
|
if (Array.isArray(item) && item.find(x => x.skip)) {
|
||||||
|
return item.filter(x => x && !x.skip);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return Menu.buildFromTemplate(templateFiltered);
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on('update-commands', async (event, arg) => {
|
ipcMain.on('update-commands', async (event, arg) => {
|
||||||
@@ -105,8 +122,12 @@ ipcMain.on('update-commands', async (event, arg) => {
|
|||||||
menu.enabled = command.enabled;
|
menu.enabled = command.enabled;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ipcMain.on('close-window', async (event, arg) => {
|
ipcMain.on('quit-app', async (event, arg) => {
|
||||||
|
if (os.platform() == 'darwin') {
|
||||||
|
app.quit();
|
||||||
|
} else {
|
||||||
mainWindow.close();
|
mainWindow.close();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
ipcMain.on('set-title', async (event, arg) => {
|
ipcMain.on('set-title', async (event, arg) => {
|
||||||
mainWindow.setTitle(arg);
|
mainWindow.setTitle(arg);
|
||||||
@@ -250,8 +271,13 @@ function createWindow() {
|
|||||||
mainWindow.setIcon(path.resolve(__dirname, '../icon.png'));
|
mainWindow.setIcon(path.resolve(__dirname, '../icon.png'));
|
||||||
}
|
}
|
||||||
// mainWindow.webContents.toggleDevTools();
|
// mainWindow.webContents.toggleDevTools();
|
||||||
|
if (runCommandOnLoad) {
|
||||||
|
mainWindow.webContents.send('run-command', runCommandOnLoad);
|
||||||
|
runCommandOnLoad = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!apiLoaded) {
|
||||||
const apiPackage = path.join(
|
const apiPackage = path.join(
|
||||||
__dirname,
|
__dirname,
|
||||||
process.env.DEVMODE ? '../../packages/api/src/index' : '../packages/api/dist/bundle.js'
|
process.env.DEVMODE ? '../../packages/api/src/index' : '../packages/api/dist/bundle.js'
|
||||||
@@ -271,6 +297,8 @@ function createWindow() {
|
|||||||
const main = api.getMainModule();
|
const main = api.getMainModule();
|
||||||
main.initializeElectronSender(mainWindow.webContents);
|
main.initializeElectronSender(mainWindow.webContents);
|
||||||
main.useAllControllers(null, electron);
|
main.useAllControllers(null, electron);
|
||||||
|
apiLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
loadMainWindow();
|
loadMainWindow();
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ module.exports = [
|
|||||||
{ command: 'group.saveAs', hideDisabled: true },
|
{ command: 'group.saveAs', hideDisabled: true },
|
||||||
{ divider: true },
|
{ divider: true },
|
||||||
{ command: 'file.exit', hideDisabled: true },
|
{ command: 'file.exit', hideDisabled: true },
|
||||||
{ command: 'app.logout', hideDisabled: true },
|
{ command: 'app.logout', hideDisabled: true, skipInApp: true },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import { apiCall } from '../utility/api';
|
|||||||
import runCommand from './runCommand';
|
import runCommand from './runCommand';
|
||||||
import { openWebLink } from '../utility/exportFileTools';
|
import { openWebLink } from '../utility/exportFileTools';
|
||||||
import { getSettings } from '../utility/metadataLoaders';
|
import { getSettings } from '../utility/metadataLoaders';
|
||||||
|
import { isMac } from '../utility/common';
|
||||||
|
|
||||||
// function themeCommand(theme: ThemeDefinition) {
|
// function themeCommand(theme: ThemeDefinition) {
|
||||||
// return {
|
// return {
|
||||||
@@ -97,7 +98,7 @@ registerCommand({
|
|||||||
toolbarOrder: 2,
|
toolbarOrder: 2,
|
||||||
name: 'Query',
|
name: 'Query',
|
||||||
toolbarName: 'New query',
|
toolbarName: 'New query',
|
||||||
keyText: 'CtrlOrCommand+Q',
|
keyText: 'CtrlOrCommand+T',
|
||||||
onClick: () => newQuery(),
|
onClick: () => newQuery(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -457,9 +458,10 @@ if (hasPermission('settings/change')) {
|
|||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'file.exit',
|
id: 'file.exit',
|
||||||
category: 'File',
|
category: 'File',
|
||||||
name: 'Exit',
|
name: isMac() ? 'Quit DbGate' : 'Exit',
|
||||||
|
keyText: isMac() ? 'Command+Q' : null,
|
||||||
testEnabled: () => getElectron() != null,
|
testEnabled: () => getElectron() != null,
|
||||||
onClick: () => getElectron().send('close-window'),
|
onClick: () => getElectron().send('quit-app'),
|
||||||
});
|
});
|
||||||
|
|
||||||
registerCommand({
|
registerCommand({
|
||||||
|
|||||||
Reference in New Issue
Block a user