mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
server-ts: Port services/tray
This commit is contained in:
parent
330334dcb4
commit
3ea4b7a72b
@ -4,7 +4,7 @@ const {app, globalShortcut, BrowserWindow} = require('electron');
|
|||||||
const sqlInit = require('./src/services/sql_init');
|
const sqlInit = require('./src/services/sql_init');
|
||||||
const appIconService = require('./src/services/app_icon.js');
|
const appIconService = require('./src/services/app_icon.js');
|
||||||
const windowService = require('./src/services/window');
|
const windowService = require('./src/services/window');
|
||||||
const tray = require('./src/services/tray.js');
|
const tray = require('./src/services/tray');
|
||||||
|
|
||||||
// Adds debug features like hotkeys for triggering dev tools and reload
|
// Adds debug features like hotkeys for triggering dev tools and reload
|
||||||
require('electron-debug')();
|
require('electron-debug')();
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
const { Menu, Tray } = require('electron');
|
import { Menu, Tray } from 'electron';
|
||||||
const path = require('path');
|
import path = require('path');
|
||||||
const windowService = require('./window');
|
import windowService = require('./window');
|
||||||
const optionService = require('./options');
|
import optionService = require('./options');
|
||||||
|
|
||||||
const UPDATE_TRAY_EVENTS = [
|
const UPDATE_TRAY_EVENTS = [
|
||||||
'minimize', 'maximize', 'show', 'hide'
|
'minimize', 'maximize', 'show', 'hide'
|
||||||
]
|
] as const;
|
||||||
|
|
||||||
let tray = null;
|
let tray: Tray | null = null;
|
||||||
// `mainWindow.isVisible` doesn't work with `mainWindow.show` and `mainWindow.hide` - it returns `false` when the window
|
// `mainWindow.isVisible` doesn't work with `mainWindow.show` and `mainWindow.hide` - it returns `false` when the window
|
||||||
// is minimized
|
// is minimized
|
||||||
let isVisible = true;
|
let isVisible = true;
|
||||||
@ -37,6 +37,7 @@ const getIconPath = () => {
|
|||||||
}
|
}
|
||||||
const registerVisibilityListener = () => {
|
const registerVisibilityListener = () => {
|
||||||
const mainWindow = windowService.getMainWindow();
|
const mainWindow = windowService.getMainWindow();
|
||||||
|
if (!mainWindow) { return; }
|
||||||
|
|
||||||
// They need to be registered before the tray updater is registered
|
// They need to be registered before the tray updater is registered
|
||||||
mainWindow.on('show', () => {
|
mainWindow.on('show', () => {
|
||||||
@ -46,13 +47,14 @@ const registerVisibilityListener = () => {
|
|||||||
isVisible = false;
|
isVisible = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
UPDATE_TRAY_EVENTS.forEach(eventName => {
|
UPDATE_TRAY_EVENTS.forEach((eventName) => {
|
||||||
mainWindow.on(eventName, updateTrayMenu)
|
mainWindow.on(eventName as any, updateTrayMenu)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateTrayMenu = () => {
|
const updateTrayMenu = () => {
|
||||||
const mainWindow = windowService.getMainWindow();
|
const mainWindow = windowService.getMainWindow();
|
||||||
|
if (!mainWindow) { return; }
|
||||||
|
|
||||||
const contextMenu = Menu.buildFromTemplate([
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
@ -83,6 +85,7 @@ const updateTrayMenu = () => {
|
|||||||
}
|
}
|
||||||
const changeVisibility = () => {
|
const changeVisibility = () => {
|
||||||
const window = windowService.getMainWindow();
|
const window = windowService.getMainWindow();
|
||||||
|
if (!window) { return; }
|
||||||
|
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
window.hide();
|
window.hide();
|
||||||
@ -106,6 +109,6 @@ function createTray() {
|
|||||||
registerVisibilityListener();
|
registerVisibilityListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export = {
|
||||||
createTray
|
createTray
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user