import BasicWidget from "../basic_widget.js"; import utils from "../../services/utils.js"; import UpdateAvailableWidget from "./update_available.js"; const axios = require("axios"); const TPL = ` `; const RELEASES_API_URL = "https://api.github.com/repos/zadam/trilium/releases/latest"; const CURRENT_VERSION = process.env.npm_package_version; export default class GlobalMenuWidget extends BasicWidget { static getVersionChange(oldVersion, newVersion) { const [oldMajor, oldMinor, oldPatch] = oldVersion.split(".").map(Number); const [newMajor, newMinor, newPatch] = newVersion.split(".").map(Number); if (newMajor !== oldMajor) { return "major"; } else if (newMinor !== oldMinor) { return "minor"; } else if (newPatch !== oldPatch) { return "patch"; } } doRender() { this.$widget = $(TPL); const $button = this.$widget.find(".global-menu-button"); $button.tooltip({ trigger: "hover" }); $button.on("click", () => $button.tooltip("hide")); this.$widget.find(".show-about-dialog-button").on('click', () => import("../../dialogs/about.js").then(d => d.showDialog())); const isElectron = utils.isElectron(); 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', () => this.$widget.find("[data-toggle='dropdown']").dropdown('toggle')); this.loadUpdateAvailable(); } async loadUpdateAvailable() { const newVersion = await this.fetchNewVersion(); if (!newVersion) { return; } const versionChange = "major"; this.$widget.find(".global-menu-button-update-available").append( new UpdateAvailableWidget() .withVersionChange(versionChange) .render() ) } async fetchNewVersion() { const {data} = await axios.get(RELEASES_API_URL); return data.tag_name.substring(1); } }