[gnome-shell] inhibitShortcuts: Save choice in permission store
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] inhibitShortcuts: Save choice in permission store
- Date: Mon, 4 Mar 2019 09:22:34 +0000 (UTC)
commit 32b8bc39ac379c2f5db036f95a2e00a74480c3db
Author: Olivier Fourdan <ofourdan redhat com>
Date: Fri Feb 1 17:44:05 2019 +0100
inhibitShortcuts: Save choice in permission store
Use the permission store to remember the user's decision as to whether
or not grant the shortcuts request when the application is known.
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/382
js/ui/inhibitShortcutsDialog.js | 69 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 66 insertions(+), 3 deletions(-)
---
diff --git a/js/ui/inhibitShortcutsDialog.js b/js/ui/inhibitShortcutsDialog.js
index 46e760a98..170cd1a33 100644
--- a/js/ui/inhibitShortcutsDialog.js
+++ b/js/ui/inhibitShortcutsDialog.js
@@ -1,11 +1,16 @@
-const { Clutter, Gio, GObject, Gtk, Meta, Shell } = imports.gi;
+const { Clutter, Gio, GLib, GObject, Gtk, Meta, Shell } = imports.gi;
const Dialog = imports.ui.dialog;
const ModalDialog = imports.ui.modalDialog;
+const PermissionStore = imports.misc.permissionStore;
const WAYLAND_KEYBINDINGS_SCHEMA = 'org.gnome.mutter.wayland.keybindings';
const APP_WHITELIST = ['gnome-control-center.desktop'];
+const APP_PERMISSIONS_TABLE = 'gnome';
+const APP_PERMISSIONS_ID = 'shortcuts-inhibitor';
+const GRANTED = 'GRANTED';
+const DENIED = 'DENIED';
var DialogResponse = Meta.InhibitShortcutsDialogResponse;
@@ -43,6 +48,29 @@ var InhibitShortcutsDialog = GObject.registerClass({
Gtk.accelerator_parse(accel));
}
+ _shouldUsePermStore() {
+ return this._app && !this._app.is_window_backed();
+ }
+
+ _saveToPermissionStore(grant) {
+ if (!this._shouldUsePermStore() || this._permStore == null)
+ return;
+
+ let permissions = {};
+ permissions[this._app.get_id()] = [grant];
+ let data = GLib.Variant.new('av', {});
+
+ this._permStore.SetRemote(APP_PERMISSIONS_TABLE,
+ true,
+ APP_PERMISSIONS_ID,
+ permissions,
+ data,
+ (result, error) => {
+ if (error != null)
+ log(error.message);
+ });
+ }
+
_buildLayout() {
let name = this._app ? this._app.get_name() : this._window.title;
@@ -64,12 +92,14 @@ var InhibitShortcutsDialog = GObject.registerClass({
this._dialog.addButton({ label: _("Deny"),
action: () => {
+ this._saveToPermissionStore(DENIED);
this._emitResponse(DialogResponse.DENY);
},
key: Clutter.KEY_Escape });
this._dialog.addButton({ label: _("Allow"),
action: () => {
+ this._saveToPermissionStore(GRANTED);
this._emitResponse(DialogResponse.ALLOW);
},
default: true });
@@ -81,10 +111,43 @@ var InhibitShortcutsDialog = GObject.registerClass({
}
vfunc_show() {
- if (this._app && APP_WHITELIST.indexOf(this._app.get_id()) != -1)
+ if (this._app && APP_WHITELIST.indexOf(this._app.get_id()) != -1) {
this._emitResponse(DialogResponse.ALLOW);
- else
+ return;
+ }
+
+ if (!this._shouldUsePermStore()) {
this._dialog.open();
+ return;
+ }
+
+ /* Check with the permission store */
+ let appId = this._app.get_id();
+ this._permStore = new PermissionStore.PermissionStore((proxy, error) => {
+ if (error) {
+ log(error.message);
+ this._dialog.open();
+ return;
+ }
+
+ this._permStore.LookupRemote(APP_PERMISSIONS_TABLE,
+ APP_PERMISSIONS_ID,
+ (res, error) => {
+ if (error) {
+ this._dialog.open();
+ log(error.message);
+ return;
+ }
+
+ let [permissions, data] = res;
+ if (permissions[appId] === undefined) // Not found
+ this._dialog.open();
+ else if (permissions[appId] == GRANTED)
+ this._emitResponse(DialogResponse.ALLOW);
+ else
+ this._emitResponse(DialogResponse.DENY);
+ });
+ });
}
vfunc_hide() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]