Skip to content

Commit

Permalink
feat: show connection status in tray icon #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Aug 19, 2023
1 parent 8c6a6fc commit d84117e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
Binary file added assets/tray-offline.ico
Binary file not shown.
Binary file added assets/tray-offline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/trayTemplate-offline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/trayTemplate-offline@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 17 additions & 5 deletions src/electron.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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()
})
Expand Down

0 comments on commit d84117e

Please sign in to comment.