UIUX: Add Custom Specter Dock Icon (#2215)

* add custom icon

* remove unused icons for macos and linux

* fix tray icon for macos + rename to only Specter

* add menu items that respond to theme

* workaround for version parsing issue

* forgot prefix v

* Change tray icon on Mac if appearance changes

---------

Co-authored-by: moneymanolis <moneymanolis@protonmail.com>
Co-authored-by: Kim Neunert <k9ert@gmx.de>
This commit is contained in:
OTK 2023-02-16 04:44:15 -05:00 committed by GitHub
parent 3621a256e5
commit 66cf35fdd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 64 additions and 11 deletions

View file

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, Menu, Tray, screen, shell, dialog, ipcMain } = require('electron')
const { app, nativeTheme, nativeImage, BrowserWindow, Menu, Tray, screen, shell, dialog, ipcMain } = require('electron')
const path = require('path')
const fs = require('fs')
@ -19,6 +19,9 @@ const getDownloadLocation = downloadloc.getDownloadLocation
const appName = downloadloc.appName()
const appNameLower = appName.toLowerCase()
// Helper
const isMac = process.platform === 'darwin'
// Logging
const {transports, format, createLogger } = require('winston')
const combinedLog = new transports.File({ filename: helpers.specterAppLogPath });
@ -42,7 +45,6 @@ const winstonOptions = {
}
const logger = createLogger(winstonOptions)
let appSettings = getAppSettings()
let dimensions = { widIth: 1500, height: 1000 };
@ -50,6 +52,15 @@ let dimensions = { widIth: 1500, height: 1000 };
const contextMenu = require('electron-context-menu');
const { options } = require('request')
const icon = nativeImage.createFromPath(
app.getAppPath() + "/assets/icon.png"
);
// Set the dock icon (MacOS only)
if (isMac) {
app.dock.setIcon(icon)
}
contextMenu({
menu: (actions) => [
{
@ -166,16 +177,45 @@ function createWindow (specterURL) {
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
// Start the tray icon
logger.info("Framework Ready! Starting tray Icon ...");
tray = new Tray(path.join(__dirname, '/assets/bitcoin-logo.svg'))
// Create the tray icon
logger.info("Framework ready! Starting tray icon ...");
if (isMac) {
const trayIconPath = nativeTheme.shouldUseDarkColors
? "/assets/menu_icon_dark.png"
: "/assets/menu_icon_light.png";
const createTrayIcon = (trayIconPath) => {
let trayIcon = nativeImage.createFromPath(
app.getAppPath() + trayIconPath
);
// Resize
trayIcon = trayIcon.resize({ width: 22, height: 22 });
return trayIcon
}
const trayIcon = createTrayIcon(trayIconPath)
tray = new Tray(trayIcon);
// Change the tray icon if appearance is changed in Mac settings
const updateTrayIcon = () => {
logger.info('Updating tray icon ...')
const trayIconPath = nativeTheme.shouldUseDarkColors
? "/assets/menu_icon_dark.png"
: "/assets/menu_icon_light.png";
const newTrayIcon = createTrayIcon(trayIconPath)
tray.setImage(newTrayIcon);
}
nativeTheme.on('updated', updateTrayIcon)
}
else {
tray = new Tray(icon)
}
trayMenu = [
{ label: 'Launching Specter...', enabled: false },
{ label: 'Show Specter Desktop', click() { mainWindow.show() }},
{ label: 'Launching Specter ...', enabled: false },
{ label: 'Show Specter', click() { mainWindow.show() }},
{ label: 'Preferences', click() { openPreferences() }},
{ label: 'Quit', click() { quitSpecterd(); app.quit() } },
]
tray.setToolTip('This is my application.')
tray.setToolTip('Specter')
tray.setContextMenu(Menu.buildFromTemplate(trayMenu))
dimensions = screen.getPrimaryDisplay().size;
@ -230,7 +270,7 @@ function initMainWindow() {
mainWindow = new BrowserWindow({
width: parseInt(dimensions.width * 0.8),
height: parseInt(dimensions.height * 0.8),
icon: path.join(__dirname, '/assets/bitcoin-logo.svg'),
icon: path.join(__dirname, 'assets/icon.png'),
webPreferences
})
@ -338,7 +378,7 @@ function startSpecterd(specterdPath) {
}
let appSettings = getAppSettings()
let hwiBridgeMode = appSettings.mode == 'hwibridge'
updatingLoaderMsg('Launching Specter Desktop...')
updatingLoaderMsg('Launching Specter ...')
updateSpecterdStatus('Launching Specter...')
let specterdArgs = ["server"]
specterdArgs.push("--no-filelog")
@ -543,7 +583,7 @@ function openErrorLog() {
}
function showError(error) {
updatingLoaderMsg('Specter Desktop encounter an error:<br>' + error.toString())
updatingLoaderMsg('Specter encounter an error:<br>' + error.toString())
}
process.on('unhandledRejection', error => {

Binary file not shown.

View file

@ -219,6 +219,19 @@ def _parse_version(version: str) -> dict:
but ignores the stuff behind the postfix (which is good enough for our use cases)
see also: https://github.com/pypa/setuptools_scm/#default-versioning-scheme
"""
if version.startswith("0.1.dev") or version.startswith("v0.1.dev"):
# setuptools_scm creates weird versions if you're somewhere where no tags are available
# on the .git
# This is the case in testing-scenarios. I couldn't figure out how to convince
# setuptools_scm to at least return 0.0.1dev or something like that.
# Anyway, let's return something, it's not relevant anyway.
# And the alternative would be yet another dependency like e.g. packaging
return {
"major": 0,
"minor": 1,
"patch": 0,
"postfix": "",
}
try:
if version[0] == "v":