[gnome-maps/wip/mlundblad/override-transit-plugin: 2/3] transitRouter: Allow overriding plugin
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/override-transit-plugin: 2/3] transitRouter: Allow overriding plugin
- Date: Tue, 12 Jan 2021 21:37:18 +0000 (UTC)
commit 6ad60155432685578d1db019db47fa36b85b7fcf
Author: Marcus Lundblad <ml update uu se>
Date: Fri Jan 8 23:22:06 2021 +0100
transitRouter: Allow overriding plugin
Allow setting the environment variable TRANSIT_PLUGIN
to override the plugin to use.
src/transitRouter.js | 36 +++++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/src/transitRouter.js b/src/transitRouter.js
index 61d8650a..e2a3e5ec 100644
--- a/src/transitRouter.js
+++ b/src/transitRouter.js
@@ -19,6 +19,7 @@
* Author: Marcus Lundblad <ml update uu se>
*/
+const GLib = imports.gi.GLib;
const Champlain = imports.gi.Champlain;
const Service = imports.service;
@@ -54,15 +55,36 @@ var TransitRouter = class TransitRoute {
* of results-
*/
fetchFirstResults() {
- let bestProvider = this._getBestProviderForQuery();
+ let pluginOverride = GLib.getenv('TRANSIT_PLUGIN');
+
+ if (pluginOverride) {
+ // override plugin was specified, try instanciating if not done yet
+ if (!this._currPluginInstance) {
+ let module = this._availablePlugins[pluginOverride];
+
+ if (module) {
+ this._currPluginInstance =
+ new imports.transitplugins[module][pluginOverride]();
+ } else {
+ throw new Error('Specified override plugin not found');
+ }
+ }
+ } else {
+ let bestProvider = this._getBestProviderForQuery();
+
+ this._currPluginInstance = null;
- if (bestProvider) {
- let provider = bestProvider[0];
+ if (bestProvider) {
+ let provider = bestProvider[0];
+
+ this._currPluginInstance = bestProvider[1];
+ this._plan.attribution = this._getAttributionForProvider(provider);
+ if (provider.attributionUrl)
+ this._plan.attributionUrl = provider.attributionUrl;
+ }
+ }
- this._currPluginInstance = bestProvider[1];
- this._plan.attribution = this._getAttributionForProvider(provider);
- if (provider.attributionUrl)
- this._plan.attributionUrl = provider.attributionUrl;
+ if (this._currPluginInstance) {
this._currPluginInstance.fetchFirstResults();
} else {
this._plan.reset();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]