From b1d7e4caf3cf8a8c8dffff8b3476eab72e4be1c1 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sat, 5 Jun 2021 18:20:43 +0200 Subject: [PATCH] Adjusted behavior Applied suggestions from Narco. --- _locales/en/messages.json | 10 ++---- background/style-manager.js | 40 +++++++++++---------- edit.html | 17 ++++----- edit/edit.js | 7 ++-- edit/{usw-linking.js => usw-integration.js} | 23 ++++-------- 5 files changed, 41 insertions(+), 56 deletions(-) rename edit/{usw-linking.js => usw-integration.js} (60%) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 8cb8f725..f8699dcc 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1365,17 +1365,13 @@ "message": "Sections", "description": "Header for the table of contents block listing style section names in the left panel of the classic editor" }, - "linking": { + "integration": { "message": "UserStyles.world integration", "description": "Header for the section to link the style with userStyles.world" }, - "linkStyle": { - "message": "Link Style", - "description": "Link the current style with userstyles.world" - }, "uploadStyle": { - "message": "Upload Style", - "description": "Upload the current style to userstyles.world" + "message": "Publish Style", + "description": "Publish the current style to userstyles.world" }, "revokeLink": { "message": "Revoke Link", diff --git a/background/style-manager.js b/background/style-manager.js index eb814945..53d22a1f 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -56,7 +56,7 @@ const styleMan = (() => { let ready = init(); chrome.runtime.onConnect.addListener(handleLivePreview); - chrome.runtime.onConnect.addListener(handleLinkingUSW); + chrome.runtime.onConnect.addListener(handlePublishingUSW); //#endregion //#region Exports @@ -349,7 +349,7 @@ const styleMan = (() => { }); } - function handleLinkingUSW(port) { + function handlePublishingUSW(port) { if (port.name !== 'link-style-usw') { return; } @@ -359,28 +359,32 @@ const styleMan = (() => { return; } 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; - } - handleSave(await saveStyle(style), 'success-linking', true); - break; - case 'revoke': await tokenMan.revokeToken('userstylesworld', style.id); style._usw = {}; handleSave(await saveStyle(style), 'success-revoke', true); break; - case 'upload': - if (!style._usw.token) { - return; + case 'publish': + if (!style._usw || !style._usw.token) { + style._linking = true; + await saveStyle(style); + const data = id2data(style.id); + if (!data) { + storeInMap(style); + } else { + data.style = 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; + } + handleSave(await saveStyle(style), 'success-publishing', true); } uploadStyle(style); break; diff --git a/edit.html b/edit.html index c4aad8ca..a48f96f9 100644 --- a/edit.html +++ b/edit.html @@ -59,7 +59,7 @@ - +