[sushi/wip/cosimoc/no-clutter: 60/66] Port to use package.js



commit f5570d1edd621f3694fe385447cb984fc5f53608
Author: Cosimo Cecchi <cosimo endlessm com>
Date:   Fri Jun 7 13:17:00 2019 -0700

    Port to use package.js
    
    Let's finally remove the C wrapper and port the app to use the
    package.js framework and simplify greatly the way the app is installed
    and runs.
    
    As part of this, we also move the JS code to a gresource and change
    some of the installation paths to account for the structure required
    by package.js.
    In practice, this means changing the package name to
    org.gnome.NautilusPreviewer, but we keep the original sushi binary
    name installed in ${bindir} for compatibility.

 data/meson.build                                   |  5 +-
 data/org.gnome.NautilusPreviewer.service.in        |  2 +-
 meson-post-install.py                              | 16 +++++
 meson.build                                        |  8 ++-
 src/js/util/path.js.in                             | 26 -------
 src/libsushi/meson.build                           |  6 +-
 src/main.c                                         | 80 ----------------------
 src/meson.build                                    | 74 ++++++--------------
 ...org.gnome.NautilusPreviewer.data.gresource.xml} |  2 +-
 src/org.gnome.NautilusPreviewer.in                 |  9 +++
 src/org.gnome.NautilusPreviewer.src.gresource.xml  | 21 ++++++
 src/sushi.in                                       | 20 ------
 src/{js => }/ui/application.js                     |  2 +-
 src/{js => }/ui/fallbackRenderer.js                |  2 -
 src/{js => }/ui/main.js                            | 34 +++++----
 src/{js => }/ui/mainWindow.js                      |  0
 src/{js => }/ui/mimeHandler.js                     |  0
 src/{js => }/ui/renderer.js                        |  0
 src/{js => }/ui/utils.js                           |  0
 src/{js => }/util/constants.js                     |  0
 src/{js => }/util/totemMimeTypes.js                |  0
 src/{js => }/viewers/audio.js                      |  3 -
 src/{js => }/viewers/evince.js                     |  3 -
 src/{js => }/viewers/font.js                       |  0
 src/{js => }/viewers/gst.js                        |  0
 src/{js => }/viewers/html.js                       |  0
 src/{js => }/viewers/image.js                      |  4 --
 src/{js => }/viewers/text.js                       |  2 -
 28 files changed, 98 insertions(+), 221 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index 1c6d588..4c917c0 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -1,9 +1,6 @@
 dbus_conf = configuration_data()
 
-dbus_conf.set(
-  'bindir',
-  bindir,
-)
+dbus_conf.set('libexecdir', libexecdir)
 
 configure_file(
   input: 'org.gnome.NautilusPreviewer.service.in',
diff --git a/data/org.gnome.NautilusPreviewer.service.in b/data/org.gnome.NautilusPreviewer.service.in
index 83ca1a3..33bb128 100644
--- a/data/org.gnome.NautilusPreviewer.service.in
+++ b/data/org.gnome.NautilusPreviewer.service.in
@@ -1,3 +1,3 @@
 [D-BUS Service]
 Name=org.gnome.NautilusPreviewer
-Exec=@bindir@/sushi
\ No newline at end of file
+Exec=@libexecdir@/org.gnome.NautilusPreviewer
diff --git a/meson-post-install.py b/meson-post-install.py
new file mode 100644
index 0000000..379b086
--- /dev/null
+++ b/meson-post-install.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+
+import os
+import subprocess
+import sys
+
+destdir = os.environ.get('DESTDIR', '')
+libexecdir = sys.argv[1]
+bindir = sys.argv[2]
+
+bindir = os.path.join(destdir, bindir)
+os.makedirs(bindir, exist_ok=True)
+
+src = os.path.join(libexecdir, 'org.gnome.NautilusPreviewer')
+dest = os.path.join(bindir, 'sushi')
+subprocess.call(['ln', '-s', '-f', src, dest])
diff --git a/meson.build b/meson.build
index 7007bc1..6440c06 100644
--- a/meson.build
+++ b/meson.build
@@ -1,5 +1,5 @@
 project(
-  'sushi',
+  'org.gnome.NautilusPreviewer',
   'c',
   version: '3.32.0',
   meson_version: '>=0.42.0'
@@ -29,9 +29,11 @@ bindir = join_paths(get_option('prefix'), get_option('bindir'))
 datadir = join_paths(get_option('prefix'), get_option('datadir'))
 libdir = join_paths(get_option('prefix'), get_option('libdir'))
 libexecdir = join_paths(get_option('prefix'), get_option('libexecdir'))
+pkgdatadir = join_paths(datadir, meson.project_name())
+pkglibdir = join_paths(libdir, meson.project_name())
+gjs = find_program('gjs', 'gjs-console')
 
 add_project_arguments(
-  '-DSUSHI_PKGDATADIR="' + join_paths(datadir, 'sushi') + '"',
   '-DGETTEXT_PACKAGE="' + meson.project_name() + '"',
   language: 'c',
 )
@@ -39,3 +41,5 @@ add_project_arguments(
 subdir('data')
 subdir('po')
 subdir('src')
+
+meson.add_install_script('meson-post-install.py', libexecdir, bindir)
diff --git a/src/libsushi/meson.build b/src/libsushi/meson.build
index bfa6a7e..367fb50 100644
--- a/src/libsushi/meson.build
+++ b/src/libsushi/meson.build
@@ -45,7 +45,7 @@ libsushi = shared_library(
     libsushi_resource
   ],
   install: true,
-  install_dir: join_paths(libdir, 'sushi')
+  install_dir: pkglibdir
 )
 
 # We use that later on to link the sushi-start executable against libsushi
@@ -74,6 +74,6 @@ gnome.generate_gir(
     'EvinceDocument-3.0',
   ],
   install: true,
-  install_dir_gir: join_paths(datadir, 'sushi', 'gir-1.0'),
-  install_dir_typelib: join_paths(libdir, 'sushi', 'girepository-1.0'),
+  install_dir_gir: join_paths(pkgdatadir, 'gir-1.0'),
+  install_dir_typelib: join_paths(pkglibdir, 'girepository-1.0'),
 )
diff --git a/src/meson.build b/src/meson.build
index 10a25ca..a6fd150 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,9 +1,5 @@
 gnome = import('gnome')
 
-sushi_sources = [
-  'main.c',
-]
-
 deps = [
   epoxy_dep,
   evince_document_dep,
@@ -28,67 +24,37 @@ deps = [
 # Compile libsushi and its introspection data
 subdir('libsushi')
 
-sushi_resources = gnome.compile_resources(
-    'sushi-resources',
-    'org.gnome.Sushi.gresource.xml',
-    c_name: 'sushi',
+sushi_data_resources = gnome.compile_resources(
+    'org.gnome.NautilusPreviewer.data',
+    'org.gnome.NautilusPreviewer.data.gresource.xml',
+    gresource_bundle: true,
+    install: true,
+    install_dir: pkgdatadir,
 )
 
-sushi_sources += sushi_resources
-
-executable(
-  'sushi-start',
-  sushi_sources,
-  # link against the just built libsushi
-  dependencies: libsushi_shared_link,
-  install: true,
-  install_dir: libexecdir,
+sushi_src_resources = gnome.compile_resources(
+    'org.gnome.NautilusPreviewer.src',
+    'org.gnome.NautilusPreviewer.src.gresource.xml',
+    gresource_bundle: true,
+    install: true,
+    install_dir: pkgdatadir,
 )
 
 conf = configuration_data()
-
-conf.set(
-  'pkgdatadir',
-  join_paths(datadir, 'sushi'),
-)
-conf.set(
-  'pkglibdir',
-  join_paths(libdir, 'sushi'),
-)
-conf.set(
-  'libexecdir',
-  libexecdir,
-)
+conf.set('GJS', gjs.path())
+conf.set('PACKAGE_NAME', meson.project_name())
+conf.set('PACKAGE_VERSION', meson.project_version())
+conf.set('prefix', get_option('prefix'))
+conf.set('libdir', libdir)
 
 sushi_bin = configure_file(
-  input: 'sushi.in',
-  output: 'sushi',
+  input: 'org.gnome.NautilusPreviewer.in',
+  output: 'org.gnome.NautilusPreviewer',
   configuration: conf,
 )
 
 install_data(
   sushi_bin,
   install_mode: 'rwxr-xr-x',
-  install_dir: bindir,
-)
-
-# Install the Javascript components without installing path.js.in as well
-install_subdir(
-  'js',
-  install_dir: join_paths(datadir, 'sushi'),
-  exclude_files: 'util/path.js.in',
-)
-
-js_conf = configuration_data()
-
-js_conf.set(
-  'localedir',
-  join_paths(datadir, 'locale'),
-)
-
-configure_file(
-  input: 'js/util/path.js.in',
-  output: 'path.js',
-  configuration: js_conf,
-  install_dir: join_paths(datadir, 'sushi', 'js', 'util'),
+  install_dir: libexecdir,
 )
diff --git a/src/org.gnome.Sushi.gresource.xml b/src/org.gnome.NautilusPreviewer.data.gresource.xml
similarity index 73%
rename from src/org.gnome.Sushi.gresource.xml
rename to src/org.gnome.NautilusPreviewer.data.gresource.xml
index e0e67c4..c791c32 100644
--- a/src/org.gnome.Sushi.gresource.xml
+++ b/src/org.gnome.NautilusPreviewer.data.gresource.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
-  <gresource prefix="/org/gnome/Sushi">
+  <gresource prefix="/org/gnome/NautilusPreviewer">
     <file alias="gtk-style.css">resources/gtk-style.css</file>
   </gresource>
 </gresources>
diff --git a/src/org.gnome.NautilusPreviewer.in b/src/org.gnome.NautilusPreviewer.in
new file mode 100644
index 0000000..87436bb
--- /dev/null
+++ b/src/org.gnome.NautilusPreviewer.in
@@ -0,0 +1,9 @@
+#!@GJS@
+
+imports.package.init({
+    name: '@PACKAGE_NAME@',
+    version: '@PACKAGE_VERSION@',
+    prefix: '@prefix@',
+    libdir: '@libdir@',
+});
+imports.package.run(imports.ui.main);
diff --git a/src/org.gnome.NautilusPreviewer.src.gresource.xml 
b/src/org.gnome.NautilusPreviewer.src.gresource.xml
new file mode 100644
index 0000000..b464b4a
--- /dev/null
+++ b/src/org.gnome.NautilusPreviewer.src.gresource.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/NautilusPreviewer/js">
+    <file>ui/application.js</file>
+    <file>ui/fallbackRenderer.js</file>
+    <file>ui/main.js</file>
+    <file>ui/mainWindow.js</file>
+    <file>ui/mimeHandler.js</file>
+    <file>ui/renderer.js</file>
+    <file>ui/utils.js</file>
+    <file>util/constants.js</file>
+    <file>util/totemMimeTypes.js</file>
+    <file>viewers/audio.js</file>
+    <file>viewers/evince.js</file>
+    <file>viewers/font.js</file>
+    <file>viewers/gst.js</file>
+    <file>viewers/html.js</file>
+    <file>viewers/image.js</file>
+    <file>viewers/text.js</file>
+  </gresource>
+</gresources>
diff --git a/src/js/ui/application.js b/src/ui/application.js
similarity index 97%
rename from src/js/ui/application.js
rename to src/ui/application.js
index 381f4ed..8f32543 100644
--- a/src/js/ui/application.js
+++ b/src/ui/application.js
@@ -66,7 +66,7 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
 
     _defineStyleAndThemes() {
         let provider = new Gtk.CssProvider();
-       provider.load_from_resource('/org/gnome/Sushi/gtk-style.css');
+        provider.load_from_resource('/org/gnome/NautilusPreviewer/gtk-style.css');
         Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),
                                                  provider,
                                                  600);
diff --git a/src/js/ui/fallbackRenderer.js b/src/ui/fallbackRenderer.js
similarity index 98%
rename from src/js/ui/fallbackRenderer.js
rename to src/ui/fallbackRenderer.js
index ba8a348..c190140 100644
--- a/src/js/ui/fallbackRenderer.js
+++ b/src/ui/fallbackRenderer.js
@@ -25,8 +25,6 @@
 
 const {Gio, GObject, Gtk, Pango, Sushi} = imports.gi;
 
-const Gettext = imports.gettext.domain('sushi');
-const _ = Gettext.gettext;
 const Renderer = imports.ui.renderer;
 
 var FallbackRenderer = GObject.registerClass(class FallbackRenderer extends Gtk.Box {
diff --git a/src/js/ui/main.js b/src/ui/main.js
similarity index 75%
rename from src/js/ui/main.js
rename to src/ui/main.js
index c84b764..e8ccb50 100644
--- a/src/js/ui/main.js
+++ b/src/ui/main.js
@@ -22,25 +22,29 @@
  * Authors: Cosimo Cecchi <cosimoc redhat com>
  *
  */
-imports.gi.versions.GdkX11 = '3.0';
-imports.gi.versions.Gtk = '3.0';
-
-const {GLib} = imports.gi;
-
-const Format = imports.format;
-const Gettext = imports.gettext;
+pkg.initGettext();
+pkg.initFormat();
+pkg.require({
+    EvinceDocument: '3.0',
+    EvinceView: '3.0',
+    Gdk: '3.0',
+    GdkX11: '3.0',
+    Gio: '2.0',
+    GLib: '2.0',
+    GObject: '2.0',
+    Gst: '1.0',
+    Gtk: '3.0',
+    GtkSource: '4',
+    Pango: '1.0',
+    Sushi: '1.0',
+    WebKit2: '4.0',
+});
 
 const Application = imports.ui.application;
-const Path = imports.util.path;
 
 const SUSHI_DBUS_NAME = 'org.gnome.NautilusPreviewer';
 
-function run(argv) {
-    Gettext.bindtextdomain('sushi', Path.LOCALE_DIR);
-    String.prototype.format = Format.format;
-
-    GLib.set_application_name('Sushi');
-
+function main(argv) {
     let application = new Application.Application({ application_id: SUSHI_DBUS_NAME });
-    return application.run(null);
+    return application.run(argv);
 }
diff --git a/src/js/ui/mainWindow.js b/src/ui/mainWindow.js
similarity index 100%
rename from src/js/ui/mainWindow.js
rename to src/ui/mainWindow.js
diff --git a/src/js/ui/mimeHandler.js b/src/ui/mimeHandler.js
similarity index 100%
rename from src/js/ui/mimeHandler.js
rename to src/ui/mimeHandler.js
diff --git a/src/js/ui/renderer.js b/src/ui/renderer.js
similarity index 100%
rename from src/js/ui/renderer.js
rename to src/ui/renderer.js
diff --git a/src/js/ui/utils.js b/src/ui/utils.js
similarity index 100%
rename from src/js/ui/utils.js
rename to src/ui/utils.js
diff --git a/src/js/util/constants.js b/src/util/constants.js
similarity index 100%
rename from src/js/util/constants.js
rename to src/util/constants.js
diff --git a/src/js/util/totemMimeTypes.js b/src/util/totemMimeTypes.js
similarity index 100%
rename from src/js/util/totemMimeTypes.js
rename to src/util/totemMimeTypes.js
diff --git a/src/js/viewers/audio.js b/src/viewers/audio.js
similarity index 99%
rename from src/js/viewers/audio.js
rename to src/viewers/audio.js
index 31efe88..81d5e8c 100644
--- a/src/js/viewers/audio.js
+++ b/src/viewers/audio.js
@@ -25,9 +25,6 @@
 
 const {GdkPixbuf, Gio, GObject, Gst, Gtk, Sushi} = imports.gi;
 
-const Gettext = imports.gettext.domain('sushi');
-const _ = Gettext.gettext;
-
 const Constants = imports.util.constants;
 const Renderer = imports.ui.renderer;
 const TotemMimeTypes = imports.util.totemMimeTypes;
diff --git a/src/js/viewers/evince.js b/src/viewers/evince.js
similarity index 98%
rename from src/js/viewers/evince.js
rename to src/viewers/evince.js
index 3f7bda5..8d190af 100644
--- a/src/js/viewers/evince.js
+++ b/src/viewers/evince.js
@@ -25,9 +25,6 @@
 
 const {EvinceDocument, EvinceView, GObject, Gtk, Sushi} = imports.gi;
 
-const Gettext = imports.gettext.domain('sushi');
-const _ = Gettext.gettext;
-
 const Constants = imports.util.constants;
 const Renderer = imports.ui.renderer;
 const Utils = imports.ui.utils;
diff --git a/src/js/viewers/font.js b/src/viewers/font.js
similarity index 100%
rename from src/js/viewers/font.js
rename to src/viewers/font.js
diff --git a/src/js/viewers/gst.js b/src/viewers/gst.js
similarity index 100%
rename from src/js/viewers/gst.js
rename to src/viewers/gst.js
diff --git a/src/js/viewers/html.js b/src/viewers/html.js
similarity index 100%
rename from src/js/viewers/html.js
rename to src/viewers/html.js
diff --git a/src/js/viewers/image.js b/src/viewers/image.js
similarity index 97%
rename from src/js/viewers/image.js
rename to src/viewers/image.js
index cdf1af0..dc50bfc 100644
--- a/src/js/viewers/image.js
+++ b/src/viewers/image.js
@@ -22,13 +22,9 @@
  * Authors: Cosimo Cecchi <cosimoc redhat com>
  *
  */
-imports.gi.versions.Gdk = '3.0';
-imports.gi.versions.Gtk = '3.0';
 
 const {Gdk, GdkPixbuf, GLib, GObject, Gtk} = imports.gi;
 
-const Gettext = imports.gettext.domain('sushi');
-const _ = Gettext.gettext;
 const Mainloop = imports.mainloop;
 
 const Renderer = imports.ui.renderer;
diff --git a/src/js/viewers/text.js b/src/viewers/text.js
similarity index 98%
rename from src/js/viewers/text.js
rename to src/viewers/text.js
index 6ebf280..233bbca 100644
--- a/src/js/viewers/text.js
+++ b/src/viewers/text.js
@@ -23,8 +23,6 @@
  *
  */
 
-imports.gi.versions.GtkSource = '4';
-
 const {Gdk, Gio, GLib, GObject, Gtk, GtkSource, Sushi} = imports.gi;
 
 const Renderer = imports.ui.renderer;


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