Notes/src/public/app/widgets/buttons/global_menu.js

323 lines
10 KiB
JavaScript
Raw Normal View History

2021-05-24 22:29:49 +02:00
import BasicWidget from "../basic_widget.js";
import utils from "../../services/utils.js";
import UpdateAvailableWidget from "./update_available.js";
2022-07-19 16:01:27 -04:00
import options from "../../services/options.js";
2020-01-15 19:40:17 +01:00
const TPL = `
2021-05-28 22:47:59 +02:00
<div class="dropdown global-menu dropright">
2020-01-15 19:40:17 +01:00
<style>
2021-06-13 22:55:31 +02:00
.global-menu {
width: 53px;
height: 53px;
}
2020-01-15 19:40:17 +01:00
.global-menu .dropdown-menu {
min-width: 20em;
2020-01-15 19:40:17 +01:00
}
2021-06-06 22:15:51 +02:00
.global-menu-button {
background-image: url("${window.glob.assetPath}/images/icon-black.png");
2021-06-06 22:15:51 +02:00
background-repeat: no-repeat;
background-position: 50% 45%;
2021-06-13 22:55:31 +02:00
width: 100%;
height: 100%;
position: relative;
2021-06-06 22:15:51 +02:00
}
.global-menu-button:hover {
background-image: url("${window.glob.assetPath}/images/icon-color.png");
2023-01-02 21:08:20 +01:00
border: 0;
2021-06-06 22:15:51 +02:00
}
.global-menu-button-update-available {
position: absolute;
right: -30px;
bottom: -30px;
width: 100%;
height: 100%;
pointer-events: none;
}
.update-to-latest-version-button {
display: none;
}
2022-11-25 09:21:56 +01:00
.global-menu .zoom-container {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: baseline;
}
.global-menu .zoom-buttons a {
display: inline-block;
border: 1px solid var(--button-border-color);
border-radius: var(--button-border-radius);
color: var(--button-text-color);
background-color: var(--button-background-color);
padding: 3px;
margin-left: 3px;
}
.global-menu .zoom-buttons a:hover {
text-decoration: none;
}
.global-menu .zoom-state {
margin-left: 5px;
margin-right: 5px;
}
2022-11-25 09:21:56 +01:00
.global-menu .dropdown-item .bx {
position: relative;
top: 3px;
font-size: 120%;
margin-right: 5px;
}
2023-02-17 16:44:04 +01:00
body.mobile .show-help-button, body.mobile .show-about-dialog-button {
/* hidden because these dialogs are not available for mobile */
display: none;
}
body.mobile .global-menu .dropdown-submenu .dropdown-menu {
display: block;
font-size: 90%;
position: relative;
left: 0;
top: 5px;
}
2020-01-15 19:40:17 +01:00
</style>
2021-06-06 22:15:51 +02:00
<button type="button" data-toggle="dropdown" data-placement="right"
aria-haspopup="true" aria-expanded="false"
class="icon-action global-menu-button" title="Menu">
<div class="global-menu-button-update-available"></div>
</button>
2021-05-28 22:47:59 +02:00
2022-11-24 22:59:09 +01:00
<ul class="dropdown-menu dropdown-menu-right">
2022-12-05 23:57:29 +01:00
<li class="dropdown-item" data-trigger-command="showOptions">
2021-05-28 22:47:59 +02:00
<span class="bx bx-slider"></span>
Options
2022-11-24 22:59:09 +01:00
</li>
2021-05-28 22:47:59 +02:00
2022-11-24 22:59:09 +01:00
<li class="dropdown-item" data-trigger-command="openNewWindow">
2021-05-28 22:47:59 +02:00
<span class="bx bx-window-open"></span>
2022-12-15 16:38:05 +01:00
Open New Window
2021-05-28 22:47:59 +02:00
<kbd data-command="openNewWindow"></kbd>
2022-11-24 22:59:09 +01:00
</li>
2021-05-28 22:47:59 +02:00
2022-11-24 22:59:09 +01:00
<li class="dropdown-item switch-to-mobile-version-button" data-trigger-command="switchToMobileVersion">
<span class="bx bx-mobile"></span>
2022-12-15 16:38:05 +01:00
Switch to Mobile Version
2022-11-24 22:59:09 +01:00
</li>
<li class="dropdown-item switch-to-desktop-version-button" data-trigger-command="switchToDesktopVersion">
<span class="bx bx-desktop"></span>
2022-12-15 16:38:05 +01:00
Switch to Desktop Version
</li>
2022-11-25 09:21:56 +01:00
<span class="zoom-container dropdown-item">
<div>
<span class="bx bx-empty"></span>
Zoom
</div>
<div class="zoom-buttons">
2022-12-15 16:38:05 +01:00
<a data-trigger-command="toggleFullscreen" title="Toggle Fullscreen" class="bx bx-expand-alt"></a>
&nbsp;
2022-12-15 16:38:05 +01:00
<a data-trigger-command="zoomOut" title="Zoom Out" class="bx bx-minus"></a>
<span class="zoom-state"></span>
2022-12-15 16:38:05 +01:00
<a data-trigger-command="zoomIn" title="Zoom In" class="bx bx-plus"></a>
</div>
</span>
2021-05-28 22:47:59 +02:00
2022-12-01 10:03:04 +01:00
<li class="dropdown-item" data-trigger-command="showLaunchBarSubtree">
2022-11-25 09:21:56 +01:00
<span class="bx bx-sidebar"></span>
2022-12-15 16:38:05 +01:00
Configure Launchbar
2022-11-24 22:59:09 +01:00
</li>
2022-11-25 15:29:57 +01:00
<li class="dropdown-item" data-trigger-command="showShareSubtree">
<span class="bx bx-share-alt"></span>
2022-12-15 16:38:05 +01:00
Show Shared Notes Subtree
2022-11-25 15:29:57 +01:00
</li>
2022-11-24 22:59:09 +01:00
<li class="dropdown-item dropdown-submenu">
<span class="dropdown-toggle">
<span class="bx bx-empty"></span>
Advanced
</span>
<ul class="dropdown-menu">
<li class="dropdown-item open-dev-tools-button" data-trigger-command="openDevTools">
2022-12-15 16:38:05 +01:00
<span class="bx bx-bug-alt"></span>
2022-11-24 22:59:09 +01:00
Open Dev Tools
<kbd data-command="openDevTools"></kbd>
</li>
<li class="dropdown-item" data-trigger-command="showSQLConsole">
<span class="bx bx-data"></span>
Open SQL Console
<kbd data-command="showSQLConsole"></kbd>
</li>
2022-12-15 16:38:05 +01:00
<li class="dropdown-item" data-trigger-command="showSQLConsoleHistory">
<span class="bx bx-empty"></span>
Open SQL Console History
</li>
<li class="dropdown-item" data-trigger-command="showSearchHistory">
<span class="bx bx-empty"></span>
Open Search History
</li>
2022-11-24 22:59:09 +01:00
<li class="dropdown-item" data-trigger-command="showBackendLog">
<span class="bx bx-empty"></span>
2022-12-15 16:38:05 +01:00
Show Backend Log
2022-11-24 22:59:09 +01:00
<kbd data-command="showBackendLog"></kbd>
</li>
<li class="dropdown-item" data-trigger-command="reloadFrontendApp"
title="Reload can help with some visual glitches without restarting the whole app.">
<span class="bx bx-empty"></span>
2022-12-15 16:38:05 +01:00
Reload Frontend
2022-11-24 22:59:09 +01:00
<kbd data-command="reloadFrontendApp"></kbd>
</li>
2022-11-25 15:29:57 +01:00
<li class="dropdown-item" data-trigger-command="showHiddenSubtree">
<span class="bx bx-empty"></span>
2022-12-15 16:38:05 +01:00
Show Hidden Subtree
2022-11-25 15:29:57 +01:00
</li>
2022-11-24 22:59:09 +01:00
</ul>
</li>
2023-02-17 16:44:04 +01:00
<li class="dropdown-item show-help-button" data-trigger-command="showHelp">
2021-05-28 22:47:59 +02:00
<span class="bx bx-info-circle"></span>
2023-02-17 16:44:04 +01:00
Show Help
<kbd data-command="showHelp"></kbd>
2022-11-24 22:59:09 +01:00
</li>
2021-05-28 22:47:59 +02:00
2022-11-24 22:59:09 +01:00
<li class="dropdown-item show-about-dialog-button">
2021-05-28 22:47:59 +02:00
<span class="bx bx-empty"></span>
About Trilium Notes
2022-11-24 22:59:09 +01:00
</li>
2021-05-28 22:47:59 +02:00
2022-11-24 22:59:09 +01:00
<li class="dropdown-item update-to-latest-version-button" data-trigger-command="downloadLatestVersion">
<span class="bx bx-sync"></span>
<span class="version-text"></span>
2022-11-24 22:59:09 +01:00
</li>
2022-11-24 22:59:09 +01:00
<li class="dropdown-item logout-button" data-trigger-command="logout">
2021-05-28 22:47:59 +02:00
<span class="bx bx-log-out"></span>
Logout
2022-11-24 22:59:09 +01:00
</li>
</ul>
2020-01-15 19:40:17 +01:00
</div>
`;
export default class GlobalMenuWidget extends BasicWidget {
constructor() {
super();
this.updateAvailableWidget = new UpdateAvailableWidget();
}
2020-01-22 20:48:56 +01:00
doRender() {
2020-01-15 19:40:17 +01:00
this.$widget = $(TPL);
this.$dropdown = this.$widget.find("[data-toggle='dropdown']");
2021-07-05 08:59:36 +02:00
const $button = this.$widget.find(".global-menu-button");
2021-07-05 17:10:10 +02:00
$button.tooltip({ trigger: "hover" });
2021-07-05 08:59:36 +02:00
$button.on("click", () => $button.tooltip("hide"));
2021-06-06 22:15:51 +02:00
2022-06-12 14:03:59 +02:00
this.$widget.find(".show-about-dialog-button").on('click', () => this.triggerCommand("openAboutDialog"));
2020-01-15 19:40:17 +01:00
const isElectron = utils.isElectron();
2020-01-15 19:40:17 +01:00
this.$widget.find(".logout-button").toggle(!isElectron);
this.$widget.find(".open-dev-tools-button").toggle(isElectron);
this.$widget.find(".switch-to-mobile-version-button").toggle(!isElectron && utils.isDesktop());
this.$widget.find(".switch-to-desktop-version-button").toggle(!isElectron && utils.isMobile());
this.$widget.on('click', '.dropdown-item', e => {
if ($(e.target).parent(".zoom-buttons")) {
return;
}
this.$dropdown.dropdown('toggle');
});
this.$widget.find(".global-menu-button-update-available").append(
this.updateAvailableWidget.render()
);
this.$updateToLatestVersionButton = this.$widget.find(".update-to-latest-version-button");
if (!utils.isElectron()) {
this.$widget.find(".zoom-container").hide();
}
this.$zoomState = this.$widget.find(".zoom-state");
this.$widget.on('show.bs.dropdown', () => this.updateZoomState());
this.$widget.find(".zoom-buttons").on("click",
// delay to wait for the actual zoom change
() => setTimeout(() => this.updateZoomState(), 300)
);
this.updateVersionStatus();
setInterval(() => this.updateVersionStatus(), 8 * 60 * 60 * 1000);
}
updateZoomState() {
2022-09-15 23:10:54 +02:00
if (!utils.isElectron()) {
return;
}
const zoomFactor = utils.dynamicRequire('electron').webFrame.getZoomFactor();
const zoomPercent = Math.round(zoomFactor * 100);
this.$zoomState.text(`${zoomPercent}%`);
}
async updateVersionStatus() {
2022-12-11 22:26:18 +01:00
await options.initializedPromise;
if (options.get("checkForUpdates") !== 'true') {
return;
2022-07-19 16:01:27 -04:00
}
const latestVersion = await this.fetchLatestVersion();
this.updateAvailableWidget.updateVersionStatus(latestVersion);
this.$updateToLatestVersionButton.toggle(latestVersion > glob.triliumVersion);
this.$updateToLatestVersionButton.find(".version-text").text(`Version ${latestVersion} is available, click to download.`);
}
async fetchLatestVersion() {
const RELEASES_API_URL = "https://api.github.com/repos/zadam/trilium/releases/latest";
const resp = await fetch(RELEASES_API_URL);
const data = await resp.json();
2023-01-17 21:06:30 +01:00
return data?.tag_name?.substring(1);
2020-01-15 19:40:17 +01:00
}
downloadLatestVersionCommand() {
window.open("https://github.com/zadam/trilium/releases/latest");
}
activeContextChangedEvent() {
this.$dropdown.dropdown('hide');
}
noteSwitchedEvent() {
this.$dropdown.dropdown('hide');
}
}