import BasicWidget from "./basic_widget.js"; import keyboardActionService from "../services/keyboard_actions.js"; import utils from "../services/utils.js"; import syncService from "../services/sync.js"; const OPTIONS = "../dialogs/options.js"; const SQL_CONSOLE = "../dialogs/sql_console.js"; const BACKEND_LOG = "../dialogs/backend_log.js"; const HELP = "../dialogs/help.js"; const ABOUT = "../dialogs/about.js"; const TPL = ` `; export default class GlobalMenuWidget extends BasicWidget { render() { this.$widget = $(TPL); let zenModeActive = false; // hide (toggle) everything except for the note content for zen mode const toggleZenMode = () => { if (!zenModeActive) { $(".hide-in-zen-mode,.gutter").addClass("hidden-by-zen-mode"); $("#container").addClass("zen-mode"); zenModeActive = true; } else { // not hiding / showing explicitly since element might be hidden also for other reasons $(".hide-in-zen-mode,.gutter").removeClass("hidden-by-zen-mode"); $("#container").removeClass("zen-mode"); zenModeActive = false; } }; this.$widget.find(".toggle-zen-mode-button").on('click', toggleZenMode); keyboardActionService.setGlobalActionHandler("ToggleZenMode", toggleZenMode); this.$widget.find(".reload-frontend-button").on('click', utils.reloadApp); keyboardActionService.setGlobalActionHandler("ReloadFrontendApp", utils.reloadApp); this.$widget.find(".open-dev-tools-button").toggle(utils.isElectron()); const showOptionsDialog = () => import(OPTIONS).then(d => d.showDialog()); this.$widget.find(".options-button").on('click', showOptionsDialog); keyboardActionService.setGlobalActionHandler("ShowOptions", showOptionsDialog); const showHelpDialog = () => import(HELP).then(d => d.showDialog()); this.$widget.find(".show-help-button").on('click', showHelpDialog); keyboardActionService.setGlobalActionHandler("ShowHelp", showHelpDialog); const showSqlConsoleDialog = () => import(SQL_CONSOLE).then(d => d.showDialog()); this.$widget.find(".open-sql-console-button").on('click', showSqlConsoleDialog); keyboardActionService.setGlobalActionHandler("ShowSQLConsole", showSqlConsoleDialog); const showBackendLogDialog = () => import(BACKEND_LOG).then(d => d.showDialog()); this.$widget.find(".show-backend-log-button").on('click', showBackendLogDialog); keyboardActionService.setGlobalActionHandler("ShowBackendLog", showBackendLogDialog); this.$widget.find(".show-about-dialog-button").on('click', () => import(ABOUT).then(d => d.showDialog())); this.$widget.find(".sync-now-button").on('click', () => syncService.syncNow()); if (utils.isElectron()) { const toggleFullscreen = () => { const win = require('electron').remote.getCurrentWindow(); if (win.isFullScreenable()) { win.setFullScreen(!win.isFullScreen()); } return false; }; this.$widget.find(".toggle-fullscreen-button").on('click', toggleFullscreen); keyboardActionService.setGlobalActionHandler("ToggleFullscreen", toggleFullscreen); } else { // outside of electron this is handled by the browser this.$widget.find(".toggle-fullscreen-button").hide(); } this.$widget.find(".logout-button") .toggle(!utils.isElectron()) .on('click', () => { const $logoutForm = $('
') .append($(``)); $("body").append($logoutForm); $logoutForm.trigger('submit'); }); return this.$widget; } }