-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update how emojis are handled * Use template icon to support light/dark theme for macOS * Removed npm-emoji as it didn't support low battery * Handle light/dark theme on Windows
- Loading branch information
Showing
10 changed files
with
94 additions
and
18 deletions.
There are no files selected for viewing
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import path = require('path'); | ||
|
||
import { Tray, Menu, MenuItem } from 'electron'; | ||
import SimpleHeadphone from 'arctis-usb-finder/dist/interfaces/simple_headphone'; | ||
import Host from 'arctis-usb-finder/dist/utils/host'; | ||
|
||
import exportView from './headphone_view'; | ||
import debugMenu from './menu_items/debug'; | ||
import helpMenuItem from './menu_items/help'; | ||
import quitMenuItem from './menu_items/quit'; | ||
import HeadphoneManager from './headphone_manager'; | ||
import HandleThemes from './windows/handle_themes'; | ||
import iconPicker from './windows/icon_picker'; | ||
|
||
let mainTray: any; | ||
let mainTray: Tray; | ||
const headphoneManager = new HeadphoneManager(); | ||
|
||
const buildTrayMenu = (force: boolean = false, debug: boolean = false) => { | ||
|
@@ -31,9 +36,24 @@ const buildTrayMenu = (force: boolean = false, debug: boolean = false) => { | |
mainTray.setContextMenu(contextMenu); | ||
}; | ||
|
||
const createTray = (path: any) => { | ||
const icon = (): string => { | ||
const assetsDirectory = path.join(__dirname, '../assets'); | ||
mainTray = new Tray(path.join(assetsDirectory, 'headphones.png')); | ||
|
||
if (Host.isMac()) { | ||
return path.join(assetsDirectory, 'headphonesTemplate.png'); | ||
} else { | ||
return path.join(assetsDirectory, '[email protected]'); | ||
} | ||
}; | ||
|
||
const createTray = async () => { | ||
if (Host.isWin()) { | ||
const handleThemes = new HandleThemes(); | ||
mainTray = new Tray(iconPicker(await handleThemes.isUsedSystemLightTheme())); | ||
handleThemes.tray = mainTray; | ||
} else { | ||
mainTray = new Tray(icon()); | ||
} | ||
|
||
const contextMenu = Menu.buildFromTemplate([ | ||
{ label: 'No Headphones USB devices plugged in', type: 'normal' }, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Tray, nativeTheme } from 'electron'; | ||
import Registry = require('winreg'); | ||
import iconPicker from './icon_picker'; | ||
|
||
export default class HandleThemes { | ||
tray: Tray; | ||
|
||
constructor() { | ||
nativeTheme.on('updated', () => this.handleThemeChange()); | ||
} | ||
|
||
async isUsedSystemLightTheme(): Promise<boolean> { | ||
const reg = new Registry({ | ||
hive: Registry.HKCU, | ||
key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize', | ||
}); | ||
return new Promise((resolve) => | ||
reg.get('SystemUsesLightTheme', (err: any, item: { value: string }) => { | ||
if (!err) return resolve(item.value === '0x1'); | ||
resolve(false); | ||
}) | ||
); | ||
} | ||
|
||
async handleThemeChange() { | ||
const isLightTheme = await this.isUsedSystemLightTheme(); | ||
console.log('in updated', isLightTheme); | ||
|
||
this.tray.setImage(iconPicker(isLightTheme)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import path = require('path'); | ||
|
||
const iconPicker = (lightTheme: boolean) => { | ||
const assetsDirectory = path.join(__dirname, '../../assets'); | ||
|
||
console.log('icon', lightTheme); | ||
if (lightTheme) { | ||
return path.join(assetsDirectory, 'icon.ico'); | ||
} else { | ||
return path.join(assetsDirectory, 'icon_white.ico'); | ||
} | ||
}; | ||
|
||
export default iconPicker; |