[gnome-characters/bilelmoussaoui/search-provider] Simplify the search provider




commit 573913f4855f9711e021d91a685d9221cea778a2
Author: Bilal Elmoussaoui <belmouss redhat com>
Date:   Sat Jan 29 00:21:53 2022 +0100

    Simplify the search provider
    
    Drop the split between the search provider and the application
    It only made the code more complciated to read

 build-aux/flatpak/org.gnome.Characters.json        |  1 -
 data/meson.build                                   | 21 +-----
 ...Characters.BackgroundService.data.gresource.xml |  8 --
 ...g.gnome.Characters.BackgroundService.service.in |  3 -
 data/org.gnome.Characters.data.gresource.xml       |  3 +
 data/org.gnome.Characters.search-provider.ini      |  4 +-
 data/org.gnome.Characters.service.in               |  2 +-
 meson.build                                        |  3 +-
 src/main.js                                        | 26 ++++---
 src/meson.build                                    | 34 +--------
 src/org.gnome.Characters.BackgroundService.in      |  6 --
 ...aracters.BackgroundService.src.gresource.xml.in |  8 --
 src/org.gnome.Characters.src.gresource.xml.in      |  1 +
 src/searchProvider.js                              | 55 ++------------
 src/service.js                                     | 86 ----------------------
 15 files changed, 33 insertions(+), 228 deletions(-)
---
diff --git a/build-aux/flatpak/org.gnome.Characters.json b/build-aux/flatpak/org.gnome.Characters.json
index ee8054f..8c7d9d9 100644
--- a/build-aux/flatpak/org.gnome.Characters.json
+++ b/build-aux/flatpak/org.gnome.Characters.json
@@ -10,7 +10,6 @@
         "--socket=fallback-x11",
         "--socket=wayland",
         "--device=dri",
-        "--own-name=org.gnome.CharactersDevel.BackgroundService",
         "--metadata=X-DConf=migrate-path=/org/gnome/Characters/"
     ],
     "cleanup" : [
diff --git a/data/meson.build b/data/meson.build
index d0de6a0..dd236f9 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -13,6 +13,7 @@ resource_data = files(
   'shortcuts.ui',
   'sidebar.ui',
   'window.ui',
+  'ShellSearchProvider2.xml'
 )
 
 gnome.compile_resources(
@@ -24,15 +25,6 @@ gnome.compile_resources(
     install_dir: characters_pkgdatadir
 )
 
-gnome.compile_resources(
-    application_id + '.BackgroundService.data',
-    'org.gnome.Characters.BackgroundService.data.gresource.xml',
-    gresource_bundle: true,
-    dependencies: files('ShellSearchProvider2.xml'),
-    install: true,
-    install_dir: characters_pkgdatadir
-)
-
 desktop_conf = configuration_data ()
 desktop_conf.set('appid', application_id)
 desktop_conf.set('bindir', characters_bindir)
@@ -81,14 +73,6 @@ configure_file(
   install_dir: dbus_service_dir
 )
 
-configure_file(
-  input: 'org.gnome.Characters.BackgroundService.service.in',
-  output: application_id + '.BackgroundService.service',
-  configuration: service_conf,
-  install: true,
-  install_dir: dbus_service_dir
-)
-
 install_data(
   'org.gnome.Characters.gschema.xml',
   install_dir: join_paths(characters_datadir, 'glib-2.0', 'schemas')
@@ -96,8 +80,7 @@ install_data(
 
 search_provider_conf = configuration_data()
 search_provider_conf.set('appid', application_id)
-search_provider_conf.set('background_service_id', background_service_id)
-search_provider_conf.set('background_service_path', background_service_path)
+search_provider_conf.set('search_provider_path', search_provider_path)
 
 configure_file(
   input: 'org.gnome.Characters.search-provider.ini',
diff --git a/data/org.gnome.Characters.data.gresource.xml b/data/org.gnome.Characters.data.gresource.xml
index 168e8a2..d6f2e17 100644
--- a/data/org.gnome.Characters.data.gresource.xml
+++ b/data/org.gnome.Characters.data.gresource.xml
@@ -16,4 +16,7 @@
     <file 
alias="characters-picture-symbolic.svg">icons/hicolor/scalable/categories/characters-picture-symbolic.svg</file>
     <file 
alias="characters-punctuation-symbolic.svg">icons/hicolor/scalable/categories/characters-punctuation-symbolic.svg</file>
   </gresource>
+  <gresource prefix="/org/gnome/shell">
+    <file>ShellSearchProvider2.xml</file>
+  </gresource>
 </gresources>
diff --git a/data/org.gnome.Characters.search-provider.ini b/data/org.gnome.Characters.search-provider.ini
index 58ef6a1..6e1a1c7 100644
--- a/data/org.gnome.Characters.search-provider.ini
+++ b/data/org.gnome.Characters.search-provider.ini
@@ -1,6 +1,6 @@
 [Shell Search Provider]
 DesktopId=@appid@.desktop
-BusName=@background_service_id@
-ObjectPath=@background_service_path@
+BusName=@appid@
+ObjectPath=@search_provider_path@
 Version=2
 DefaultDisabled=false
diff --git a/data/org.gnome.Characters.service.in b/data/org.gnome.Characters.service.in
index 43297d9..97514ac 100644
--- a/data/org.gnome.Characters.service.in
+++ b/data/org.gnome.Characters.service.in
@@ -1,3 +1,3 @@
 [D-BUS Service]
 Name=@appid@
-Exec=@pkgdatadir@/@appid@.BackgroundService
+Exec=@bindir@/gnome-characters --gapplication-service
diff --git a/meson.build b/meson.build
index 6069a3d..e3329f7 100644
--- a/meson.build
+++ b/meson.build
@@ -19,8 +19,7 @@ else
   version_suffix = ''
 endif
 application_id = 'org.gnome.Characters@0@'.format(profile)
-background_service_path = '/org/gnome/Characters@0@/BackgroundService'.format(profile)
-background_service_id = application_id + '.BackgroundService'
+search_provider_path = '/org/gnome/Characters@0@/SearchProvider'.format(profile)
 
 characters_version = meson.project_version()
 
diff --git a/src/main.js b/src/main.js
index d84d3f3..61e4b05 100644
--- a/src/main.js
+++ b/src/main.js
@@ -44,7 +44,7 @@ const { Sidebar } = imports.sidebar;
 const { MainWindow } = imports.window;
 
 const Util = imports.util;
-
+const SearchProvider = imports.searchProvider;
 var settings = null;
 
 var MyApplication = GObject.registerClass({
@@ -56,16 +56,16 @@ var MyApplication = GObject.registerClass({
             resource_base_path: '/org/gnome/Characters',
         });
         GLib.set_application_name(_('Characters'));
+
+        this._searchProvider = new SearchProvider.SearchProvider(this);
     }
 
-    _onQuit() {
-        this.quit();
+    get window() {
+        return this._appwindow;
     }
 
-    _onSearch(action, parameter) {
-        const window = new MainWindow(this);
-        window.setSearchKeywords(parameter.get_strv());
-        window.show();
+    _onQuit() {
+        this.quit();
     }
 
     vfunc_startup() {
@@ -75,11 +75,6 @@ var MyApplication = GObject.registerClass({
 
         Util.initActions(this, [
             { name: 'quit', activate: this._onQuit },
-            {
-                name: 'search',
-                activate: this._onSearch,
-                parameterType: new GLib.VariantType('as'),
-            },
         ]);
         this.set_accels_for_action('app.quit', ['<Primary>q']);
         this.set_accels_for_action('win.find', ['<Primary>f']);
@@ -92,6 +87,13 @@ var MyApplication = GObject.registerClass({
         log('Characters Application started');
     }
 
+    vfunc_dbus_register(connection, path) {
+        const searchProviderPath = `${path}/SearchProvider`;
+        super.vfunc_dbus_register(connection, searchProviderPath);
+        this._searchProvider.export(connection, searchProviderPath);
+        return true;
+    }
+
     vfunc_activate() {
         if (!this._appwindow)
             this._appwindow = new MainWindow(this);
diff --git a/src/meson.build b/src/meson.build
index 26d9be1..d9cb676 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -13,31 +13,18 @@ configure_file(
     install_dir: characters_pkgdatadir
 )
 
-configure_file(
-    input: 'org.gnome.Characters.BackgroundService.in',
-    output: application_id + '.BackgroundService',
-    configuration: script_conf,
-    install: true,
-    install_dir: characters_pkgdatadir
-)
 
-common_resource_data = files(
-  'util.js'
-)
-
-resource_data = common_resource_data + files(
+resource_data = files(
   'characterDialog.js',
   'charactersView.js',
   'main.js',
   'sidebar.js',
   'sidebarRow.js',
-  'window.js'
-)
-
-resource_data = common_resource_data + files(
+  'window.js',
   'searchProvider.js',
-  'service.js'
+  'util.js',
 )
+
 resources_conf = configuration_data()
 resources_conf.set('profile', profile)
 
@@ -53,16 +40,3 @@ gnome.compile_resources(
   install: true,
   install_dir: characters_pkgdatadir
 )
-
-gnome.compile_resources(
-  application_id + '.BackgroundService.src',
-  configure_file(
-    input: 'org.gnome.Characters.BackgroundService.src.gresource.xml.in',
-    output: '@BASENAME@',
-    configuration: resources_conf
-  ),
-  gresource_bundle: true,
-  dependencies: resource_data,
-  install: true,
-  install_dir: characters_pkgdatadir
-)
diff --git a/src/org.gnome.Characters.src.gresource.xml.in b/src/org.gnome.Characters.src.gresource.xml.in
index b71d75d..8d77206 100644
--- a/src/org.gnome.Characters.src.gresource.xml.in
+++ b/src/org.gnome.Characters.src.gresource.xml.in
@@ -8,5 +8,6 @@
     <file>window.js</file>
     <file>characterDialog.js</file>
     <file>charactersView.js</file>
+    <file>searchProvider.js</file>
   </gresource>
 </gresources>
diff --git a/src/searchProvider.js b/src/searchProvider.js
index ff75a92..1f5eceb 100644
--- a/src/searchProvider.js
+++ b/src/searchProvider.js
@@ -18,7 +18,7 @@
 // with Gnome Weather; if not, write to the Free Software Foundation,
 // Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-const { Gc, Gdk, Gio, GLib, GObject } = imports.gi;
+const { Gc, Gio, GLib, GObject } = imports.gi;
 
 const ByteArray = imports.byteArray;
 const Util = imports.util;
@@ -32,9 +32,6 @@ var SearchProvider = GObject.registerClass({
 }, class SearchProvider extends GObject.Object {
     _init(application) {
         this._app = application;
-        const serviceId = application.get_application_id();
-        this._appId = serviceId.replace('.BackgroundService', '');
-        this._appObjectPath = `/${this._appId.split('.').join('/')}`;
 
         this._impl = Gio.DBusExportedObject.wrapJSObject(SearchProviderInterface, this);
         this._cancellable = new Gio.Cancellable();
@@ -68,24 +65,18 @@ var SearchProvider = GObject.registerClass({
                     log(`Failed to search by keywords: ${e.message}`);
                 }
                 invocation.return_value(new GLib.Variant('(as)', [characters]));
-
-                this._app.release();
             });
     }
 
     GetInitialResultSetAsync(params, invocation) {
-        this._app.hold();
         this._runQuery(params[0], invocation);
     }
 
     GetSubsearchResultSetAsync(params, invocation) {
-        this._app.hold();
         this._runQuery(params[1], invocation);
     }
 
     GetResultMetas(identifiers) {
-        this._app.hold();
-
         let ret = [];
 
         for (let i = 0; i < identifiers.length; i++) {
@@ -106,9 +97,6 @@ var SearchProvider = GObject.registerClass({
                 clipboardText: new GLib.Variant('s', character),
             });
         }
-
-        this._app.release();
-
         return ret;
     }
 
@@ -119,43 +107,10 @@ var SearchProvider = GObject.registerClass({
         this._app.send_notification(null, notification);
     }
 
-    _getPlatformData(timestamp) {
-        let display = Gdk.Display.get_default();
-        let context = display.get_app_launch_context();
-        context.set_timestamp(timestamp);
-
-        let app = Gio.DesktopAppInfo.new(`${this._appId}.desktop`);
-        let id = context.get_startup_notify_id(app, []);
-        return { 'desktop-startup-id': new GLib.Variant('s', id) };
-    }
-
-    _activateAction(action, parameter, timestamp) {
-        let wrappedParam;
-        if (parameter)
-            wrappedParam = [parameter];
-        else
-            wrappedParam = [];
-
-        Gio.DBus.session.call(this._appId,
-            this._appObjectPath,
-            'org.freedesktop.Application',
-            'ActivateAction',
-            new GLib.Variant('(sava{sv})', [action, wrappedParam,
-                this._getPlatformData(timestamp)]),
-            null,
-            Gio.DBusCallFlags.NONE,
-            -1, null, (connection, result) => {
-                try {
-                    connection.call_finish(result);
-                } catch (e) {
-                    log(`Failed to launch application: ${e.message}`);
-                }
-
-                this._app.release();
-            });
-    }
-
     LaunchSearch(terms, timestamp) {
-        this._activateAction('search', new GLib.Variant('as', terms), timestamp);
+        this._app.activate();
+        const window = this._app.window;
+        window.setSearchKeywords(terms);
+        window.presnt_with_time(timestamp);
     }
 });


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