diff --git a/contributing.md b/contributing.md index 43d68d85d..8fad81e33 100644 --- a/contributing.md +++ b/contributing.md @@ -8,7 +8,7 @@ There is an issue template for you to follow. Please provide as much information Thank you in advance for your help. ### When you open a pull request -There is a pull request template for your to follow. Please fill in the template before submitting your code. Your pull request will be reviewed faster if we know exactly what it does. +There is a pull request template for you to follow. Please fill in the template before submitting your code. Your pull request will be reviewed faster if we know exactly what it does. Make sure that you have: - Checked [`code_style.md`](docs/code_style.md) for information on code style diff --git a/lib/main-app.js b/lib/main-app.js index cc3439bc1..9c8cc624b 100644 --- a/lib/main-app.js +++ b/lib/main-app.js @@ -118,6 +118,12 @@ app.on('ready', function() { mainWindow.setMenu(menu) } + // Create tray icon for Linux (fixes issue #377) + if (process.platform === 'linux') { + const mainTray = require('./main-tray') + mainTray.createTray(mainWindow) + } + // Check update every day setInterval(function() { if (isPackaged) checkUpdate() diff --git a/lib/main-tray.js b/lib/main-tray.js new file mode 100644 index 000000000..8a5cabaab --- /dev/null +++ b/lib/main-tray.js @@ -0,0 +1,102 @@ +const { Tray, Menu, app, nativeImage } = require('electron') +const path = require('path') + +let tray = null + +/** + * Create tray icon for Linux + * This functionality was missing in the original codebase + * Issue: https://github.com/BoostIO/BoostNote-Legacy/issues/377 + */ +function createTray(mainWindow) { + // Only create tray on Linux + if (process.platform !== 'linux') { + return null + } + + // Get the appropriate tray icon + const iconPath = path.join(__dirname, '../resources/tray-icon.png') + + // Create native image for tray icon + let icon + try { + icon = nativeImage.createFromPath(iconPath) + + // Try @2x version for HiDPI displays + if (icon.isEmpty()) { + const iconPath2x = path.join(__dirname, '../resources/tray-icon@2x.png') + icon = nativeImage.createFromPath(iconPath2x) + } + } catch (e) { + console.error('Failed to load tray icon:', e) + return null + } + + if (icon.isEmpty()) { + console.warn('Tray icon is empty, skipping tray creation') + return null + } + + // Create tray + tray = new Tray(icon) + + // Set tooltip + tray.setToolTip('Boostnote') + + // Context menu + const contextMenu = Menu.buildFromTemplate([ + { + label: 'Show Boostnote', + click: () => { + if (mainWindow) { + mainWindow.show() + mainWindow.focus() + } + } + }, + { + label: 'Hide Boostnote', + click: () => { + if (mainWindow) { + mainWindow.hide() + } + } + }, + { type: 'separator' }, + { + label: 'Quit', + click: () => { + app.quit() + } + } + ]) + + tray.setContextMenu(contextMenu) + + // Handle click - show/hide window + tray.on('click', () => { + if (mainWindow) { + if (mainWindow.isVisible()) { + mainWindow.hide() + } else { + mainWindow.show() + mainWindow.focus() + } + } + }) + + // Handle double-click - show window + tray.on('double-click', () => { + if (mainWindow) { + mainWindow.show() + mainWindow.focus() + } + }) + + return tray +} + +module.exports = { + createTray, + getTray: () => tray +} \ No newline at end of file