diff --git a/assets/tray-offline.ico b/assets/tray-offline.ico new file mode 100644 index 0000000..cbea6f4 Binary files /dev/null and b/assets/tray-offline.ico differ diff --git a/assets/tray-offline.png b/assets/tray-offline.png new file mode 100644 index 0000000..1ffe73b Binary files /dev/null and b/assets/tray-offline.png differ diff --git a/assets/trayTemplate-offline.png b/assets/trayTemplate-offline.png new file mode 100644 index 0000000..a335434 Binary files /dev/null and b/assets/trayTemplate-offline.png differ diff --git a/assets/trayTemplate-offline@2x.png b/assets/trayTemplate-offline@2x.png new file mode 100644 index 0000000..b27e139 Binary files /dev/null and b/assets/trayTemplate-offline@2x.png differ diff --git a/src/electron.ts b/src/electron.ts index bf642b4..16a72bc 100644 --- a/src/electron.ts +++ b/src/electron.ts @@ -1,5 +1,5 @@ // eslint-disable-next-line node/no-unpublished-import -import { app, Tray, Menu, MenuItem, dialog } from 'electron' +import { app, Tray, Menu, MenuItem, dialog, nativeImage } from 'electron' import * as path from 'path' // eslint-disable-next-line node/no-unpublished-import import * as electronStore from 'electron-store' @@ -122,17 +122,29 @@ app.whenReady() tryConnect() restartRestApi() - let trayImage = path.join(__dirname, '../assets', 'tray.png') + let trayImagePath = path.join(__dirname, '../assets', 'tray.png') + let trayImageOfflinePath = path.join(__dirname, '../assets', 'tray-offline.png') switch (process.platform) { case 'darwin': - trayImage = path.join(__dirname, '../assets', 'trayTemplate.png') + trayImagePath = path.join(__dirname, '../assets', 'trayTemplate.png') + trayImageOfflinePath = path.join(__dirname, '../assets', 'trayTemplate-offline.png') break case 'win32': - trayImage = path.join(__dirname, '../assets', 'tray.ico') + trayImagePath = path.join(__dirname, '../assets', 'tray.ico') + trayImageOfflinePath = path.join(__dirname, '../assets', 'tray-offline.ico') break } + const trayImage = nativeImage.createFromPath(trayImagePath) + const trayImageOffline = nativeImage.createFromPath(trayImageOfflinePath) - tray = new Tray(trayImage) + tray = new Tray(trayImageOffline) + + client.on('connected', () => { + tray?.setImage(trayImage) + }) + client.on('disconnected', () => { + tray?.setImage(trayImageOffline) + }) updateTray() })