mirror of https://github.com/Fabio286/antares.git
feat(UI): ctrl|cmd+t, ctrl|cmd+w shortcut to open/close workspace tabs
This commit is contained in:
parent
46987faea8
commit
9046b858b1
|
@ -41,18 +41,18 @@ async function createMainWindow () {
|
||||||
remoteMain.enable(window.webContents);
|
remoteMain.enable(window.webContents);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isDevelopment) { //
|
if (isDevelopment) {
|
||||||
|
//
|
||||||
await window.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`);
|
await window.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`);
|
||||||
|
|
||||||
// const { default: installExtension, VUEJS3_DEVTOOLS } = require('electron-devtools-installer');
|
// const { default: installExtension, VUEJS3_DEVTOOLS } = require('electron-devtools-installer');
|
||||||
|
|
||||||
// const oldDevToolsID = session.defaultSession.getAllExtensions().find(ext => ext.name === 'Vue.js devtools').id;
|
// const oldDevToolsID = session.defaultSession.getAllExtensions().find(ext => ext.name === 'Vue.js devtools').id;
|
||||||
// session.defaultSession.removeExtension(oldDevToolsID);
|
// session.defaultSession.removeExtension(oldDevToolsID);
|
||||||
// const toolName = await installExtension(VUEJS3_DEVTOOLS);
|
// const toolName = await installExtension(VUEJS3_DEVTOOLS);
|
||||||
// console.log(toolName, 'installed');
|
// console.log(toolName, 'installed');
|
||||||
}
|
}
|
||||||
else
|
else await window.loadURL(new URL(`file:///${path.join(__dirname, 'index.html')}`).href);
|
||||||
await window.loadURL(new URL(`file:///${path.join(__dirname, 'index.html')}`).href);
|
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
@ -70,10 +70,9 @@ async function createMainWindow () {
|
||||||
});
|
});
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
};
|
}
|
||||||
|
|
||||||
if (!gotTheLock)
|
if (!gotTheLock) app.quit();
|
||||||
app.quit();
|
|
||||||
else {
|
else {
|
||||||
require('@electron/remote/main').initialize();
|
require('@electron/remote/main').initialize();
|
||||||
|
|
||||||
|
@ -83,33 +82,53 @@ else {
|
||||||
// quit application when all windows are closed
|
// quit application when all windows are closed
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
// on macOS it is common for applications to stay open until the user explicitly quits
|
// on macOS it is common for applications to stay open until the user explicitly quits
|
||||||
if (process.platform !== 'darwin')
|
if (process.platform !== 'darwin') app.quit();
|
||||||
app.quit();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('activate', async () => {
|
app.on('activate', async () => {
|
||||||
// on macOS it is common to re-create a window even after all windows have been closed
|
// on macOS it is common to re-create a window even after all windows have been closed
|
||||||
if (mainWindow === null) {
|
if (mainWindow === null) {
|
||||||
mainWindow = await createMainWindow();
|
mainWindow = await createMainWindow();
|
||||||
if (isDevelopment)
|
if (isDevelopment) mainWindow.webContents.openDevTools();
|
||||||
mainWindow.webContents.openDevTools();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// create main BrowserWindow when electron is ready
|
// create main BrowserWindow when electron is ready
|
||||||
app.on('ready', async () => {
|
app.on('ready', async () => {
|
||||||
mainWindow = await createMainWindow();
|
mainWindow = await createMainWindow();
|
||||||
Menu.setApplicationMenu(null);
|
createAppMenu();
|
||||||
|
|
||||||
if (isDevelopment)
|
if (isDevelopment) mainWindow.webContents.openDevTools();
|
||||||
mainWindow.webContents.openDevTools();
|
|
||||||
|
|
||||||
process.on('uncaughtException', error => {
|
process.on('uncaughtException', (error) => {
|
||||||
mainWindow.webContents.send('unhandled-exception', error);
|
mainWindow.webContents.send('unhandled-exception', error);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('unhandledRejection', error => {
|
process.on('unhandledRejection', (error) => {
|
||||||
mainWindow.webContents.send('unhandled-exception', error);
|
mainWindow.webContents.send('unhandled-exception', error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createAppMenu () {
|
||||||
|
let menu = null;
|
||||||
|
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
menu = Menu.buildFromTemplate([
|
||||||
|
{
|
||||||
|
label: app.name,
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
role: 'about'
|
||||||
|
},
|
||||||
|
{ type: 'separator' },
|
||||||
|
{
|
||||||
|
role: 'quit'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu.setApplicationMenu(menu);
|
||||||
|
}
|
||||||
|
|
|
@ -586,11 +586,16 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async created () {
|
async created () {
|
||||||
|
window.addEventListener('keydown', this.onKey);
|
||||||
await this.addWorkspace(this.connection.uid);
|
await this.addWorkspace(this.connection.uid);
|
||||||
const isInitiated = await Connection.checkConnection(this.connection.uid);
|
const isInitiated = await Connection.checkConnection(this.connection.uid);
|
||||||
if (isInitiated)
|
if (isInitiated)
|
||||||
this.connectWorkspace(this.connection);
|
this.connectWorkspace(this.connection);
|
||||||
},
|
},
|
||||||
|
beforeDestroy () {
|
||||||
|
window.removeEventListener('keydown', this.onKey);
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions({
|
...mapActions({
|
||||||
addWorkspace: 'workspaces/addWorkspace',
|
addWorkspace: 'workspaces/addWorkspace',
|
||||||
|
@ -604,6 +609,25 @@ export default {
|
||||||
addQueryTab () {
|
addQueryTab () {
|
||||||
this.newTab({ uid: this.connection.uid, type: 'query' });
|
this.newTab({ uid: this.connection.uid, type: 'query' });
|
||||||
},
|
},
|
||||||
|
getSelectedTab () {
|
||||||
|
return this.workspace.tabs.find(tab => tab.uid === this.selectedTab);
|
||||||
|
},
|
||||||
|
onKey (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
if (!this.isSelected)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ((e.ctrlKey || e.metaKey) && e.keyCode === 84) { // CTRL|Command + t
|
||||||
|
this.addQueryTab();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((e.ctrlKey || e.metaKey) && e.keyCode === 87) { // CTRL|Command + w
|
||||||
|
const currentTab = this.getSelectedTab();
|
||||||
|
if (currentTab)
|
||||||
|
this.closeTab(currentTab);
|
||||||
|
}
|
||||||
|
},
|
||||||
openAsPermanentTab (tab) {
|
openAsPermanentTab (tab) {
|
||||||
const permanentTabs = {
|
const permanentTabs = {
|
||||||
table: 'data',
|
table: 'data',
|
||||||
|
|
Loading…
Reference in New Issue