-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
How to send notifications #26
Comments
There is currently no builtin utility for sending notifications yet, you can use libnotify in the meantime |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I'm trying to use libnotify but no success, am I doing something wrong? Using libnotify in my ScreenRecorderService GObject. (But acting the same even in App main function) After sending notification Ags just stops responding to anything const ScreenRecorderService = GObject.registerClass(
{
Properties: {
...
},
},
class Recorder extends GObject.Object {
#recordings = GLib.getenv("HOME") + "/Videos/Screenrecords";
#screenshots = GLib.getenv("HOME") + "/Pictures/Screenshots";
#file = "";
#interval: AstalIO.Time | null = null;
#recording = false;
#timer = 0;
get recording() {
return this.#recording;
}
get timer() {
return this.#timer;
}
async start() {
...
}
async stop() {
if (!this.recording) return;
Notify.init("Ags");
try {
await execAsync(
`bash -c "$XDG_CONFIG_HOME/ags/bin/screenrecord-end.sh" & disown`,
);
this.#recording = false;
this.notify("recording");
if (this.#interval) this.#interval.cancel();
this.#timer = 0;
this.notify("timer");
try {
const notification = new Notify.Notification({
appName: "Ags",
summary: "Screenrecord",
body: this.#file,
iconName: icons.fallback.video,
});
notification.add_action(
"show_in_files",
"Show in Files",
() => exec(`bash -c xdg-open ${this.#recordings}`),
);
notification.add_action("view", "View", () =>
exec(`bash -c xdg-open ${this.#file}`),
);
if (!notification.show()) {
console.log("Error in notify");
}
} catch (e) {
console.log(e);
}
} catch (e) {
console.error("Error executing screenrecord-end script:", e);
} finally {
// Ensure Notify is uninitialized when done with it
Notify.uninit();
}
}
},
); |
libnotify is synchronous, so if you send from the same process that runs the daemon, it will block the eventblock currently the most simple way to send a notification imo is just execAsync+notify-send const res = await execAsync([
"notify-send", "Screenrecord", this.file,
"-a", "Screenrecord",
"-i", "video-x-generic-symbolic",
"--hint=string:image:video-x-generic-symbolic",
"-A", "file=Show in Files",
"-A", "view=View",
])
switch (res) {
case "file":
return execAsync([
GLib.getenv("FILE_MANAGER") || "xdg-open", Recording.DIR,
])
case "view":
return execAsync([
"xdg-open", this.file,
])
} |
Similar to
Utils.notify
The text was updated successfully, but these errors were encountered: