server-ts: Address some review comments

This commit is contained in:
Elian Doran 2024-04-02 23:39:45 +03:00
parent a420129631
commit d4c8d24d50
No known key found for this signature in database
3 changed files with 7 additions and 12 deletions

View File

@ -51,9 +51,7 @@ class SearchResult {
addScoreForStrings(tokens: string[], str: string, factor: number) { addScoreForStrings(tokens: string[], str: string, factor: number) {
const chunks = str.toLowerCase().split(" "); const chunks = str.toLowerCase().split(" ");
if (!this.score) { this.score = 0;
this.score = 0;
}
for (const chunk of chunks) { for (const chunk of chunks) {
for (const token of tokens) { for (const token of tokens) {

View File

@ -113,7 +113,7 @@ class ValueExtractor {
i++; i++;
const attr = cursor.getAttributeCaseInsensitive('relation', cur()); const attr = cursor.getAttributeCaseInsensitive('relation', cur());
cursor = (attr ? attr.targetNote || null : null); cursor = attr?.targetNote || null;
} }
else if (cur() === 'parents') { else if (cur() === 'parents') {
cursor = cursor.parents[0]; cursor = cursor.parents[0];

View File

@ -3,11 +3,7 @@ import path = require('path');
import windowService = require('./window'); import windowService = require('./window');
import optionService = require('./options'); import optionService = require('./options');
const UPDATE_TRAY_EVENTS = [ let tray: Tray;
'minimize', 'maximize', 'show', 'hide'
] as const;
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;
@ -42,14 +38,15 @@ const registerVisibilityListener = () => {
// 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', () => {
isVisible = true; isVisible = true;
updateTrayMenu();
}); });
mainWindow.on('hide', () => { mainWindow.on('hide', () => {
isVisible = false; isVisible = false;
updateTrayMenu();
}); });
UPDATE_TRAY_EVENTS.forEach((eventName) => { mainWindow.on("minimize", updateTrayMenu);
mainWindow.on(eventName as any, updateTrayMenu) mainWindow.on("maximize", updateTrayMenu);
});
} }
const updateTrayMenu = () => { const updateTrayMenu = () => {