diff --git a/.gitignore b/.gitignore index 485dee64..d44ee64e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +.history \ No newline at end of file diff --git a/src/img/logo-1.png b/src/img/logo-1.png new file mode 100644 index 00000000..494e4571 Binary files /dev/null and b/src/img/logo-1.png differ diff --git a/src/img/logo.png b/src/img/logo.png index 494e4571..e2f1ac96 100644 Binary files a/src/img/logo.png and b/src/img/logo.png differ diff --git a/src/js/_date-filter-directive.js b/src/js/_date-filter-directive.js index c1b9a9c9..4361f05d 100644 --- a/src/js/_date-filter-directive.js +++ b/src/js/_date-filter-directive.js @@ -1,5 +1,5 @@ /* - Copyright 2016 - 2022 Sunflower IT (http://sunflowerweb.nl) + Copyright 2016 - 2022 Therp (http://therp.nl) License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ diff --git a/src/js/_localstorage.js b/src/js/_localstorage.js index c029bccf..a4b64d9d 100644 --- a/src/js/_localstorage.js +++ b/src/js/_localstorage.js @@ -1,5 +1,5 @@ /* - Copyright 2016 - 2022 Sunflower IT (http://sunflowerweb.nl) + Copyright 2016 - 2022 Therp (http://therp.nl) License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ diff --git a/src/js/_main.js b/src/js/_main.js index 252320c6..7129682a 100755 --- a/src/js/_main.js +++ b/src/js/_main.js @@ -1,5 +1,5 @@ /* - Copyright 2016 - 2022 Sunflower IT (http://sunflowerweb.nl) + Copyright 2016 - 2022 Therp (http://therp.nl) License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ diff --git a/src/js/_sfit-readmore-directive.js b/src/js/_sfit-readmore-directive.js index 3670c9db..7d7f7403 100644 --- a/src/js/_sfit-readmore-directive.js +++ b/src/js/_sfit-readmore-directive.js @@ -1,5 +1,5 @@ /* - Copyright 2016 - 2022 Sunflower IT (http://sunflowerweb.nl) + Copyright 2016 - 2022 Therp (http://sunflowerweb.nl) License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ diff --git a/src/js/_utils.js b/src/js/_utils.js index 6bb956df..b336179c 100644 --- a/src/js/_utils.js +++ b/src/js/_utils.js @@ -1,5 +1,5 @@ /* - Copyright 2016 - 2022 Sunflower IT (http://sunflowerweb.nl) + Copyright 2016 - 2022 Therp (http://therp.nl) License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ diff --git a/src/js/background.js b/src/js/background.js index 07d39abb..67d49d83 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -1,32 +1,36 @@ -/* - Copyright 2016 - 2022 Sunflower IT (http://sunflowerweb.nl) - License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - */ +// ---- one API alias for Chrome/Firefox ---- +const api = (typeof chrome !== 'undefined' && chrome.runtime) + ? chrome // Chrome (and Chromium) + : (typeof browser !== 'undefined' ? browser : null); // Firefox -var online = "it is online"; -console.log(online); -var TogglButton = { - setBrowserAction: function (timer) { - console.log("TIMER CHECK:" + timer); - if (timer === true) { - var imagePath = {'19': 'img/icon_19.png', '38': 'img/icon_38.png'}; - } - else if (timer === 'pause') { - var imagePath = {'19': 'img/icon-pause.png', '38': 'img/icon-pause.png'}; - } - else { - var imagePath = {'19': 'img/inactive_19.png', '38': 'img/inactive_19.png'}; - } - browser.action.setIcon({ - path: imagePath, - }); - console.log("works"); - }, -}; -browser.runtime.onMessage.addListener(async (msg, sender) => { - console.log("BG page received message", msg, "from", sender); - console.log("Stored data", await browser.storage.local.get()); - TogglButton.setBrowserAction(msg.TimerActive); -}); +if (!api) throw new Error('No extension API found'); +// helpers +const R = api.runtime; +const A = api.action || api.browserAction; // MV3 uses action +const S = api.storage; +const url = (p) => R.getURL(p); // build extension-absolute URLs +const TogglButton = { + setBrowserAction(timer) { + console.log('TIMER CHECK:', timer); + let path; + if (timer === true || String(timer).toLowerCase() === 'true') { + path = { 19: url('img/icon_19.png'), 38: url('img/icon_38.png') }; + } else if (String(timer).toLowerCase() === 'pause') { + path = { 19: url('img/icon-pause.png'), 38: url('img/icon-pause.png') }; + } else { + path = { 19: url('img/inactive_19.png'), 38: url('img/inactive_38.png') }; + } + const p = A.setIcon({ path }); + if (p?.catch) p.catch(err => console.error('setIcon failed:', err)); + }, +}; + +// Message listener (works in both) +api.runtime.onMessage.addListener(async (msg, sender) => { + console.log('BG got message', msg, 'from', sender); + const data = await S?.local?.get?.(['TimerActive']); + console.log('Stored data', data); + TogglButton.setBrowserAction(msg?.TimerActive); +}); diff --git a/src/js/options_main_page.js b/src/js/options_main_page.js index 6c088094..9a2618ee 100644 --- a/src/js/options_main_page.js +++ b/src/js/options_main_page.js @@ -1,5 +1,5 @@ /* - Copyright 2016 - 2022 Sunflower IT (http://sunflowerweb.nl) + Copyright 2016 - 2022 Therp (http://therp.nl) License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ diff --git a/src/manifest.json b/src/manifest.json index 056e2e3c..31516f17 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -15,13 +15,13 @@ "default_title": "Therp Timer", "default_popup": "popup.html" }, - "devtools_page": "/devtools/devtools-page.html", "background": { "scripts": [ "/js/lib/browser-polyfill.js", "/js/lib/jquery-3.6.0.min.js", "/js/background.js" - ] + ], + "service_worker": "/js/background.js" }, "options_ui": { "page": "options_main_page.html" diff --git a/src/options_main_page.html b/src/options_main_page.html index 862e371a..1af1fca7 100644 --- a/src/options_main_page.html +++ b/src/options_main_page.html @@ -62,7 +62,7 @@

Description


- This is a cross-platform Sunflower IT Timer App that works in + This is a cross-platform Therp Timer App that works in Firefox, Opera and Chrome browsers with the aim of registering working hours of individual's issues/tasks based on Odoo timesheets.
@@ -94,7 +94,7 @@

Add Remote

type="text" ng-model="data.remote_host" type="text" class="form-control" id="remote-host" - placeholder="https://wwww.sunflowerweb.nl"> + placeholder="https://wwww.therp.nl">