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

265 lines
8.7 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");
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;
}
.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;
}
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">
<li class="dropdown-item options-button" 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>
Open new window
<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-empty"></span>
Switch to mobile version
2022-11-24 22:59:09 +01:00
</li>
<span class="zoom-container dropdown-item" style="display: flex; flex-direction: row; justify-content: space-between;">
<div>
<span class="bx bx-empty"></span>
Zoom
</div>
<div class="zoom-buttons">
<a data-trigger-command="toggleFullscreen" title="Toggle fullscreen" class="bx bx-expand-alt"></a>
&nbsp;
<a data-trigger-command="zoomOut" title="Zoom out" class="bx bx-minus"></a>
<span class="zoom-state"></span>
<a data-trigger-command="zoomIn" title="Zoom in" class="bx bx-plus"></a>
</div>
</span>
2021-05-28 22:47:59 +02:00
2022-11-24 22:59:09 +01:00
<li class="dropdown-item" data-trigger-command="toggleFullscreen">
2021-05-28 22:47:59 +02:00
<span class="bx bx-empty"></span>
Toggle fullscreen
<kbd ></kbd>
2022-11-24 22:59:09 +01:00
</li>
<li class="dropdown-item options-button" data-trigger-command="showLaunchBarShortcuts">
<span class="bx bx-horizontal-left"></span>
Configure launchbar shortcuts
</li>
<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">
<span class="bx bx-terminal"></span>
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>
<li class="dropdown-item" data-trigger-command="showBackendLog">
<span class="bx bx-empty"></span>
Show backend log
<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>
Reload frontend
<kbd data-command="reloadFrontendApp"></kbd>
</li>
</ul>
</li>
<li class="dropdown-item" data-trigger-command="showHelp">
2021-05-28 22:47:59 +02:00
<span class="bx bx-info-circle"></span>
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);
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);
this.$widget.on('click', '.dropdown-item', e => {
if ($(e.target).parent(".zoom-buttons")) {
return;
}
this.$widget.find("[data-toggle='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() {
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();
return data.tag_name.substring(1);
2020-01-15 19:40:17 +01:00
}
downloadLatestVersionCommand() {
window.open("https://github.com/zadam/trilium/releases/latest");
}
}