Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KK-Designs committed Jul 28, 2023
1 parent e80f6f8 commit a11e5bb
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
5 changes: 4 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ assets/
.github/

# ESlint config
.eslintrc.json
.eslintrc.json

# Packaged builds
builds/
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![weekly_downloads](https://img.shields.io/npm/dw/electron-taskbar-badge?color=blue&style=for-the-badge "Weekly Downloads")](https://www.npmjs.com/package/electron-taskbar-badge#:~:text=Weekly%20Downloads)
![downloads](https://badgen.net/npm/dt/electron-taskbar-badge "Downloads")
![downloads](https://img.shields.io/npm/dt/electron-taskbar-badge?style=for-the-badge&logo=npm&color=%23ca0000&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Felectron-taskbar-badge "Downloads")
[![issues](https://img.shields.io/github/issues/KK-Designs/KK-Designs/electron-taskbar-badge?style=for-the-badge "Issues")](https://github.com/KK-Designs/electron-taskbar-badge/issues)
Expand All @@ -16,13 +16,11 @@ An easy way for electron apps to add app badges to the taskbar to indicate notif

---

# Changelog (`v1.1.0`)
# Changelog (`v1.1.1`)

• Made the color 100% accurate, no longer an estimation! \
• Now compatible with automatically set colors! \
• Automatically changes color when the system accent color changes! \
• Added RGB support \
• Fixed typescript support \
• Fixed error when accent color theme was changed when the badge wasn't set \
• Added default accent color when it cannot be detected (restricted environments, etc.) \
• Detect non win32 environments \
• And more bug fixes

---
Expand Down
1 change: 1 addition & 0 deletions lib/cjs/badge_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = class BadgeGenerator {
}

generate(number, updateColor) {
if (!number) return;
let opts = JSON.stringify(this.style);
if (updateColor) {
opts = JSON.stringify(this.style);
Expand Down
10 changes: 8 additions & 2 deletions lib/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ if (!fs.existsSync('C:\\Program Files\\PowerShell\\7\\pwsh.exe')) {
*/
module.exports = class Badge {
constructor(win, opts = {}) {
if (process.platform == 'win32') console.warn('Only win32 environments are supported!');
this.win = win;
this.opts = opts;
const accentColor = getLightAccentColor(powershell);
Expand All @@ -62,7 +63,7 @@ module.exports = class Badge {
}

update(badgeNumber) {
if (typeof badgeNumber !== 'number') {
if (typeof badgeNumber !== 'number' && badgeNumber != null) {
throw new TypeError(`Invalid badgeNumber specified.\nExpected: number\nGot: ${typeof badgeNumber}`);
}
if (badgeNumber) {
Expand Down Expand Up @@ -106,7 +107,12 @@ module.exports = class Badge {
};

function getLightAccentColor(pwsh) {
const accentColorData = JSON.parse(require('child_process').execSync(`"${pwsh}" -NoProfile -Command "Get-ItemProperty -Path 'HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent' | Select-Object AccentPalette | ConvertTo-Json"`).toString()).AccentPalette;
let accentColorData;
try {
accentColorData = JSON.parse(require('child_process').execSync(`"${pwsh}" -NoProfile -Command "Get-ItemProperty -Path 'HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent' | Select-Object AccentPalette | ConvertTo-Json"`).toString()).AccentPalette;
} catch (error) {
return '#4cc2ff';
}
const accentColorLight = Array.from({ length: Math.ceil(accentColorData.length / 4) }, (_, i) => accentColorData.slice(i * 4, i * 4 + 4)).map(arr => arr.slice(0, arr.length - 1))[1];

return rgbToHex.apply(null, [...accentColorLight]);
Expand Down
1 change: 1 addition & 0 deletions lib/esm/badge_generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class BadgeGenerator {
}

generate(number, updateColor) {
if (!number) return;
let opts = JSON.stringify(this.style);
if (updateColor) {
opts = JSON.stringify(this.style);
Expand Down
11 changes: 8 additions & 3 deletions lib/esm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ if (!fs.existsSync('C:\\Program Files\\PowerShell\\7\\pwsh.exe')) {
*/
export default class Badge {
constructor(win, opts = {}) {
if (process.platform == 'win32') console.warn('Only win32 environments are supported!');
this.win = win;
this.opts = opts;
const accentColor = getLightAccentColor(powershell);
Expand All @@ -62,7 +63,7 @@ export default class Badge {
}

update(badgeNumber) {
if (typeof badgeNumber !== 'number') {
if (typeof badgeNumber !== 'number' && badgeNumber != null) {
throw new TypeError(`Invalid badgeNumber specified.\nExpected: number\nGot: ${typeof badgeNumber}`);
}
if (badgeNumber) {
Expand Down Expand Up @@ -106,12 +107,16 @@ export default class Badge {
}

function getLightAccentColor(pwsh) {
const accentColorData = JSON.parse(require('child_process').execSync(`"${pwsh}" -NoProfile -Command "Get-ItemProperty -Path 'HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent' | Select-Object AccentPalette | ConvertTo-Json"`).toString()).AccentPalette;
let accentColorData;
try {
accentColorData = JSON.parse(require('child_process').execSync(`"${pwsh}" -NoProfile -Command "Get-ItemProperty -Path 'HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Accent' | Select-Object AccentPalette | ConvertTo-Json"`).toString()).AccentPalette;
} catch (error) {
return '#4cc2ff';
}
const accentColorLight = Array.from({ length: Math.ceil(accentColorData.length / 4) }, (_, i) => accentColorData.slice(i * 4, i * 4 + 4)).map(arr => arr.slice(0, arr.length - 1))[1];

return rgbToHex.apply(null, [...accentColorLight]);
}

function rgbToHex(r, g, b) {
const red = parseInt(r);
const green = parseInt(g);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-taskbar-badge",
"version": "1.1.0",
"version": "1.1.1",
"description": "An easy way for electron apps to add app badges to the taskbar to indicate notifications and other countable things, with maximum compatibility and customizability.",
"type": "commonjs",
"main": "./lib/cjs/index.js",
Expand All @@ -23,7 +23,7 @@
},
"homepage": "https://github.com/KK-Designs/electron-taskbar-badge#readme",
"author": "NotBacon",
"license": "CC0-1.0",
"license": "GPL-2.0",
"repository": {
"type": "git",
"url": "https://github.com/KK-Designs/electron-taskbar-badge"
Expand Down

0 comments on commit a11e5bb

Please sign in to comment.