status/location: Make AppAuthorizer async
Instead of passing a callback through a series of methods and callbacks, change authorize() to return its result asynchronously. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2344>
This commit is contained in:
parent
c6861c0a3d
commit
db3916434e
@ -110,17 +110,15 @@ var GeoclueAgent = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthorizeAppAsync(params, invocation) {
|
async AuthorizeAppAsync(params, invocation) {
|
||||||
let [desktopId, reqAccuracyLevel] = params;
|
let [desktopId, reqAccuracyLevel] = params;
|
||||||
|
|
||||||
let authorizer = new AppAuthorizer(desktopId,
|
let authorizer = new AppAuthorizer(desktopId,
|
||||||
reqAccuracyLevel, this._permStoreProxy, this.maxAccuracyLevel);
|
reqAccuracyLevel, this._permStoreProxy, this.maxAccuracyLevel);
|
||||||
|
|
||||||
authorizer.authorize(accuracyLevel => {
|
const accuracyLevel = await authorizer.authorize();
|
||||||
let ret = accuracyLevel != GeoclueAccuracyLevel.NONE;
|
const ret = accuracyLevel !== GeoclueAccuracyLevel.NONE;
|
||||||
invocation.return_value(GLib.Variant.new('(bu)',
|
invocation.return_value(GLib.Variant.new('(bu)', [ret, accuracyLevel]));
|
||||||
[ret, accuracyLevel]));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get MaxAccuracyLevel() {
|
get MaxAccuracyLevel() {
|
||||||
@ -232,29 +230,22 @@ var AppAuthorizer = class {
|
|||||||
this._accuracyLevel = GeoclueAccuracyLevel.NONE;
|
this._accuracyLevel = GeoclueAccuracyLevel.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
authorize(onAuthDone) {
|
async authorize() {
|
||||||
this._onAuthDone = onAuthDone;
|
|
||||||
|
|
||||||
let appSystem = Shell.AppSystem.get_default();
|
let appSystem = Shell.AppSystem.get_default();
|
||||||
this._app = appSystem.lookup_app(`${this.desktopId}.desktop`);
|
this._app = appSystem.lookup_app(`${this.desktopId}.desktop`);
|
||||||
if (this._app == null || this._permStoreProxy == null) {
|
if (this._app == null || this._permStoreProxy == null)
|
||||||
this._completeAuth();
|
return this._completeAuth();
|
||||||
|
|
||||||
return;
|
try {
|
||||||
}
|
[this._permissions] = await this._permStoreProxy.LookupAsync(
|
||||||
|
APP_PERMISSIONS_TABLE,
|
||||||
this._permStoreProxy.LookupRemote(APP_PERMISSIONS_TABLE,
|
APP_PERMISSIONS_ID);
|
||||||
APP_PERMISSIONS_ID,
|
} catch (error) {
|
||||||
this._onPermLookupDone.bind(this));
|
if (error.domain === Gio.DBusError) {
|
||||||
}
|
|
||||||
|
|
||||||
_onPermLookupDone(result, error) {
|
|
||||||
if (error != null) {
|
|
||||||
if (error.domain == Gio.DBusError) {
|
|
||||||
// Likely no xdg-app installed, just authorize the app
|
// Likely no xdg-app installed, just authorize the app
|
||||||
this._accuracyLevel = this.reqAccuracyLevel;
|
this._accuracyLevel = this.reqAccuracyLevel;
|
||||||
this._permStoreProxy = null;
|
this._permStoreProxy = null;
|
||||||
this._completeAuth();
|
return this._completeAuth();
|
||||||
} else {
|
} else {
|
||||||
// Currently xdg-app throws an error if we lookup for
|
// Currently xdg-app throws an error if we lookup for
|
||||||
// unknown ID (which would be the case first time this code
|
// unknown ID (which would be the case first time this code
|
||||||
@ -262,23 +253,20 @@ var AppAuthorizer = class {
|
|||||||
// and ID is added to the store if user says "yes".
|
// and ID is added to the store if user says "yes".
|
||||||
log(error.message);
|
log(error.message);
|
||||||
this._permissions = {};
|
this._permissions = {};
|
||||||
this._userAuthorizeApp();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[this._permissions] = result;
|
|
||||||
let permission = this._permissions[this.desktopId];
|
let permission = this._permissions[this.desktopId];
|
||||||
|
|
||||||
if (permission == null) {
|
if (permission == null) {
|
||||||
this._userAuthorizeApp();
|
await this._userAuthorizeApp();
|
||||||
} else {
|
} else {
|
||||||
let [levelStr] = permission || ['NONE'];
|
let [levelStr] = permission || ['NONE'];
|
||||||
this._accuracyLevel = GeoclueAccuracyLevel[levelStr] ||
|
this._accuracyLevel = GeoclueAccuracyLevel[levelStr] ||
|
||||||
GeoclueAccuracyLevel.NONE;
|
GeoclueAccuracyLevel.NONE;
|
||||||
this._completeAuth();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this._completeAuth();
|
||||||
}
|
}
|
||||||
|
|
||||||
_userAuthorizeApp() {
|
_userAuthorizeApp() {
|
||||||
@ -286,21 +274,18 @@ var AppAuthorizer = class {
|
|||||||
let appInfo = this._app.get_app_info();
|
let appInfo = this._app.get_app_info();
|
||||||
let reason = appInfo.get_locale_string("X-Geoclue-Reason");
|
let reason = appInfo.get_locale_string("X-Geoclue-Reason");
|
||||||
|
|
||||||
this._showAppAuthDialog(name, reason);
|
this._dialog =
|
||||||
}
|
new GeolocationDialog(name, reason, this.reqAccuracyLevel);
|
||||||
|
|
||||||
_showAppAuthDialog(name, reason) {
|
return new Promise(resolve => {
|
||||||
this._dialog = new GeolocationDialog(name,
|
const responseId = this._dialog.connect('response',
|
||||||
reason,
|
(dialog, level) => {
|
||||||
this.reqAccuracyLevel);
|
this._dialog.disconnect(responseId);
|
||||||
|
this._accuracyLevel = level;
|
||||||
let responseId = this._dialog.connect('response', (dialog, level) => {
|
resolve();
|
||||||
this._dialog.disconnect(responseId);
|
});
|
||||||
this._accuracyLevel = level;
|
this._dialog.open();
|
||||||
this._completeAuth();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this._dialog.open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_completeAuth() {
|
_completeAuth() {
|
||||||
@ -310,7 +295,7 @@ var AppAuthorizer = class {
|
|||||||
}
|
}
|
||||||
this._saveToPermissionStore();
|
this._saveToPermissionStore();
|
||||||
|
|
||||||
this._onAuthDone(this._accuracyLevel);
|
return this._accuracyLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
_saveToPermissionStore() {
|
_saveToPermissionStore() {
|
||||||
|
Loading…
Reference in New Issue
Block a user