Skip to content

Commit

Permalink
Add notification for play and open folder (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryonakano authored Apr 13, 2024
1 parent 7fd78fc commit 28f557a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/reco.desktop.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Exec=com.github.ryonakano.reco
Icon=com.github.ryonakano.reco
Terminal=false
Type=Application
X-GNOME-UsesNotifications=true
Keywords=Record;Audio;Sound;Voice;
22 changes: 22 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ public class Application : Gtk.Application {

public static Settings settings { get; private set; }

/**
* Action names and their callbacks.
*/
private const ActionEntry[] ACTION_ENTRIES = {
{ "open", on_open_activate, "s" },
};

private MainWindow window;
private unowned Manager.StyleManager style_manager;

Expand Down Expand Up @@ -127,6 +134,19 @@ public class Application : Gtk.Application {
add_action (style_action);
}

private void on_open_activate (SimpleAction action, Variant? parameter) requires (parameter != null) {
unowned string path = parameter.get_string ();
var launcher = new Gtk.FileLauncher (File.new_for_path (path));

launcher.launch.begin (window, null, (obj, res) => {
try {
launcher.launch.end (res);
} catch (Error err) {
warning ("on_open_activate: failed to Gtk.FileLauncher.launch: %s", err.message);
}
});
}

protected override void startup () {
base.startup ();

Expand All @@ -150,6 +170,8 @@ public class Application : Gtk.Application {
icon_theme.add_resource_path ("/com/github/ryonakano/reco");

setup_style ();

add_action_entries (ACTION_ENTRIES, this);
}

protected override void activate () {
Expand Down
13 changes: 13 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ public class MainWindow : Gtk.ApplicationWindow {

if (is_success) {
welcome_view.show_success_button ();

var notification = new Notification (_("Saved recording"));
// The app that handles actions would be already destroyed when the user activates the notification,
// so do not offer actions if it's decided to be destroyed
if (destroy_on_save) {
notification.set_body (_("Recording saved successfully."));
} else {
notification.set_body (_("Click here to play."));
notification.set_default_action_and_target_value ("app.open", new Variant.string (save_path.get_path ()));
notification.add_button_with_target_value (_("Open folder"), "app.open", new Variant.string (save_path.get_parent ().get_path ()));
}

application.send_notification ("com.github.ryonakano.reco", notification);
}

if (destroy_on_save) {
Expand Down

0 comments on commit 28f557a

Please sign in to comment.