app menu definition in JSON

This commit is contained in:
Jan Prochazka
2022-02-12 07:40:58 +01:00
parent 19a43b6fbc
commit 0c951b4659
9 changed files with 266 additions and 107 deletions

View File

@@ -26,6 +26,7 @@ import { removeLocalStorage } from '../utility/storageCache';
import { showSnackbarSuccess } from '../utility/snackbar';
import { apiCall } from '../utility/api';
import runCommand from './runCommand';
import { openWebLink } from '../utility/exportElectronFile';
function themeCommand(theme: ThemeDefinition) {
return {
@@ -552,6 +553,66 @@ export function registerFileCommands({
}
}
registerCommand({
id: 'app.minimize',
category: 'Application',
name: 'Minimize',
testEnabled: () => getElectron() != null,
onClick: () => getElectron().send('window-action', 'minimize'),
});
registerCommand({
id: 'app.toggleFullScreen',
category: 'Application',
name: 'Toggle full screen',
testEnabled: () => getElectron() != null,
onClick: () => getElectron().send('window-action', 'fullscreen'),
});
registerCommand({
id: 'app.toggleDevTools',
category: 'Application',
name: 'Toggle Dev Tools',
testEnabled: () => getElectron() != null,
onClick: () => getElectron().send('window-action', 'devtools'),
});
registerCommand({
id: 'app.reload',
category: 'Application',
name: 'Reload',
testEnabled: () => getElectron() != null,
onClick: () => getElectron().send('window-action', 'reload'),
});
registerCommand({
id: 'app.openDocs',
category: 'Application',
name: 'Documentation',
onClick: () => openWebLink('https://github.com/dbgate/dbgate/wiki'),
});
registerCommand({
id: 'app.openWeb',
category: 'Application',
name: 'DbGate web',
onClick: () => openWebLink('https://dbgate.org'),
});
registerCommand({
id: 'app.openIssue',
category: 'Application',
name: 'Report problem or feature request',
onClick: () => openWebLink('https://github.com/dbgate/dbgate/issues/new'),
});
registerCommand({
id: 'app.openSponsoring',
category: 'Application',
name: 'Become sponsor',
onClick: () => openWebLink('https://opencollective.com/dbgate'),
});
const electron = getElectron();
if (electron) {
electron.addEventListener('run-command', (e, commandId) => runCommand(commandId));

View File

@@ -1,25 +1,18 @@
<script lang="ts">
import getElectron from '../utility/getElectron';
import { openWebLink } from '../utility/exportElectronFile';
export let href = undefined;
export let onClick = undefined;
const electron = getElectron();
</script>
{#if onClick}
<a on:click={onClick}>
<slot />
</a>
{:else if electron}
<a on:click={() => electron.shell.openExternal(href)}>
<slot />
</a>
{:else}
<a {href} target="_blank" rel="noopener noreferrer">
<slot />
</a>
{/if}
<a
on:click={() => {
if (onClick) onClick();
else openWebLink(href);
}}
>
<slot />
</a>
<style>
a {

View File

@@ -136,7 +136,7 @@
}}
>
<a on:click={e => handleClick(e, item)} class:disabled={item.disabled}>
{item.text}
{item.text || item.label}
{#if item.keyText}
<span class="keyText">{item.keyText}</span>
{/if}

View File

@@ -78,3 +78,13 @@ export async function saveFileToDisk(
window.open(`${resolveApi()}/uploads/get?file=${resp.fileName}`, '_blank');
}
}
export function openWebLink(href) {
const electron = getElectron();
if (electron) {
electron.send('open-link', href);
} else {
window.open(href, '_blank');
}
}

View File

@@ -10,7 +10,7 @@
</script>
<div class="container">
<div class="icon"><FontIcon icon="img dbgate" /></div>
<div class="icon"><img src="logo192.png" width="20" height="20" /></div>
<div class="menu">File Edit Window</div>
<div class="title">{title}</div>
@@ -41,6 +41,7 @@
.title {
flex-grow: 1;
text-align: center;
/* font-weight: bold; */
}
.icon {