Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[notifications] fix SnoreToast implementation #941

Merged
merged 2 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,60 +38,6 @@ jobs:
- name: Install dependencies
run: yarn --frozen-lockfile

######################
# Patch SnoreToast to fix App ID - see https://github.com/th-ch/youtube-music/issues/479#issuecomment-965473559
- name: SnoreToast - parameters
id: snoretoast-params
if: startsWith(matrix.os, 'windows')
shell: bash
run: |
echo "::set-output name=version::v0.8.0"
echo "::set-output name=path::./vendor/snoretoast"

- name: SnoreToast - cache
id: snoretoast-cache
uses: actions/cache@v2
if: startsWith(matrix.os, 'windows')
with:
path: ${{ steps.snoretoast-params.outputs.path }}
key: snoretoast-${{ steps.snoretoast-params.outputs.version }}

- name: SnoreToast - compile
if: |
startsWith(matrix.os, 'windows') &&
steps.snoretoast-cache.outputs.cache-hit != 'true'
shell: bash
run: |
SNORETOAST_TAG="${{ steps.snoretoast-params.outputs.version }}"
echo "Compiling SnoreToast $SNORETOAST_TAG"

git config --global user.email "th-ch@users.noreply.github.com"
git config --global user.name "YouTube Music"
git clone -c advice.detachedHead=false --branch $SNORETOAST_TAG --depth 1 https://github.com/KDE/snoretoast.git ${{ steps.snoretoast-params.outputs.path }}
cd ${{ steps.snoretoast-params.outputs.path }}

# Apply https://github.com/KDE/snoretoast/pull/15/commits/c5faeceaf36f4b9fb27e5269990b716a25ecbe43
# Patch generated with `git format-patch -1 c5faeceaf36f4b9fb27e5269990b716a25ecbe43`
git am < ../snoretoast-patch/0001-Fix-activation-not-writing-to-pipe.patch

# Compile for win32
cmake -A Win32 -B build32
cmake --build build32 --config Release

# Compile for x64
cmake -A x64 -B build64
cmake --build build64 --config Release

- name: SnoreToast - overwrite with custom build
if: startsWith(matrix.os, 'windows')
shell: bash
run: |
# Override SnoreToast with the patched versions
cp ${{ steps.snoretoast-params.outputs.path }}/build32/bin/Release/snoretoast.exe ./node_modules/node-notifier/vendor/snoreToast/snoretoast-x86.exe
cp ${{ steps.snoretoast-params.outputs.path }}/build64/bin/Release/snoretoast.exe ./node_modules/node-notifier/vendor/snoreToast/snoretoast-x64.exe
# End of SnoreToast patch
######################

- name: Test
uses: GabrielBB/xvfb-action@v1
env:
Expand Down
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ app.on("ready", () => {

// Register appID on windows
if (is.windows()) {
// Depends on SnoreToast version https://github.com/KDE/snoretoast/blob/master/CMakeLists.txt#L5
const toastActivatorClsid = "eb1fdd5b-8f70-4b5a-b230-998a2dc19303";

const appID = "com.github.th-ch.youtube-music";
app.setAppUserModelId(appID);
const appLocation = process.execPath;
Expand All @@ -372,7 +375,11 @@ app.on("ready", () => {
const shortcutPath = path.join(appData, "Microsoft", "Windows", "Start Menu", "Programs", "YouTube Music.lnk");
try { // check if shortcut is registered and valid
const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet
if (shortcutDetails.target !== appLocation || shortcutDetails.appUserModelId !== appID) {
if (
shortcutDetails.target !== appLocation ||
shortcutDetails.appUserModelId !== appID ||
shortcutDetails.toastActivatorClsid !== toastActivatorClsid
) {
throw "needUpdate";
}
} catch (error) { // if not valid -> Register shortcut
Expand All @@ -381,9 +388,10 @@ app.on("ready", () => {
error === "needUpdate" ? "update" : "create",
{
target: appLocation,
cwd: appLocation.slice(0, appLocation.lastIndexOf(path.sep)),
cwd: path.dirname(appLocation),
description: "YouTube Music Desktop App - including custom plugins",
appUserModelId: appID
appUserModelId: appID,
toastActivatorClsid
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/notifications/interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function sendToaster(songInfo) {
//download image and get path
let imgSrc = notificationImage(songInfo, true);
toDelete = {
appID: is.dev() ? undefined : "com.github.th-ch.youtube-music",
appID: "com.github.th-ch.youtube-music",
title: songInfo.title || "Playing",
message: songInfo.artist,
id: parseInt(Math.random() * 1000000, 10),
Expand Down

This file was deleted.