[sushi] Add a command line launcher



commit b65217aa5572e0d1d5681bcb01df070c46e90bc0
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Jul 16 18:37:05 2019 +0200

    Add a command line launcher
    
    Turn the symlink into an actual launcher that uses the ShowFile()
    D-Bus method to open a preview window for the passed-in file.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758253

 meson-post-install.py | 16 ---------------
 meson.build           |  2 --
 src/meson.build       | 17 ++++++++++++++--
 src/sushi.in          | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 69 insertions(+), 20 deletions(-)
---
diff --git a/meson.build b/meson.build
index d87840c..c6c91d3 100644
--- a/meson.build
+++ b/meson.build
@@ -40,5 +40,3 @@ add_project_arguments(
 subdir('data')
 subdir('po')
 subdir('src')
-
-meson.add_install_script('meson-post-install.py', libexecdir, bindir)
diff --git a/src/meson.build b/src/meson.build
index 5222ee8..36f6fe8 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -25,15 +25,28 @@ conf.set('PACKAGE_NAME', meson.project_name())
 conf.set('PACKAGE_VERSION', meson.project_version())
 conf.set('prefix', get_option('prefix'))
 conf.set('libdir', libdir)
+conf.set('pkgdatadir', pkgdatadir)
 
-sushi_bin = configure_file(
+nautilus_previewer_bin = configure_file(
   input: 'org.gnome.NautilusPreviewer.in',
   output: 'org.gnome.NautilusPreviewer',
   configuration: conf,
 )
 
 install_data(
-  sushi_bin,
+  nautilus_previewer_bin,
   install_mode: 'rwxr-xr-x',
   install_dir: libexecdir,
 )
+
+sushi_bin = configure_file(
+  input: 'sushi.in',
+  output: 'sushi',
+  configuration: conf,
+)
+
+install_data(
+  sushi_bin,
+  install_mode: 'rwxr-xr-x',
+  install_dir: bindir,
+)
diff --git a/src/sushi.in b/src/sushi.in
new file mode 100644
index 0000000..e7cab16
--- /dev/null
+++ b/src/sushi.in
@@ -0,0 +1,54 @@
+#!@GJS@
+
+const {Gio, GLib, GObject} = imports.gi;
+
+const ByteArray = imports.byteArray;
+const System = imports.system;
+
+GLib.set_prgname('sushi');
+
+function help() {
+    print(`Usage:
+    sushi FILE
+    Opens FILE in a NautilusPreviewer window.`);
+}
+
+if (ARGV.includes('-h') || ARGV.includes('--help')) {
+    help();
+    System.exit(0);
+}
+
+if (ARGV.length != 1) {
+    printerr('The launcher takes exactly one argument\n');
+    help();
+    System.exit(1);
+}
+
+let file = Gio.File.new_for_commandline_arg(ARGV[0]);
+if (!file.query_exists(null)) {
+    printerr(`The file at ${file.get_uri()} does not exist.`);
+    System.exit(1);
+}
+
+try {
+    let dataResource = Gio.Resource.load('@pkgdatadir@/org.gnome.NautilusPreviewer.data.gresource');
+    dataResource._register();
+} catch(e) {
+    logError(e, 'Unable to load data resource');
+    System.exit(1);
+}
+
+let bytes = Gio.resources_lookup_data(
+    '/org/gnome/NautilusPreviewer/org.gnome.NautilusPreviewer.xml', 0);
+let wrapper = Gio.DBusProxy.makeProxyWrapper(ByteArray.toString(bytes.toArray()));
+
+let proxy;
+try {
+    proxy = new wrapper(
+        Gio.DBus.session, 'org.gnome.NautilusPreviewer', '/org/gnome/NautilusPreviewer');
+} catch(e) {
+    logError(e, 'Unable to create DBus proxy for NautilusPreviewer');
+    System.exit(1);
+}
+
+proxy.ShowFileSync(file.get_uri(), 0, false);


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