Skip to content

Commit

Permalink
fix(tray): Add dark theme icon for Mac
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <[email protected]>
  • Loading branch information
ShGKme authored and nickvergessen committed Jul 25, 2023
1 parent 8a8d993 commit b125e9d
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 11 deletions.
Binary file added img/icons/icon-tray-mac-dark.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 img/icons/[email protected]
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 img/icons/icon-tray-mac-light.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 img/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions img/talk-icon-plain-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
23 changes: 16 additions & 7 deletions scripts/generate-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const icongen = require('icon-gen')
async function generateIcons() {
const originalPath = path.join(__dirname, '../img/talk-icon-rounded.svg')
const originalMacPath = path.join(__dirname, '../img/talk-icon-mac-shadow.svg')
const originalMacTrayPath = path.join(__dirname, '../img/talk-icon-plain.svg')
const originalMacTrayLightPath = path.join(__dirname, '../img/talk-icon-plain-light.svg')
const originalMacTrayDarkPath = path.join(__dirname, '../img/talk-icon-plain-dark.svg')
const outputPath = path.join(__dirname, '../img/icons')

await icongen(originalPath, outputPath, {
Expand All @@ -56,10 +57,16 @@ async function generateIcons() {
},
})

await icongen(originalMacTrayPath, outputPath, {
// Mac
// Tray icon - Mac
await icongen(originalMacTrayLightPath, outputPath, {
favicon: {
name: 'icon-tray-mac-light',
pngSizes: [16, 32],
},
})
await icongen(originalMacTrayDarkPath, outputPath, {
favicon: {
name: 'icon-tray-mac',
name: 'icon-tray-mac-dark',
pngSizes: [16, 32],
},
})
Expand All @@ -72,9 +79,11 @@ async function generateIcons() {
// Remove unused favicon
await fs.unlink(path.join(outputPath, 'favicon.ico'))

// Rename icon-tray-mac16.png -> icon-tray-mac.png, icon-tray-mac32.png -> [email protected]
await fs.rename(path.join(outputPath, 'icon-tray-mac16.png'), path.join(outputPath, 'icon-tray-mac.png'))
await fs.rename(path.join(outputPath, 'icon-tray-mac32.png'), path.join(outputPath, '[email protected]'))
// Rename icon-tray-mac-(light|dark)16.png -> icon-tray-mac-(light|dark).png, icon-tray-mac-(light|dark)32.png -> icon-tray-mac-(light|dark)@2x.png
await fs.rename(path.join(outputPath, 'icon-tray-mac-light16.png'), path.join(outputPath, 'icon-tray-mac-light.png'))
await fs.rename(path.join(outputPath, 'icon-tray-mac-light32.png'), path.join(outputPath, '[email protected]'))
await fs.rename(path.join(outputPath, 'icon-tray-mac-dark16.png'), path.join(outputPath, 'icon-tray-mac-dark.png'))
await fs.rename(path.join(outputPath, 'icon-tray-mac-dark32.png'), path.join(outputPath, '[email protected]'))
}

generateIcons()
Expand Down
17 changes: 13 additions & 4 deletions src/shared/icons.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const { nativeTheme } = require('electron')

const icons = {
tray: {
darwin: require('../../img/icons/icon-tray-mac.png'),
darwin: {
light: require('../../img/icons/icon-tray-mac-light.png'),
dark: require('../../img/icons/icon-tray-mac-dark.png'),
},

// This property is not used, but import is required to add the icon to the bundle.
// It will be used by electron internally
darwin_x2: require('../../img/icons/[email protected]'),
darwin_x2: {
light: require('../../img/icons/[email protected]'),
dark: require('../../img/icons/[email protected]'),
},

win32: require('../../img/icons/icon.ico'),

Expand All @@ -37,11 +45,12 @@ const icons = {
* Get tray icon for the given platform
*
* @param {'darwin'|'win32'|'cygwin'|string} [platform] platform otherwise current process.platform is used
* @param {'light'|'dark'} [theme] theme for the darwin platform
*/
function getTrayIcon(platform) {
function getTrayIcon(platform, theme) {
switch (platform ?? process.platform) {
case 'darwin':
return icons.tray.darwin
return nativeTheme.shouldUseDarkColors || theme === 'dark' ? icons.tray.darwin.dark : icons.tray.darwin.light
case 'win32':
return icons.tray.win32
default:
Expand Down

0 comments on commit b125e9d

Please sign in to comment.