[gnome-shell/screenshot-ui-gsd-binds: 7/10] screenshot-ui: Add screencast done notification




commit e588c0b5589c4c91626739eb38ca654f5a6780c5
Author: Ivan Molodetskikh <yalterz gmail com>
Date:   Fri Dec 17 09:40:57 2021 +0300

    screenshot-ui: Add screencast done notification

 js/ui/screenshot.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js
index a3acb26a38..c17642b8a8 100644
--- a/js/ui/screenshot.js
+++ b/js/ui/screenshot.js
@@ -1885,7 +1885,7 @@ class ScreenshotUI extends St.Widget {
                 /* xgettext:no-c-format */
                 _('Screencast from %d %t.webm'),
                 { 'draw-cursor': new GLib.Variant('b', drawCursor) },
-                ([success, _filename], error) => {
+                ([success, path], error) => {
                     if (error !== null) {
                         this._screencastAreaIndicator.hide();
                         this._screencastInProgress = false;
@@ -1897,7 +1897,10 @@ class ScreenshotUI extends St.Widget {
                         this._screencastAreaIndicator.hide();
                         this._screencastInProgress = false;
                         log('Error starting screencast');
+                        return;
                     }
+
+                    this._screencastPath = path;
                 }
             );
         };
@@ -1942,8 +1945,51 @@ class ScreenshotUI extends St.Widget {
                 return;
             }
 
-            if (!success)
+            if (!success) {
                 log('Error stopping screencast');
+                return;
+            }
+
+            // Show a notification.
+            const file = Gio.file_new_for_path(this._screencastPath);
+
+            const source = new MessageTray.Source(
+                // Translators: notification source name.
+                _('Screenshot'),
+                'applets-screenshooter'
+            );
+            const notification = new MessageTray.Notification(
+                source,
+                // Translators: notification title.
+                _('Screencast recorded'),
+                // Translators: notification body when a screencast was recorded.
+                _('Click here to view the video.')
+            );
+            // Translators: button on the screencast notification.
+            notification.addAction(_('Show in Files'), () => {
+                const app =
+                    Gio.app_info_get_default_for_type('inode/directory', false);
+
+                if (app === null) {
+                    // It may be null e.g. in a toolbox without nautilus.
+                    log('Error showing in files: no default app set for inode/directory');
+                    return;
+                }
+
+                app.launch([file], global.create_app_launch_context(0, -1));
+            });
+            notification.connect('activated', () => {
+                try {
+                    Gio.app_info_launch_default_for_uri(
+                        file.get_uri(), global.create_app_launch_context(0, -1));
+                } catch (err) {
+                    logError(err, 'Error opening screencast');
+                }
+            });
+            notification.setTransient(true);
+
+            Main.messageTray.add(source);
+            source.showNotification(notification);
         });
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]