Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bashgeek committed Dec 21, 2024
1 parent ed2f621 commit 018ff86
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 19 deletions.
Binary file modified bun.lockb
Binary file not shown.
8 changes: 3 additions & 5 deletions dist/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
}

/*
! tailwindcss v3.4.16 | MIT License | https://tailwindcss.com
! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com
*/

/*
Expand Down Expand Up @@ -2231,8 +2231,7 @@ input.tab:checked + .tab-content,

.progress::-moz-progress-bar {
border-radius: var(--rounded-box, 1rem);
--tw-bg-opacity: 1;
background-color: var(--fallback-bc,oklch(var(--bc)/var(--tw-bg-opacity)));
background-color: currentColor;
}

.progress:indeterminate {
Expand All @@ -2256,8 +2255,7 @@ input.tab:checked + .tab-content,

.progress::-webkit-progress-value {
border-radius: var(--rounded-box, 1rem);
--tw-bg-opacity: 1;
background-color: var(--fallback-bc,oklch(var(--bc)/var(--tw-bg-opacity)));
background-color: currentColor;
}

.progress:indeterminate::-moz-progress-bar {
Expand Down
38 changes: 29 additions & 9 deletions inc/background.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
const bg = {
init: function () {
icingaData.init();
bg.refresh();

if (typeof chrome !== 'undefined') {
chrome.alarms.onAlarm.addListener(() => {
bg.refresh();
});
chrome.alarms.onAlarm.removeListener(bg.refreshAlarm);
chrome.alarms.onAlarm.addListener(bg.refreshAlarm);
} else {
browser.alarms.onAlarm.addListener(() => {
bg.refresh();
});
browser.alarms.onAlarm.removeListener(bg.refreshAlarm);
browser.alarms.onAlarm.addListener(bg.refreshAlarm);
}

bg.refresh();
},

// Refresh method for alarm
refreshAlarm: function (alarm) {
if (alarm.name !== 'icinga-refresh') {
return;
}

bg.refresh();
},

// Refresh data for all icinga instances
Expand All @@ -38,9 +46,21 @@ const bg = {
let interval_in_seconds = (settings.refresh === undefined) ? 30 : settings.refresh;
let interval_in_minutes = interval_in_seconds / 60;
if (typeof chrome !== 'undefined') {
chrome.alarms.create('icinga-refresh', {delayInMinutes: interval_in_minutes});
chrome.alarms.get('icinga-refresh', alarm => {
if (alarm) {
return;
}

chrome.alarms.create('icinga-refresh', {delayInMinutes: interval_in_minutes});
});
} else {
browser.alarms.create('icinga-refresh', {delayInMinutes: interval_in_minutes});
browser.alarms.get('icinga-refresh', alarm => {
if (alarm) {
return;
}

browser.alarms.create('icinga-refresh', {delayInMinutes: interval_in_minutes});
});
}
});
},
Expand Down
32 changes: 31 additions & 1 deletion inc/background_script.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
function isExtensionStartup() {
if (!browser.storage.session) return Promise.resolve(true);
return new Promise(resolve => {
return browser.storage.session.get('hasAlreadyStarted', v => {
resolve(v.hasAlreadyStarted !== true);
});
});
}

bg.init();
function setHasAlreadyStarted() {
if (!browser.storage.session) return;
browser.storage.session.set({
hasAlreadyStarted: true,
});
}

browser.runtime.onStartup.addListener(() => {
bg.init();
});

browser.runtime.onInstalled.addListener(details => {
if (details.reason === 'install' || details.reason === 'update') {
bg.init();
}
});

isExtensionStartup().then(isStartup => {
if (isStartup) {
bg.init();
setHasAlreadyStarted();
}
});
34 changes: 33 additions & 1 deletion inc/service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,36 @@ importScripts('icinga.js');
importScripts('data.js');
importScripts('background.js');

bg.init();
function isExtensionStartup() {
if (!chrome.storage.session) return Promise.resolve(true);
return new Promise(resolve => {
return chrome.storage.session.get('hasAlreadyStarted', v => {
resolve(v.hasAlreadyStarted !== true);
});
});
}

function setHasAlreadyStarted() {
if (!chrome.storage.session) return;
chrome.storage.session.set({
hasAlreadyStarted: true,
});
}

chrome.runtime.onStartup.addListener(() => {
bg.init();
});

chrome.runtime.onInstalled.addListener(details => {
if (details.reason === 'install' || details.reason === 'update') {
bg.init();
}
});

isExtensionStartup().then(isStartup => {
if (isStartup) {
bg.init();
setHasAlreadyStarted();
}
});

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "Icinga Multi Status",
"short_name": "Icinga Multi Status",
"version": "1.0.2",
"version": "1.0.3",
"description": "Icinga Multi Status helps you monitor your Icinga instances with alert badges and notifications about incidents.",
"author": "Daniel Schmitz, bashgeek.net",

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "npx tailwindcss -i ./src/style.css -o ./dist/style.css"
},
"devDependencies": {
"daisyui": "^4.12.20",
"tailwindcss": "^3.4.16"
"daisyui": "^4.12.22",
"tailwindcss": "^3.4.17"
}
}

0 comments on commit 018ff86

Please sign in to comment.