[gnome-weather] Convert to load sources from a GResource



commit e10547eb18620972b6ea8642300fa94ba940422b
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Wed Jan 15 21:32:19 2014 +0100

    Convert to load sources from a GResource
    
    Compile sources into a GResource file and load that instead
    of individual JS files.
    For ease of development, when running uninstalled we still
    load the JS files (and thus don't require a make first)

 data/Makefile.am                                   |   10 +++---
 ...g.gnome.Weather.Application.data.gresource.xml} |    0
 src/Makefile.am                                    |   35 ++++++++++++--------
 src/main.js                                        |    3 +-
 ...org.gnome.Weather.Application.src.gresource.xml |   14 ++++++++
 src/util.js                                        |    2 +-
 6 files changed, 42 insertions(+), 22 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index cf24b36..232b0b6 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -2,12 +2,12 @@
 # 5 different directory declarations
 SUBDIRS = icons
 
-resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies 
$(srcdir)/$(PACKAGE_NAME).gresource.xml)
-$(PACKAGE_NAME).gresource: $(PACKAGE_NAME).gresource.xml $(resource_files)
+resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies 
$(srcdir)/$(PACKAGE_NAME).data.gresource.xml)
+$(PACKAGE_NAME).data.gresource: $(PACKAGE_NAME).data.gresource.xml $(resource_files)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
 
 resourcedir = $(pkgdatadir)
-resource_DATA = $(PACKAGE_NAME).gresource
+resource_DATA = $(PACKAGE_NAME).data.gresource
 
 appsdir = $(datadir)/applications
 apps_DATA = $(PACKAGE_NAME).desktop
@@ -41,7 +41,7 @@ EXTRA_DIST = \
        CREDITS \
        $(PACKAGE_NAME).desktop.in \
        $(PACKAGE_NAME).service.in \
-       $(PACKAGE_NAME).gresource.xml \
+       $(PACKAGE_NAME).data.gresource.xml \
        $(gsettings_SCHEMAS) \
        $(PACKAGE_NAME).appdata.xml.in \
        $(resource_files) \
@@ -49,7 +49,7 @@ EXTRA_DIST = \
 
 CLEANFILES = \
        $(PACKAGE_NAME).service \
-       $(PACKAGE_NAME).gresource \
+       $(PACKAGE_NAME).data.gresource \
        $(PACKAGE_NAME).appdata.xml \
        $(apps_DATA) \
        *.valid \
diff --git a/data/org.gnome.Weather.Application.gresource.xml 
b/data/org.gnome.Weather.Application.data.gresource.xml
similarity index 100%
rename from data/org.gnome.Weather.Application.gresource.xml
rename to data/org.gnome.Weather.Application.data.gresource.xml
diff --git a/src/Makefile.am b/src/Makefile.am
index bf12cc1..52e0913 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,21 +3,18 @@ NULL =
 nodist_bin_SCRIPTS = $(PACKAGE_TARNAME)
 nodist_pkgdata_SCRIPTS = $(PACKAGE_NAME)
 
+resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies 
$(srcdir)/$(PACKAGE_NAME).src.gresource.xml)
+$(PACKAGE_NAME).src.gresource: $(PACKAGE_NAME).src.gresource.xml $(resource_files)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
+
+resourcedir = $(pkgdatadir)
+resource_DATA = $(PACKAGE_NAME).src.gresource
+
 EXTRA_SCRIPTS = org.gnome.Weather.Application gnome-weather
 
+# Legacy, until we can depend on package.js provided by gjs
 jsdir = $(pkgdatadir)
-dist_js_DATA = \
-       city.js         \
-       forecast.js     \
-       main.js         \
-       package.js      \
-       params.js       \
-       searchProvider.js \
-       strings.js      \
-       util.js         \
-       window.js       \
-       world.js        \
-       $(NULL)
+dist_js_DATA = package.js
 
 $(PACKAGE_TARNAME): $(PACKAGE_TARNAME).in
        $(AM_V_GEN) sed \
@@ -41,7 +38,17 @@ $(PACKAGE_NAME): $(PACKAGE_NAME).in
                $< > $@
        @chmod +x $@
 
-EXTRA_DIST = $(PACKAGE_NAME).in $(PACKAGE_TARNAME).in
-CLEANFILES = $(PACKAGE_NAME) $(PACKAGE_TARNAME)
+EXTRA_DIST = \
+       $(PACKAGE_NAME).in \
+       $(PACKAGE_TARNAME).in \
+       $(PACKAGE_NAME).src.gresource.xml \
+       $(resource_files) \
+       $(NULL)
+
+CLEANFILES = \
+       $(PACKAGE_NAME) \
+       $(PACKAGE_TARNAME) \
+       $(PACKAGE_NAME).src.gresource \
+       $(NULL)
 
 -include $(top_srcdir)/git.mk
diff --git a/src/main.js b/src/main.js
index 401765d..3e333fe 100644
--- a/src/main.js
+++ b/src/main.js
@@ -19,7 +19,6 @@
 pkg.initSubmodule('libgd');
 pkg.initGettext();
 pkg.initFormat();
-pkg.initResources();
 pkg.require({ 'Gd': '1.0',
               'Gdk': '3.0',
               'GdkPixbuf': '2.0',
@@ -119,7 +118,7 @@ const Application = new Lang.Class({
         this.add_accelerator("Escape", "win.selection-mode(false)", null);
         this.add_accelerator("<Primary>a", "win.select-all", null);
 
-        if (pkg.pkgdatadir != pkg.moduledir) // running from source
+        if (!pkg.moduledir.startsWith('resource://')) // running from source
             this.activate();
     },
 
diff --git a/src/org.gnome.Weather.Application.src.gresource.xml 
b/src/org.gnome.Weather.Application.src.gresource.xml
new file mode 100644
index 0000000..a2f82f7
--- /dev/null
+++ b/src/org.gnome.Weather.Application.src.gresource.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/Weather/Application/js">
+    <file>city.js</file>
+    <file>forecast.js</file>
+    <file>main.js</file>
+    <file>params.js</file>
+    <file>searchProvider.js</file>
+    <file>strings.js</file>
+    <file>util.js</file>
+    <file>window.js</file>
+    <file>world.js</file>
+  </gresource>
+</gresources>
diff --git a/src/util.js b/src/util.js
index eb2e7e9..2c7feb3 100644
--- a/src/util.js
+++ b/src/util.js
@@ -84,7 +84,7 @@ function getSettings(schemaId, path) {
     const GioSSS = Gio.SettingsSchemaSource;
     let schemaSource;
 
-    if (pkg.moduledir != pkg.pkgdatadir) {
+    if (!pkg.moduledir.startsWith('resource://')) {
         // Running from the source tree
         schemaSource = GioSSS.new_from_directory(pkg.pkgdatadir,
                                                  GioSSS.get_default(),


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