2021-05-24 22:29:49 +02:00
|
|
|
import BasicWidget from "../basic_widget.js";
|
|
|
|
import utils from "../../services/utils.js";
|
2021-11-14 12:42:50 +00:00
|
|
|
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 {
|
2021-11-14 21:52:18 +01:00
|
|
|
min-width: 20em;
|
2020-01-15 19:40:17 +01:00
|
|
|
}
|
2021-06-06 22:15:51 +02:00
|
|
|
|
|
|
|
.global-menu-button {
|
2022-10-26 23:50:54 +02:00
|
|
|
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%;
|
2021-11-14 12:42:50 +00:00
|
|
|
position: relative;
|
2021-06-06 22:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.global-menu-button:hover {
|
2022-10-26 23:50:54 +02:00
|
|
|
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
|
|
|
}
|
2021-11-14 12:42:50 +00:00
|
|
|
|
|
|
|
.global-menu-button-update-available {
|
|
|
|
position: absolute;
|
|
|
|
right: -30px;
|
|
|
|
bottom: -30px;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
2022-08-24 22:07:04 +02:00
|
|
|
|
|
|
|
.update-to-latest-version-button {
|
|
|
|
display: none;
|
|
|
|
}
|
2022-09-14 23:28:29 +02:00
|
|
|
|
2022-11-25 09:21:56 +01:00
|
|
|
.global-menu .zoom-container {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: baseline;
|
|
|
|
}
|
|
|
|
|
2022-09-14 23:28:29 +02:00
|
|
|
.global-menu .zoom-buttons a {
|
|
|
|
display: inline-block;
|
|
|
|
border: 1px solid var(--button-border-color);
|
2022-09-18 13:52:19 +02:00
|
|
|
border-radius: var(--button-border-radius);
|
2022-09-14 23:28:29 +02:00
|
|
|
color: var(--button-text-color);
|
|
|
|
background-color: var(--button-background-color);
|
2022-09-18 13:52:19 +02:00
|
|
|
padding: 3px;
|
|
|
|
margin-left: 3px;
|
2022-09-14 23:28:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.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;
|
|
|
|
}
|
2022-12-13 22:29:26 +01:00
|
|
|
|
2023-02-17 16:44:04 +01:00
|
|
|
body.mobile .show-help-button, body.mobile .show-about-dialog-button {
|
2022-12-13 22:29:26 +01:00
|
|
|
/* hidden because these dialogs are not available for mobile */
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2022-12-25 11:58:24 +01:00
|
|
|
body.mobile .global-menu .dropdown-submenu .dropdown-menu {
|
2022-12-13 22:29:26 +01:00
|
|
|
display: block;
|
|
|
|
font-size: 90%;
|
|
|
|
position: relative;
|
|
|
|
left: 0;
|
2023-02-15 14:49:58 +01:00
|
|
|
top: 5px;
|
2022-12-13 22:29:26 +01:00
|
|
|
}
|
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"
|
2021-11-14 12:42:50 +00:00
|
|
|
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">
|
2022-12-12 23:48:34 +01:00
|
|
|
<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>
|
2022-09-14 23:28:29 +02:00
|
|
|
|
2022-12-12 23:48:34 +01:00
|
|
|
<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
|
2022-12-12 23:48:34 +01:00
|
|
|
</li>
|
|
|
|
|
2022-11-25 09:21:56 +01:00
|
|
|
<span class="zoom-container dropdown-item">
|
2022-09-14 23:28:29 +02:00
|
|
|
<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>
|
2022-09-14 23:28:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-12-15 16:38:05 +01:00
|
|
|
<a data-trigger-command="zoomOut" title="Zoom Out" class="bx bx-minus"></a>
|
2022-09-14 23:28:29 +02:00
|
|
|
|
|
|
|
<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>
|
2022-09-14 23:28:29 +02:00
|
|
|
</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">
|
2021-11-14 12:42:50 +00:00
|
|
|
<span class="bx bx-sync"></span>
|
2021-11-14 21:52:18 +01:00
|
|
|
|
|
|
|
<span class="version-text"></span>
|
2022-11-24 22:59:09 +01:00
|
|
|
</li>
|
2021-11-14 12:42:50 +00:00
|
|
|
|
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 {
|
2021-11-14 21:52:18 +01:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.updateAvailableWidget = new UpdateAvailableWidget();
|
2021-11-14 12:42:50 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 20:48:56 +01:00
|
|
|
doRender() {
|
2020-01-15 19:40:17 +01:00
|
|
|
this.$widget = $(TPL);
|
|
|
|
|
2023-03-24 09:32:06 +01:00
|
|
|
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
|
|
|
|
2021-10-31 16:56:23 +01:00
|
|
|
const isElectron = utils.isElectron();
|
2020-01-15 19:40:17 +01:00
|
|
|
|
2021-10-31 16:56:23 +01:00
|
|
|
this.$widget.find(".logout-button").toggle(!isElectron);
|
|
|
|
this.$widget.find(".open-dev-tools-button").toggle(isElectron);
|
2022-12-12 23:48:34 +01:00
|
|
|
this.$widget.find(".switch-to-mobile-version-button").toggle(!isElectron && utils.isDesktop());
|
|
|
|
this.$widget.find(".switch-to-desktop-version-button").toggle(!isElectron && utils.isMobile());
|
2020-08-28 14:52:38 +02:00
|
|
|
|
2022-09-14 23:28:29 +02:00
|
|
|
this.$widget.on('click', '.dropdown-item', e => {
|
|
|
|
if ($(e.target).parent(".zoom-buttons")) {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-14 12:42:50 +00:00
|
|
|
|
2023-03-24 09:32:06 +01:00
|
|
|
this.$dropdown.dropdown('toggle');
|
2022-09-14 23:28:29 +02:00
|
|
|
});
|
2021-11-14 12:42:50 +00:00
|
|
|
|
2021-11-14 21:52:18 +01:00
|
|
|
this.$widget.find(".global-menu-button-update-available").append(
|
|
|
|
this.updateAvailableWidget.render()
|
|
|
|
);
|
|
|
|
|
|
|
|
this.$updateToLatestVersionButton = this.$widget.find(".update-to-latest-version-button");
|
2021-11-14 12:42:50 +00:00
|
|
|
|
2022-09-14 23:28:29 +02:00
|
|
|
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)
|
|
|
|
);
|
|
|
|
|
2021-11-14 21:52:18 +01:00
|
|
|
this.updateVersionStatus();
|
2021-11-14 12:42:50 +00:00
|
|
|
|
2021-11-14 21:52:18 +01:00
|
|
|
setInterval(() => this.updateVersionStatus(), 8 * 60 * 60 * 1000);
|
|
|
|
}
|
2021-11-14 12:42:50 +00:00
|
|
|
|
2022-09-14 23:28:29 +02:00
|
|
|
updateZoomState() {
|
2022-09-15 23:10:54 +02:00
|
|
|
if (!utils.isElectron()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-14 23:28:29 +02:00
|
|
|
const zoomFactor = utils.dynamicRequire('electron').webFrame.getZoomFactor();
|
|
|
|
const zoomPercent = Math.round(zoomFactor * 100);
|
|
|
|
|
2022-12-21 15:19:05 +01:00
|
|
|
this.$zoomState.text(`${zoomPercent}%`);
|
2022-09-14 23:28:29 +02:00
|
|
|
}
|
|
|
|
|
2021-11-14 21:52:18 +01:00
|
|
|
async updateVersionStatus() {
|
2022-12-11 22:26:18 +01:00
|
|
|
await options.initializedPromise;
|
|
|
|
|
2022-07-20 00:11:12 +02:00
|
|
|
if (options.get("checkForUpdates") !== 'true') {
|
|
|
|
return;
|
2022-07-19 16:01:27 -04:00
|
|
|
}
|
2022-07-20 00:11:12 +02: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.`);
|
2021-11-14 12:42:50 +00:00
|
|
|
}
|
|
|
|
|
2021-11-14 21:52:18 +01:00
|
|
|
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();
|
2021-11-14 12:42:50 +00:00
|
|
|
|
2023-01-17 21:06:30 +01:00
|
|
|
return data?.tag_name?.substring(1);
|
2020-01-15 19:40:17 +01:00
|
|
|
}
|
2021-11-14 21:52:18 +01:00
|
|
|
|
|
|
|
downloadLatestVersionCommand() {
|
|
|
|
window.open("https://github.com/zadam/trilium/releases/latest");
|
|
|
|
}
|
2023-03-24 09:32:06 +01:00
|
|
|
|
|
|
|
activeContextChangedEvent() {
|
|
|
|
this.$dropdown.dropdown('hide');
|
|
|
|
}
|
|
|
|
|
|
|
|
noteSwitchedEvent() {
|
|
|
|
this.$dropdown.dropdown('hide');
|
|
|
|
}
|
2020-06-13 10:23:36 +02:00
|
|
|
}
|