Compare commits
6 Commits
Author | SHA1 | Date |
---|---|---|
Thomas Rupprecht | 7d1ecd166a | |
Thomas Rupprecht | e985995ddd | |
Thomas Rupprecht | 5682f2322b | |
Thomas Rupprecht | 5ea42bccb4 | |
Thomas Rupprecht | 82bcdef199 | |
Thomas Rupprecht | ad9abe3c94 |
|
@ -1,25 +1,25 @@
|
|||
{
|
||||
"name": "usrspace-browser-addon",
|
||||
"version": "0.9.0",
|
||||
"version": "0.9.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "usrspace-browser-addon",
|
||||
"version": "0.9.0",
|
||||
"version": "0.9.1",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"webextension-polyfill": "^0.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"web-ext-types": "^3.2.1"
|
||||
"@types/firefox-webext-browser": "^109.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/web-ext-types": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/web-ext-types/-/web-ext-types-3.2.1.tgz",
|
||||
"integrity": "sha512-oQZYDU3W8X867h8Jmt3129kRVKklz70db40Y6OzoTTuzOJpF/dB2KULJUf0txVPyUUXuyzV8GmT3nVvRHoG+Ew==",
|
||||
"node_modules/@types/firefox-webext-browser": {
|
||||
"version": "109.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/firefox-webext-browser/-/firefox-webext-browser-109.0.0.tgz",
|
||||
"integrity": "sha512-tkEjBP/zZxaS5bv8MH/0kUs3WeUm8KU3Ew1B9BtQQdq5PwtG23SXvAbjxjMSQpoIzbxyWG4Yu4mi1uB2S8W7ng==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/webextension-polyfill": {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "usrspace-browser-addon",
|
||||
"description": "WebExtension for the Hacker-/Maker-Space /usr/space",
|
||||
"version": "0.9.0",
|
||||
"version": "0.9.1",
|
||||
"dependencies": {
|
||||
"webextension-polyfill": "^0.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"web-ext-types": "^3.2.1"
|
||||
"@types/firefox-webext-browser": "^109.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"copy-browser-polyfill": "cp node_modules/webextension-polyfill/dist/browser-polyfill.js src/browser-polyfill.js",
|
||||
|
|
|
@ -49,6 +49,9 @@ function fetchSpaceApi() {
|
|||
}
|
||||
|
||||
async function fetchNewData() {
|
||||
if (!globalThis.navigator.onLine) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const result = await Promise.allSettled([fetchCalendar(), fetchSpaceApi()]);
|
||||
const calendarJson = result[0].value;
|
||||
|
@ -60,20 +63,11 @@ async function fetchNewData() {
|
|||
new Date(event.begin) <= now && now <= new Date(event.end)
|
||||
)) ?? false;
|
||||
|
||||
const badgeText = browser.i18n.getMessage(spaceApiJson.state.open ? 'badgeOpen' : eventActive ? 'badgeEvent' : 'badgeClosed');
|
||||
const badgeBgColor = spaceApiJson.state.open ? BADGE_COLORS.open : eventActive ? BADGE_COLORS.event : BADGE_COLORS.closed;
|
||||
await browser.action.setBadgeText({text: badgeText});
|
||||
await browser.action.setBadgeBackgroundColor({color: badgeBgColor});
|
||||
await setBadgeStatus(spaceApiJson.state.open, eventActive);
|
||||
|
||||
const {spaceApi} = await browser.storage.local.get('spaceApi');
|
||||
if (spaceApi && spaceApi.state.open !== spaceApiJson.state.open) {
|
||||
const state = browser.i18n.getMessage(spaceApiJson.state.open ? 'open' : 'closed');
|
||||
await browser.notifications.create('status-change', {
|
||||
type: 'basic',
|
||||
title: browser.i18n.getMessage('stateNotificationTitle'),
|
||||
message: browser.i18n.getMessage('stateNotificationMessage', state),
|
||||
iconUrl: browser.runtime.getURL('icons/favicon.svg'),
|
||||
});
|
||||
await createStatusChangedNotification(spaceApiJson.state.open);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,6 +80,30 @@ async function fetchNewData() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} open
|
||||
* @param {boolean} eventActive
|
||||
*/
|
||||
async function setBadgeStatus(open, eventActive) {
|
||||
const badgeText = browser.i18n.getMessage(open ? 'badgeOpen' : eventActive ? 'badgeEvent' : 'badgeClosed');
|
||||
const badgeBgColor = open ? BADGE_COLORS.open : eventActive ? BADGE_COLORS.event : BADGE_COLORS.closed;
|
||||
await browser.action.setBadgeText({text: badgeText});
|
||||
await browser.action.setBadgeBackgroundColor({color: badgeBgColor});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} open
|
||||
*/
|
||||
async function createStatusChangedNotification(open) {
|
||||
const stateL10n = browser.i18n.getMessage(open ? 'open' : 'closed');
|
||||
await browser.notifications.create('status-changed', {
|
||||
type: 'basic',
|
||||
title: browser.i18n.getMessage('stateNotificationTitle'),
|
||||
message: browser.i18n.getMessage('stateNotificationMessage', stateL10n),
|
||||
iconUrl: browser.runtime.getURL('icons/favicon.svg'),
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
fetchNewData();
|
||||
|
||||
|
|
|
@ -23,13 +23,18 @@ export const QUICK_LINKS = [
|
|||
text: 'Wiki',
|
||||
},
|
||||
{
|
||||
iconTemplateId: 'template-icon-gitea',
|
||||
iconTemplateId: 'template-icon-git',
|
||||
url: 'https://gitea.usrspace.at/',
|
||||
text: 'Gitea',
|
||||
text: 'Git',
|
||||
},
|
||||
{
|
||||
iconTemplateId: 'template-icon-nextcloud',
|
||||
iconTemplateId: 'template-icon-cloud',
|
||||
url: 'https://cloud.usrspace.at/',
|
||||
text: 'Nextcloud',
|
||||
text: 'Cloud',
|
||||
},
|
||||
{
|
||||
iconTemplateId: 'template-icon-pad',
|
||||
url: 'https://pads.usrspace.at/',
|
||||
text: 'Pad',
|
||||
},
|
||||
];
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"manifest_version": 3,
|
||||
"name": "__MSG_extensionName__",
|
||||
"description": "__MSG_extensionDescription__",
|
||||
"version": "0.9.0",
|
||||
"version": "0.9.1",
|
||||
"icons": {
|
||||
"48": "icons/favicon.svg",
|
||||
"96": "icons/favicon.svg"
|
||||
|
|
|
@ -33,16 +33,21 @@
|
|||
<path d="M640 51.2l-.3 12.2c-28.1.8-45 15.8-55.8 40.3-25 57.8-103.3 240-155.3 358.6H415l-81.9-193.1c-32.5 63.6-68.3 130-99.2 193.1-.3.3-15 0-15-.3C172 352.3 122.8 243.4 75.8 133.4 64.4 106.7 26.4 63.4.2 63.7c0-3.1-.3-10-.3-14.2h161.9v13.9c-19.2 1.1-52.8 13.3-43.3 34.2 21.9 49.7 103.6 240.3 125.6 288.6 15-29.7 57.8-109.2 75.3-142.8-13.9-28.3-58.6-133.9-72.8-160-9.7-17.8-36.1-19.4-55.8-19.7V49.8l142.5.3v13.1c-19.4.6-38.1 7.8-29.4 26.1 18.9 40 30.6 68.1 48.1 104.7 5.6-10.8 34.7-69.4 48.1-100.8 8.9-20.6-3.9-28.6-38.6-29.4.3-3.6 0-10.3.3-13.6 44.4-.3 111.1-.3 123.1-.6v13.6c-22.5.8-45.8 12.8-58.1 31.7l-59.2 122.8c6.4 16.1 63.3 142.8 69.2 156.7L559.2 91.8c-8.6-23.1-36.4-28.1-47.2-28.3V49.6l127.8 1.1.2.5z"/>
|
||||
</svg>
|
||||
</template>
|
||||
<template id="template-icon-gitea">
|
||||
<template id="template-icon-git">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="19" height="19" fill="currentColor" viewBox="0 0 16 16" role="img" aria-label="">
|
||||
<path d="M15.698 7.287 8.712.302a1.03 1.03 0 0 0-1.457 0l-1.45 1.45 1.84 1.84a1.223 1.223 0 0 1 1.55 1.56l1.773 1.774a1.224 1.224 0 0 1 1.267 2.025 1.226 1.226 0 0 1-2.002-1.334L8.58 5.963v4.353a1.226 1.226 0 1 1-1.008-.036V5.887a1.226 1.226 0 0 1-.666-1.608L5.093 2.465l-4.79 4.79a1.03 1.03 0 0 0 0 1.457l6.986 6.986a1.03 1.03 0 0 0 1.457 0l6.953-6.953a1.031 1.031 0 0 0 0-1.457"/>
|
||||
</svg>
|
||||
</template>
|
||||
<template id="template-icon-nextcloud">
|
||||
<template id="template-icon-cloud">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="19" height="19" fill="currentColor" viewBox="0 0 16 16" role="img" aria-label="">
|
||||
<path d="M4.406 3.342A5.53 5.53 0 0 1 8 2c2.69 0 4.923 2 5.166 4.579C14.758 6.804 16 8.137 16 9.773 16 11.569 14.502 13 12.687 13H3.781C1.708 13 0 11.366 0 9.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383z"/>
|
||||
</svg>
|
||||
</template>
|
||||
<template id="template-icon-pad">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="19" height="19" fill="currentColor" viewBox="0 0 16 16" role="img" aria-label="">
|
||||
<path fill-rule="evenodd" d="M8 0c-.69 0-1.843.265-2.928.56-1.11.3-2.229.655-2.887.87a1.54 1.54 0 0 0-1.044 1.262c-.596 4.477.787 7.795 2.465 9.99a11.777 11.777 0 0 0 2.517 2.453c.386.273.744.482 1.048.625.28.132.581.24.829.24s.548-.108.829-.24a7.159 7.159 0 0 0 1.048-.625 11.775 11.775 0 0 0 2.517-2.453c1.678-2.195 3.061-5.513 2.465-9.99a1.541 1.541 0 0 0-1.044-1.263 62.467 62.467 0 0 0-2.887-.87C9.843.266 8.69 0 8 0zm0 5a1.5 1.5 0 0 1 .5 2.915l.385 1.99a.5.5 0 0 1-.491.595h-.788a.5.5 0 0 1-.49-.595l.384-1.99A1.5 1.5 0 0 1 8 5z"/>
|
||||
</svg>
|
||||
</template>
|
||||
<template id="template-link-item">
|
||||
<li class="panel-list-item link" data-url="">
|
||||
<div class="icon"></div>
|
||||
|
|
|
@ -63,7 +63,7 @@ async function init() {
|
|||
updateState(spaceApi);
|
||||
}
|
||||
}
|
||||
init();
|
||||
await init();
|
||||
|
||||
/**
|
||||
* @param {Array<object>} nextEvents
|
||||
|
|
Loading…
Reference in New Issue