-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: offline support with service worker caching (#141)
- Loading branch information
Showing
31 changed files
with
1,242 additions
and
125 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,9 @@ | |
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
|
||
<!-- Base styles for better consistency across platforms (aka. CSS reset). --> | ||
<link rel="stylesheet" type="text/css" href="../normalize.css" /> | ||
|
||
<!-- Custom styles. --> | ||
<link rel="stylesheet" type="text/css" href="./styles.css" /> | ||
|
||
<!-- Add empty favicon to suppress not found errors. --> | ||
<link rel="icon" href="data:;" /> | ||
|
||
<!-- Allows React to be run buildless via "text/babel" script below. --> | ||
<script | ||
src="https://unpkg.com/@babel/[email protected]/babel.min.js" | ||
|
@@ -52,7 +46,7 @@ | |
return ( | ||
<div className="app"> | ||
{output.audio?.defaultPlaybackDevice && ( | ||
<div class="chip"> | ||
<div className="chip"> | ||
{output.audio.defaultPlaybackDevice.name}- | ||
{output.audio.defaultPlaybackDevice.volume} | ||
<input | ||
|
@@ -67,7 +61,7 @@ | |
/> | ||
</div> | ||
)} | ||
<div class="chip"> | ||
<div className="chip"> | ||
Media: {output.media?.currentSession?.title}- | ||
{output.media?.currentSession?.artist} | ||
<button onClick={() => output.media?.togglePlayPause()}> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,9 @@ | |
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
|
||
<!-- Base styles for better consistency across platforms (aka. CSS reset). --> | ||
<link rel="stylesheet" type="text/css" href="../normalize.css" /> | ||
|
||
<!-- Custom styles. --> | ||
<link rel="stylesheet" type="text/css" href="./styles.css" /> | ||
|
||
<!-- Add empty favicon to suppress not found errors. --> | ||
<link rel="icon" href="data:;" /> | ||
|
||
<!-- Allows React to be run buildless via "text/babel" script below. --> | ||
<script | ||
src="https://unpkg.com/@babel/[email protected]/babel.min.js" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,9 @@ | |
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
|
||
<!-- Base styles for better consistency across platforms (aka. CSS reset). --> | ||
<link rel="stylesheet" type="text/css" href="../normalize.css" /> | ||
|
||
<!-- Custom styles. --> | ||
<link rel="stylesheet" type="text/css" href="./styles.css" /> | ||
|
||
<!-- Add empty favicon to suppress not found errors. --> | ||
<link rel="icon" href="data:;" /> | ||
|
||
<!-- Allows React to be run buildless via "text/babel" script below. --> | ||
<script | ||
src="https://unpkg.com/@babel/[email protected]/babel.min.js" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,9 @@ | |
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
|
||
<!-- Base styles for better consistency across platforms (aka. CSS reset). --> | ||
<link rel="stylesheet" type="text/css" href="../normalize.css" /> | ||
|
||
<!-- Custom styles. --> | ||
<link rel="stylesheet" type="text/css" href="./styles.css" /> | ||
|
||
<!-- Add empty favicon to suppress not found errors. --> | ||
<link rel="icon" href="data:;" /> | ||
|
||
<!-- Allows React to be run buildless via "text/babel" script below. --> | ||
<script | ||
src="https://unpkg.com/@babel/[email protected]/babel.min.js" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './monitor-selection'; | ||
export * from './dock-config'; | ||
export * from './widget-caching'; | ||
export * from './widget-config'; | ||
export * from './widget-placement'; | ||
export * from './widget-preset'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type WidgetCaching = { | ||
defaultDuration: number; | ||
rules: WidgetCachingRule[]; | ||
}; | ||
|
||
export type WidgetCachingRule = { | ||
urlRegex: string; | ||
duration: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
if (window.location.host === '127.0.0.1:6124') { | ||
if ('serviceWorker' in navigator) { | ||
navigator.serviceWorker | ||
.register('/__zebar/sw.js', { scope: '/' }) | ||
.then(sw => { | ||
console.log('[Zebar] Service Worker registered.'); | ||
|
||
const message = { | ||
type: 'SET_CONFIG', | ||
config: window.__ZEBAR_STATE.config.caching, | ||
}; | ||
|
||
sw.active?.postMessage(message); | ||
sw.installing?.postMessage(message); | ||
sw.waiting?.postMessage(message); | ||
}) | ||
.catch(err => | ||
console.error('[Zebar] Service Worker failed to register:', err), | ||
); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
addFavicon(); | ||
loadCss('/__zebar/normalize.css'); | ||
}); | ||
} | ||
|
||
/** | ||
* Adds a CSS file with the given path to the head element. | ||
*/ | ||
function loadCss(path) { | ||
const link = document.createElement('link'); | ||
link.setAttribute('data-zebar', ''); | ||
link.rel = 'stylesheet'; | ||
link.type = 'text/css'; | ||
link.href = path; | ||
insertIntoHead(link); | ||
} | ||
|
||
/** | ||
* Adds a favicon to the head element if one is not already present. | ||
*/ | ||
function addFavicon() { | ||
if (!document.querySelector('link[rel="icon"]')) { | ||
const link = document.createElement('link'); | ||
link.setAttribute('data-zebar', ''); | ||
link.rel = 'icon'; | ||
link.href = 'data:;'; | ||
insertIntoHead(link); | ||
} | ||
} | ||
|
||
/** | ||
* Inserts the element before any other resource tags in the head element. | ||
* Ensures that user-defined stylesheets or favicons are prioritized over | ||
* Zebar's defaults. | ||
*/ | ||
function insertIntoHead(element) { | ||
const resources = document.head.querySelectorAll('link, script, style'); | ||
const target = resources[0]?.previousElementSibling; | ||
|
||
if (target) { | ||
target.after(element); | ||
} else { | ||
document.head.appendChild(element); | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.