[gnome-maps/wip/mlundblad/remaining_cmd_options] application: Handle command line args with GApplication
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/remaining_cmd_options] application: Handle command line args with GApplication
- Date: Sun, 12 Jul 2020 21:45:09 +0000 (UTC)
commit 46b9a6aca3dc4d04ca8a3a4aa7e5cecc4bb12155
Author: Marcus Lundblad <ml update uu se>
Date: Sat Jul 11 11:55:19 2020 +0200
application: Handle command line args with GApplication
Use GApplication::command_line to handle "remaining" args.
This way we can get a proper description for the file|URI
parameters.
src/application.js | 78 ++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 55 insertions(+), 23 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 0cd91640..b61c5244 100644
--- a/src/application.js
+++ b/src/application.js
@@ -84,7 +84,8 @@ var Application = GObject.registerClass({
_ensuredTypes.forEach((type) => GObject.type_ensure(type));
super._init({ application_id: 'org.gnome.Maps',
- flags: Gio.ApplicationFlags.HANDLES_OPEN });
+ flags: Gio.ApplicationFlags.HANDLES_OPEN |
+ Gio.ApplicationFlags.HANDLES_COMMAND_LINE });
this._connected = false;
this.add_main_option('local',
@@ -109,28 +110,12 @@ var Application = GObject.registerClass({
GLib.OptionArg.NONE,
_("Ignore network availability"),
null);
-
- this.connect('handle-local-options', (app, options) => {
- if (options.contains('local')) {
- let variant = options.lookup_value('local', null);
- this.local_tile_path = variant.deep_unpack();
- normalStartup = false;
- if (options.contains('local-tile-size')) {
- variant = options.lookup_value('local-tile-size', null);
- this.local_tile_size = variant.deep_unpack();
- }
- } else if (options.contains('version')) {
- print(pkg.version);
- /* quit the invoked process after printing the version number
- * leaving the running instance unaffected
- */
- return 0;
- } else if (options.contains('force-online')) {
- this._forceOnline = true;
- }
-
- return -1;
- });
+ this.add_main_option(GLib.OPTION_REMAINING,
+ 0,
+ 0,
+ GLib.OptionArg.STRING_ARRAY,
+ _("[FILE…|URI]"),
+ _("[FILE…|URI]"));
}
_checkNetwork() {
@@ -320,6 +305,8 @@ var Application = GObject.registerClass({
let uri = files[0].get_uri();
let scheme = GLib.uri_parse_scheme(uri);
+ Utils.debug('uri: ' + uri);
+
if (scheme === 'geo') {
/* we get an uri that looks like geo:///lat,lon, remove slashes */
let geoURI = uri.replace(/\//g, '');
@@ -343,6 +330,51 @@ var Application = GObject.registerClass({
this._openInternal.bind(this, files));
}
+ vfunc_command_line(cmdline) {
+ let options = cmdline.get_options_dict();
+
+ if (options.contains('local')) {
+ let variant = options.lookup_value('local', null);
+ this.local_tile_path = variant.deep_unpack();
+ normalStartup = false;
+ if (options.contains('local-tile-size')) {
+ variant = options.lookup_value('local-tile-size', null);
+ this.local_tile_size = variant.deep_unpack();
+ }
+ } else if (options.contains('version')) {
+ print(pkg.version);
+ /* quit the invoked process after printing the version number
+ * leaving the running instance unaffected
+ */
+ return 0;
+ } else if (options.contains('force-online')) {
+ this._forceOnline = true;
+ }
+
+ let remaining = options.lookup(GLib.OPTION_REMAINING, null);
+
+ if (remaining) {
+ let files = [];
+
+ remaining.forEach((r) => {
+ let path = r.get_string()[0];
+
+ if (path.startsWith('geo:') || path.startsWith('http://') ||
+ path.startsWith('https://')) {
+ files.push(Gio.File.new_for_uri(path));
+ } else {
+ files.push(Gio.File.new_for_path(path));
+ }
+ });
+
+ this.open(files, '');
+ } else {
+ this.activate();
+ }
+
+ return 0;
+ }
+
_onWindowDestroy(window) {
this._mainWindow = null;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]