[gnome-weather] Update package.js
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-weather] Update package.js
- Date: Wed, 1 Jan 2014 17:22:35 +0000 (UTC)
commit 88c2e1cc3360c3df018cd9bda4654fe69e74faad
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Wed Jan 1 18:16:56 2014 +0100
Update package.js
Use the new format, which removes the automagic includes and hopefully
will be merged in gjs at some point...
Also includes some small improvements in the launcher binary
(which now conforms to the GNU conventions for --help and --version)
src/city.js | 4 ++
src/forecast.js | 7 +++
src/gnome-weather.in | 5 ++-
src/main.js | 14 +++--
src/package.js | 144 ++++++++++++++++++++++++-------------------------
src/params.js | 4 --
src/searchProvider.js | 5 ++
src/util.js | 8 +++
src/window.js | 7 +++
src/world.js | 9 +++
10 files changed, 124 insertions(+), 83 deletions(-)
---
diff --git a/src/city.js b/src/city.js
index d765a22..f71b6f3 100644
--- a/src/city.js
+++ b/src/city.js
@@ -16,7 +16,11 @@
// with Gnome Weather; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
+
const Forecast = imports.forecast;
+const Params = imports.params;
const Util = imports.util;
const SPINNER_SIZE = 128;
diff --git a/src/forecast.js b/src/forecast.js
index 7168f69..7b1ff37 100644
--- a/src/forecast.js
+++ b/src/forecast.js
@@ -16,6 +16,13 @@
// with Gnome Weather; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const GWeather = imports.gi.GWeather;
+const Lang = imports.lang;
+
+const Params = imports.params;
const Strings = imports.strings;
const Util = imports.util;
diff --git a/src/gnome-weather.in b/src/gnome-weather.in
index 8c1dbd1..d92b317 100755
--- a/src/gnome-weather.in
+++ b/src/gnome-weather.in
@@ -1,3 +1,6 @@
#! GJS@
imports.searchPath.push("@pkgdatadir@");
-imports.package.launch({ name: "@PACKAGE_NAME@" });
\ No newline at end of file
+imports.package.launch({ name: "@PACKAGE_NAME@",
+ version: "@PACKAGE_VERSION@",
+ prefix: "@prefix@",
+ libdir: "@libdir@" });
\ No newline at end of file
diff --git a/src/main.js b/src/main.js
index c1f8683..010eab0 100644
--- a/src/main.js
+++ b/src/main.js
@@ -27,11 +27,15 @@ pkg.require({ 'Gd': '1.0',
'GLib': '2.0',
'GObject': '2.0',
'Gtk': '3.0',
- 'GWeather': '3.0',
- 'Lang': '',
- 'Mainloop': '',
- 'Params': '1.0',
- 'System': '' });
+ 'GWeather': '3.0' });
+
+const Gd = imports.gi.Gd;
+const Gdk = imports.gi.Gdk;
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const GWeather = imports.gi.GWeather;
+const Lang = imports.lang;
const Util = imports.util;
const Window = imports.window;
diff --git a/src/package.js b/src/package.js
index f8fab2d..4a77679 100644
--- a/src/package.js
+++ b/src/package.js
@@ -33,6 +33,7 @@ const Gettext = imports.gettext;
/*< public >*/
var name;
var version;
+var appFlags;
var prefix;
var datadir;
var libdir;
@@ -45,17 +46,13 @@ var localedir;
let _base;
let _requires;
-function _runningFromSource(name) {
- if (System.version >= 13600) {
- let fileName = System.programInvocationName;
+function _runningFromSource() {
+ let fileName = System.programInvocationName;
+ let prgName = GLib.path_get_basename(fileName);
- let binary = Gio.File.new_for_path(fileName);
- let sourceBinary = Gio.File.new_for_path('./src/' + name);
- return binary.equal(sourceBinary);
- } else {
- return GLib.file_test(name + '.doap',
- GLib.FileTest.EXISTS);
- }
+ let binary = Gio.File.new_for_path(fileName);
+ let sourceBinary = Gio.File.new_for_path('./src/' + prgName);
+ return binary.equal(sourceBinary);
}
/**
@@ -103,6 +100,7 @@ function init(params) {
window.pkg = imports.package;
name = params.name;
version = params.version;
+ appFlags = params.flags;
// Must call it first, because it can only be called
// once, and other library calls might have it as a
@@ -114,7 +112,7 @@ function init(params) {
datadir = GLib.build_filenamev([prefix, 'share']);
let libpath, girpath;
- if (_runningFromSource(name)) {
+ if (_runningFromSource()) {
log('Running from source tree, using local files');
// Running from source directory
_base = GLib.get_current_dir();
@@ -125,6 +123,8 @@ function init(params) {
localedir = GLib.build_filenamev([_base, 'po']);
moduledir = GLib.build_filenamev([_base, 'src']);
} else {
+ appFlags |= Gio.ApplicationFlags.IS_SERVICE;
+
_base = prefix;
pkglibdir = GLib.build_filenamev([libdir, name]);
libpath = pkglibdir;
@@ -148,10 +148,12 @@ function init(params) {
* You must define a main(ARGV) function inside a main.js
* module in moduledir.
*/
-function start(params) {
+function start(params, args) {
+ params.flags = params.flags || 0;
+ args = args || ARGV;
init(params);
- return imports.main.main(ARGV);
+ return imports.main.main(args);
}
function _checkVersion(required, current) {
@@ -180,47 +182,6 @@ function _checkVersion(required, current) {
return true;
}
-function _isGjsModule(name, version) {
- // This is a subset of the JS modules we offer,
- // it includes only those that makes sense to use
- // standalone and in a general app.
- //
- // You will not find Gettext or Format here, use
- // the package functions instead. And Package, obviously,
- // because it's available as window.package.
- //
- // cairo is also a JS module, but the version checking
- // differs, see _isForeignModule()
- //
- // FIXME: Mainloop might be better as a GLib override?
- // FIXME: Signals should be an extension to Lang
- const RECOGNIZED_MODULE_NAMES = ['Lang',
- 'Mainloop',
- 'Signals',
- 'System',
- 'Params'];
- for (let i = 0; i < RECOGNIZED_MODULE_NAMES.length; i++) {
- let module = RECOGNIZED_MODULE_NAMES[i];
-
- if (module == name) {
- let actualModule = imports[module.toLowerCase()];
- let required = version.split('.');
-
- if (!_checkVersion(required, actualModule.$API_VERSION)) {
- printerr('Unsatisfied dependency: requested GJS module at version '
- + version + ', but only ' + (actualModule.$API_VERSION.join('.'))
- + ' is available');
- System.exit(1);
- } else {
- window[module] = actualModule;
- return true;
- }
- }
- }
-
- return false;
-}
-
/**
* require:
* @libs: the external dependencies to import
@@ -230,9 +191,6 @@ function _isGjsModule(name, version) {
* @libs must be an object whose keys are a typelib name,
* and values are the respective version. The empty string
* indicates any version.
- *
- * If dependencies are statisfied, require() will make
- * the module objects available as global names.
*/
function require(libs) {
_requires = libs;
@@ -240,21 +198,11 @@ function require(libs) {
for (let l in libs) {
let version = libs[l];
- if (_isGjsModule(l, version))
- continue;
-
if (version != '')
imports.gi.versions[l] = version;
try {
- if (name == 'cairo') {
- // Import the GI package to check the version,
- // but then load the JS one
- imports.gi.cairo;
- window.cairo = imports.cairo;
- } else {
- window[l] = imports.gi[l];
- }
+ imports.gi[l];
} catch(e) {
printerr('Unsatisfied dependency: ' + e.message);
System.exit(1);
@@ -300,11 +248,61 @@ function initResources() {
resource._register();
}
+// Launcher support
+
+function _launcherUsage(flags) {
+ print('Usage:');
+
+ let name = GLib.path_get_basename(System.programInvocationName);
+ if (flags & Gio.ApplicationFlags.HANDLES_OPEN)
+ print(' ' + name + ' [OPTION...] [FILE...]\n');
+ else
+ print(' ' + name + ' [OPTION...]\n');
+
+ print('Options:');
+ print(' -h, --help Show this help message');
+ print(' --version Show the application version');
+}
+
+function _parseLaunchArgs(args, params) {
+ let newArgs = [];
+
+ for (let i = 0; i < args.length; i++) {
+ switch (args[i]) {
+ case '--':
+ newArgs.concat(args.slice(i));
+ return newArgs;
+
+ case '--help':
+ case '-h':
+ _launcherUsage(params.flags);
+ System.exit(0);
+ break;
+
+ case '--version':
+ print(params.name + ' ' + params.version);
+ System.exit(0);
+ break;
+
+ default:
+ newArgs.push(args[i]);
+ }
+ }
+
+ return newArgs;
+}
+
function launch(params) {
params.flags = params.flags || 0;
- let app = new Gio.Application({ application_id: params.name,
- flags: (Gio.ApplicationFlags.IS_LAUNCHER |
- params.flags),
- });
- return app.run(ARGV);
+ let args = _parseLaunchArgs(ARGV, params);
+
+ if (_runningFromSource()) {
+ return start(params, args);
+ } else {
+ params.flags |= Gio.ApplicationFlags.IS_LAUNCHER;
+
+ let app = new Gio.Application({ application_id: params.name,
+ flags: params.flags });
+ return app.run(args);
+ }
}
diff --git a/src/params.js b/src/params.js
index 4bbade0..ee45c81 100644
--- a/src/params.js
+++ b/src/params.js
@@ -1,9 +1,5 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
-// Rules for versioning: bump major when making API incompatible changes,
-// bump minor when adding API
-var $API_VERSION = [1, 0];
-
// Params:
//
// A set of convenience functions for dealing with pseudo-keyword
diff --git a/src/searchProvider.js b/src/searchProvider.js
index 0c4f063..2b03ecd 100644
--- a/src/searchProvider.js
+++ b/src/searchProvider.js
@@ -16,6 +16,11 @@
// with Gnome Weather; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const GWeather = imports.gi.GWeather;
+const Lang = imports.lang;
+
const Util = imports.util;
const Window = imports.window;
const World = imports.world;
diff --git a/src/util.js b/src/util.js
index eae90dd..eb2e7e9 100644
--- a/src/util.js
+++ b/src/util.js
@@ -24,6 +24,14 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+const Gdk = imports.gi.Gdk;
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const System = imports.system;
+
+const Params = imports.params;
+
function loadUI(resourcePath, objects) {
let ui = new Gtk.Builder();
diff --git a/src/window.js b/src/window.js
index 265333e..88882ab 100644
--- a/src/window.js
+++ b/src/window.js
@@ -16,7 +16,14 @@
// with Gnome Weather; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
+const Gtk = imports.gi.Gtk;
+const GWeather = imports.gi.GWeather;
+const Lang = imports.lang;
+
const City = imports.city;
+const Params = imports.params;
const World = imports.world;
const Util = imports.util;
diff --git a/src/world.js b/src/world.js
index 874339b..38e4bb3 100644
--- a/src/world.js
+++ b/src/world.js
@@ -16,6 +16,15 @@
// with Gnome Weather; if not, write to the Free Software Foundation,
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+const Gd = imports.gi.Gd;
+const GdkPixbuf = imports.gi.GdkPixbuf;
+const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
+const Gtk = imports.gi.Gtk;
+const GWeather = imports.gi.GWeather;
+const Lang = imports.lang;
+
+const Params = imports.params;
const Util = imports.util;
const Columns = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]