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

[Guide] How to use SnoreToast with both appID and actions #424

Open
Araxeus opened this issue Jan 7, 2023 · 2 comments
Open

[Guide] How to use SnoreToast with both appID and actions #424

Araxeus opened this issue Jan 7, 2023 · 2 comments

Comments

@Araxeus
Copy link
Contributor

Araxeus commented Jan 7, 2023

Here is an example from youtube-music :

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

		const appID = "com.github.th-ch.youtube-music";
		app.setAppUserModelId(appID);

		const appLocation = process.execPath;
		const appData = app.getPath("appData");

		// continue if not in dev mode / running portable app
		if (!is.dev() && !appLocation.startsWith(path.join(appData, "..", "Local", "Temp"))) {
			// shortcutPath can be anywhere inside AppData\Roaming\Microsoft\Windows\Start Menu\Programs\
			const shortcutPath = path.join(appData, "Microsoft", "Windows", "Start Menu", "Programs", "YouTube Music.lnk");
			// check if shortcut doesn't exist -> create it, if it exist and invalid -> update it
			try { 
				const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throws error if it doesn't exist yet
				// validate shortcutDetails
				if (
					shortcutDetails.target !== appLocation ||
					shortcutDetails.appUserModelId !== appID ||
					shortcutDetails.toastActivatorClsid !== toastActivatorClsid
				) {
					throw "needUpdate";
				}
				// if the execution got to this line, the shortcut exists and is valid
			} catch (error) { // if not valid -> Register shortcut
				electron.shell.writeShortcutLink(
					shortcutPath,
					error === "needUpdate" ? "update" : "create",
					{
						target: appLocation,
						cwd: path.dirname(appLocation),
						description: "YouTube Music Desktop App - including custom plugins",
						appUserModelId: appID,
						toastActivatorClsid
					}
				);
			}
		}
	}

this method currently requires Electron but you could get packages from npm / make similar functions yourself

@Araxeus
Copy link
Contributor Author

Araxeus commented Jan 7, 2023

@mikaelbr

  • There should be some official way to know the version of SnoreToast in /vendors,
  • Maybe this post or the gist of it should be mentioned in the Readme

@mikaelbr
Copy link
Owner

mikaelbr commented Jan 9, 2023

Thanks for the guide 🙌 ! Added link to this post here 027f0d6.
If you have any suggestion how to have an official way to know the version, I'm happy to hear it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants