Pass styleInfo trough usw's hook

Related commit on USW: 461ddb03c7
This commit is contained in:
Gusted 2021-06-05 17:11:18 +02:00
parent 921da08317
commit b115e1c2d4
No known key found for this signature in database
GPG Key ID: FD821B732837125F
3 changed files with 13 additions and 9 deletions

View File

@ -360,9 +360,12 @@ const styleMan = (() => {
}
switch (reason) {
case 'link':
style._linking = true;
saveStyle(style);
style._usw = {
token: await tokenMan.getToken('userstylesworld', true, style),
};
delete style._linking;
for (const [k, v] of Object.entries(await retrieveStyleInformation(style._usw.token))) {
style._usw[k] = v;
}

View File

@ -92,11 +92,8 @@ const tokenMan = (() => {
if (!interactive) {
throw new Error(`Invalid token: ${name}`);
}
const styleInformation = name === 'userstylesworld' ? JSON.stringify({
'code': style.sourceCode,
'name': style.name,
}) : null;
return authUser(name, k, interactive, styleInformation);
const accessToken = authUser(name, k, interactive);
return accessToken;
},
async revokeToken(name, styleId) {
@ -136,7 +133,7 @@ const tokenMan = (() => {
return handleTokenResult(result, k);
}
async function authUser(name, k, interactive = false, styleInformation = null) {
async function authUser(name, k, interactive = false) {
await require(['/vendor/webext-launch-web-auth-flow/webext-launch-web-auth-flow.min']);
/* global webextLaunchWebAuthFlow */
const provider = AUTH[name];
@ -147,9 +144,6 @@ const tokenMan = (() => {
redirect_uri: provider.redirect_uri || chrome.identity.getRedirectURL(),
state,
};
if (styleInformation) {
query['styleInfo'] = styleInformation;
}
if (provider.scopes) {
query.scope = provider.scopes.join(' ');
}

View File

@ -1,3 +1,4 @@
/* global API */// msg.js
'use strict';
(() => {
@ -18,5 +19,11 @@
}
};
if (window.location.pathname === '/api/oauth/authorize_style/new') {
API.styles.find({_linking: true}).then(style => {
sendPostMessage({type: 'usw-fill-new-style', data: style});
});
}
window.addEventListener('message', onPageLoaded);
})();