diff --git a/background.js b/background.js index 3c8a881..de5fc60 100644 --- a/background.js +++ b/background.js @@ -2,6 +2,26 @@ const reData = new RegExp('^data:(.*?);base64,(.*)$'); +const idleIcon = { + path: { + 16: 'icons/idle-16.png', + 48: 'icons/idle-48.png', + 64: 'icons/idle-64.png', + 128: 'icons/idle-128.png', + 256: 'icons/idle-256.png', + }, +} + +const activeIcon = { + path: { + 16: 'icons/active-16.png', + 48: 'icons/active-48.png', + 64: 'icons/active-64.png', + 128: 'icons/active-128.png', + 256: 'icons/active-256.png', + }, +} + async function handleClick(tab, e) { if (e.modifiers.includes('Shift')) { await sendPaste(); @@ -22,14 +42,12 @@ async function handleClick(tab, e) { noteParts.push(''); - const store = {}; - store[`create_${crypto.randomUUID()}`] = { + await queue('create', { name: tab.title, html_notes: noteParts.join(''), attach: imgURL, filename: 'screenshot.png', - }; - await browser.storage.local.set(store); + }); if (!e.modifiers.includes('Command')) { browser.tabs.remove([tab.id]); @@ -39,12 +57,10 @@ async function handleClick(tab, e) { async function sendPaste() { const clip = await navigator.clipboard.readText(); - const store = {}; - store[`create_${crypto.randomUUID()}`] = { + await queue('create', { name: 'Paste', html_notes: `${escapeHTML(clip)}`, - }; - await browser.storage.local.set(store); + }); } let inHandleChange = false; @@ -68,6 +84,7 @@ async function handleChangeInt(e) { const keys = Object.getOwnPropertyNames(queue); if (keys.length == 0) { + browser.browserAction.setIcon(idleIcon); return; } @@ -115,13 +132,11 @@ async function create(cfg, task) { const create = await createResp.json(); if (task.attach) { - const store = {}; - store[`attach_${crypto.randomUUID()}`] = { + await queue('attach', { gid: create.data.gid, attach: task.attach, filename: task.filename, - }; - await browser.storage.local.set(store); + }); } } @@ -147,6 +162,14 @@ async function attach(cfg, task) { } } +async function queue(type, details) { + browser.browserAction.setIcon(activeIcon); + + const store = {}; + store[`${type}_${crypto.randomUUID()}`] = details; + await browser.storage.local.set(store); +} + async function getSelectedText(tabId) { const selecteds = await browser.tabs.executeScript( tabId, diff --git a/icons/active-128.png b/icons/active-128.png new file mode 100644 index 0000000..d4aa2c4 Binary files /dev/null and b/icons/active-128.png differ diff --git a/icons/active-16.png b/icons/active-16.png new file mode 100644 index 0000000..024c24d Binary files /dev/null and b/icons/active-16.png differ diff --git a/icons/active-256.png b/icons/active-256.png new file mode 100644 index 0000000..f33097f Binary files /dev/null and b/icons/active-256.png differ diff --git a/icons/active-48.png b/icons/active-48.png new file mode 100644 index 0000000..3c835a2 Binary files /dev/null and b/icons/active-48.png differ diff --git a/icons/active-64.png b/icons/active-64.png new file mode 100644 index 0000000..c90a181 Binary files /dev/null and b/icons/active-64.png differ diff --git a/icons/asana.png b/icons/asana.png deleted file mode 100644 index e47a612..0000000 Binary files a/icons/asana.png and /dev/null differ diff --git a/icons/idle-128.png b/icons/idle-128.png new file mode 100644 index 0000000..e6511fe Binary files /dev/null and b/icons/idle-128.png differ diff --git a/icons/idle-16.png b/icons/idle-16.png new file mode 100644 index 0000000..4cafe97 Binary files /dev/null and b/icons/idle-16.png differ diff --git a/icons/idle-256.png b/icons/idle-256.png new file mode 100644 index 0000000..baeaa70 Binary files /dev/null and b/icons/idle-256.png differ diff --git a/icons/idle-48.png b/icons/idle-48.png new file mode 100644 index 0000000..b5992fd Binary files /dev/null and b/icons/idle-48.png differ diff --git a/icons/idle-64.png b/icons/idle-64.png new file mode 100644 index 0000000..5213ab5 Binary files /dev/null and b/icons/idle-64.png differ diff --git a/manifest.json b/manifest.json index 1d619f2..5f276e9 100644 --- a/manifest.json +++ b/manifest.json @@ -1,30 +1,40 @@ { - "manifest_version": 2, - "name": "Quick Asana", - "version": "0.1", - "icons": { - "48": "icons/asana.png" - }, + "manifest_version": 2, + "name": "Quick Asana", + "version": "0.1", + "icons": { + "16": "icons/idle-16.png", + "48": "icons/idle-48.png", + "64": "icons/idle-64.png", + "128": "icons/idle-128.png", + "256": "icons/idle-256.png" + }, - "permissions": [ - "clipboardRead", - "storage", - "unlimitedStorage", - "" - ], + "permissions": [ + "clipboardRead", + "storage", + "unlimitedStorage", + "" + ], - "browser_action": { - "default_icon": "icons/asana.png", - "default_title": "Quick Asana" - }, + "browser_action": { + "default_icon": { + "16": "icons/idle-16.png", + "48": "icons/idle-48.png", + "64": "icons/idle-64.png", + "128": "icons/idle-128.png", + "256": "icons/idle-256.png" + }, + "default_title": "Quick Asana" + }, - "background": { - "scripts": ["background.js"] - }, + "background": { + "scripts": ["background.js"] + }, - "browser_specific_settings": { - "gecko": { - "id": "{073d8528-4b24-11ed-9b73-c71d3da4ab37}" - } - } + "browser_specific_settings": { + "gecko": { + "id": "{073d8528-4b24-11ed-9b73-c71d3da4ab37}" + } + } }