-
-
Save criztovyl/fb6d8a48da9a97d8e1d2 to your computer and use it in GitHub Desktop.
Hello World Gnome Search Provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -*- Mode: js; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*- | |
// | |
// Copyright (c) 2015 Christoph Schulz, based on | |
// https://git.gnome.org/browse/gnome-weather/plain/src/service/searchProvider.js | |
// Copyright (c) 2013 Giovanni Campagna <scampa.giovanni@gmail.com> (GPLv2 or later) | |
// | |
// Thus is free software; you can redistribute it and/or modify | |
// it under the terms of the GNU General Public License as published by the | |
// Free Software Foundation; either version 3 of the License, or (at your | |
// option) any later version. | |
// | |
// Gnome Weather is distributed in the hope that it will be useful, but | |
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
// for more details. | |
// | |
// You should have received a copy of the GNU General Public License along | |
// 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 Lang = imports.lang; | |
const SearchProviderInterface = Gio.resources_lookup_data('/org/gnome/Shell/ShellSearchProvider2.xml', 0).toArray().toString(); | |
const SearchProvider = new Lang.Class({ | |
Name: 'MySearchProvider', | |
_init: function() { | |
this.myterms = {"foo": "bar", "bar": "foo", "Where are you?": "I'm here!", "Are you there?": "Yes." } | |
this._impl = Gio.DBusExportedObject.wrapJSObject(SearchProviderInterface, this); | |
}, | |
export: function(connection, path) { | |
return this._impl.export(connection, path); | |
}, | |
unexport: function(connection) { | |
return this._impl.unexport_from_connection(connection); | |
}, | |
GetInitialResultSet: function(params) { | |
let terms = params[0]; | |
return this._runQuery(terms); | |
}, | |
_runQuery: function(terms) { | |
let result = []; | |
//terms = terms.join(" "); | |
for(var myterm in this.myterms){ | |
// String#beginsWith(terms) | |
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv | |
if(myterm.slice(0, terms.length) == terms) result.push(myterm); | |
} | |
return result; | |
}, | |
GetSubsearchResultSet: function(previous, terms) { | |
let ret = []; | |
//terms = terms.join(" "); | |
for(i=0; i < previous.length; i++){ | |
if(this.myterms[previous[i]].slice(0, terms.length) == terms) ret.push(previous[i]); | |
} | |
for(myterm in this.myterms){ | |
if(myterm.slice(0, terms.length) == terms && ret.indexOf(myterm) < 0) ret.push(myterm); | |
} | |
return ret; | |
}, | |
GetResultMetas: function(identifiers) { | |
let ret = []; | |
for(i=0; i < identifiers.length; i++){ | |
ret.push({ | |
"id": identifiers[i], | |
"name": this.myterms[identifiers[i]], | |
"description": "You searched, I deliver."}); | |
} | |
return ret; | |
}, | |
_activateAction: function(action, parameter, timestamp) { | |
}, | |
ActivateResult: function(id, terms, timestamp) { | |
print("Please activate: " + id); | |
}, | |
LaunchSearch: function(terms, timestamp) { | |
print("Launch search plz."); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment