Changeset View
Changeset View
Standalone View
Standalone View
extension/extension-purpose.js
Show All 11 Lines | 1 | /* | |||
---|---|---|---|---|---|
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. | ||
13 | 13 | | |||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | let purposeShareMenuId = "purpose_share"; | 18 | let purposeShareMenuId = "purpose_share"; | ||
19 | 19 | | |||
20 | // Stores <notification id, share url> so that when you click the finished | ||||
21 | // notification it will open the URL | ||||
22 | let purposeNotificationUrls = {}; | ||||
23 | | ||||
20 | function purposeShare(data) { | 24 | function purposeShare(data) { | ||
21 | return new Promise((resolve, reject) => { | 25 | return new Promise((resolve, reject) => { | ||
22 | sendPortMessageWithReply("purpose", "share", {data}).then((reply) => { | 26 | sendPortMessageWithReply("purpose", "share", {data}).then((reply) => { | ||
23 | if (!reply.success) { | 27 | if (!reply.success) { | ||
24 | if (!["BUSY", "CANCELED", "INVALID_ARGUMENT"].includes(reply.errorCode) | 28 | if (!["BUSY", "CANCELED", "INVALID_ARGUMENT"].includes(reply.errorCode) | ||
25 | && reply.errorCode !== 1 /*ERR_USER_CANCELED*/) { | 29 | && reply.errorCode !== 1 /*ERR_USER_CANCELED*/) { | ||
26 | chrome.notifications.create(null, { | 30 | chrome.notifications.create(null, { | ||
27 | type: "basic", | 31 | type: "basic", | ||
Show All 10 Lines | |||||
38 | 42 | | |||
39 | let url = reply.response.url; | 43 | let url = reply.response.url; | ||
40 | if (url) { | 44 | if (url) { | ||
41 | chrome.notifications.create(null, { | 45 | chrome.notifications.create(null, { | ||
42 | type: "basic", | 46 | type: "basic", | ||
43 | title: chrome.i18n.getMessage("purpose_share_finished_title"), | 47 | title: chrome.i18n.getMessage("purpose_share_finished_title"), | ||
44 | message: chrome.i18n.getMessage("purpose_share_finished_text", url), | 48 | message: chrome.i18n.getMessage("purpose_share_finished_text", url), | ||
45 | iconUrl: "icons/document-share.png" | 49 | iconUrl: "icons/document-share.png" | ||
50 | }, (notificationId) => { | ||||
51 | if (chrome.runtime.lastError) { | ||||
52 | return; | ||||
53 | } | ||||
54 | | ||||
55 | purposeNotificationUrls[notificationId] = url; | ||||
46 | }); | 56 | }); | ||
47 | } | 57 | } | ||
48 | 58 | | |||
49 | resolve(); | 59 | resolve(); | ||
50 | }); | 60 | }); | ||
51 | }); | 61 | }); | ||
52 | } | 62 | } | ||
53 | 63 | | |||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 108 | /*chrome.contextMenus.create({ | |||
99 | id: purposeShareMenuId, | 109 | id: purposeShareMenuId, | ||
100 | contexts: ["link", "page", "image", "audio", "video", "selection"], | 110 | contexts: ["link", "page", "image", "audio", "video", "selection"], | ||
101 | title: chrome.i18n.getMessage("purpose_share") | 111 | title: chrome.i18n.getMessage("purpose_share") | ||
102 | });*/ | 112 | });*/ | ||
103 | 113 | | |||
104 | addRuntimeCallback("purpose", "share", (message, sender, action) => { | 114 | addRuntimeCallback("purpose", "share", (message, sender, action) => { | ||
105 | return purposeShare(message); | 115 | return purposeShare(message); | ||
106 | }); | 116 | }); | ||
117 | | ||||
118 | chrome.notifications.onClicked.addListener((notificationId) => { | ||||
119 | const url = purposeNotificationUrls[notificationId]; | ||||
120 | if (url) { | ||||
121 | chrome.tabs.create({url}); | ||||
122 | } | ||||
123 | }); | ||||
124 | | ||||
125 | chrome.notifications.onClosed.addListener((notificationId) => { | ||||
126 | delete purposeNotificationUrls[notificationId]; | ||||
127 | }); |