Skip to content

Commit

Permalink
Merge branch 'main' into pause-button
Browse files Browse the repository at this point in the history
  • Loading branch information
michidk authored Dec 16, 2024
2 parents e85f943 + 844b132 commit f02cb00
Show file tree
Hide file tree
Showing 32 changed files with 1,243 additions and 125 deletions.
386 changes: 386 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/boilerplate-react-buildless/example.zebar.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://github.com/glzr-io/zebar/raw/v2.4.0/resources/widget-schema.json",
"$schema": "https://github.com/glzr-io/zebar/raw/v2.7.0/resources/widget-schema.json",
"htmlPath": "./index.html",
"zOrder": "normal",
"shownInTaskbar": false,
Expand Down
10 changes: 2 additions & 8 deletions examples/boilerplate-react-buildless/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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/standalone@7.25.6/babel.min.js"
Expand Down Expand Up @@ -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
Expand All @@ -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()}>
Expand Down
2 changes: 1 addition & 1 deletion examples/boilerplate-solid-ts/example.zebar.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://github.com/glzr-io/zebar/raw/v2.4.0/resources/widget-schema.json",
"$schema": "https://github.com/glzr-io/zebar/raw/v2.7.0/resources/widget-schema.json",
"htmlPath": "./dist/index.html",
"zOrder": "normal",
"shownInTaskbar": false,
Expand Down
1 change: 0 additions & 1 deletion examples/boilerplate-solid-ts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<title>Zebar</title>
<link rel="stylesheet" type="text/css" href="../normalize.css" />
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
6 changes: 0 additions & 6 deletions examples/starter/vanilla.html
Original file line number Diff line number Diff line change
Expand Up @@ -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/standalone@7.25.6/babel.min.js"
Expand Down
2 changes: 1 addition & 1 deletion examples/starter/vanilla.zebar.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://github.com/glzr-io/zebar/raw/v2.4.0/resources/widget-schema.json",
"$schema": "https://github.com/glzr-io/zebar/raw/v2.7.0/resources/widget-schema.json",
"htmlPath": "./vanilla.html",
"zOrder": "normal",
"shownInTaskbar": false,
Expand Down
6 changes: 0 additions & 6 deletions examples/starter/with-glazewm.html
Original file line number Diff line number Diff line change
Expand Up @@ -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/standalone@7.25.6/babel.min.js"
Expand Down
2 changes: 1 addition & 1 deletion examples/starter/with-glazewm.zebar.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://github.com/glzr-io/zebar/raw/v2.4.0/resources/widget-schema.json",
"$schema": "https://github.com/glzr-io/zebar/raw/v2.7.0/resources/widget-schema.json",
"htmlPath": "./with-glazewm.html",
"zOrder": "normal",
"shownInTaskbar": false,
Expand Down
6 changes: 0 additions & 6 deletions examples/starter/with-komorebi.html
Original file line number Diff line number Diff line change
Expand Up @@ -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/standalone@7.25.6/babel.min.js"
Expand Down
2 changes: 1 addition & 1 deletion examples/starter/with-komorebi.zebar.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://github.com/glzr-io/zebar/raw/v2.4.0/resources/widget-schema.json",
"$schema": "https://github.com/glzr-io/zebar/raw/v2.7.0/resources/widget-schema.json",
"htmlPath": "./with-komorebi.html",
"zOrder": "normal",
"shownInTaskbar": false,
Expand Down
1 change: 1 addition & 0 deletions packages/client-api/src/config/index.ts
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';
9 changes: 9 additions & 0 deletions packages/client-api/src/config/widget-caching.ts
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;
};
2 changes: 2 additions & 0 deletions packages/client-api/src/config/widget-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { WidgetCaching } from './widget-caching';
import type { WidgetPreset } from './widget-preset';

export type WidgetConfig = {
Expand All @@ -7,5 +8,6 @@ export type WidgetConfig = {
focused: boolean;
resizable: boolean;
transparent: boolean;
caching: WidgetCaching;
presets: WidgetPreset[];
};
1 change: 1 addition & 0 deletions packages/client-api/src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './audio/audio-provider-types';
export * from './battery/battery-provider-types';
export * from './cpu/cpu-provider-types';
export * from './date/date-provider-types';
Expand Down
14 changes: 8 additions & 6 deletions packages/desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ async-trait = "0.1"
base64 = "0.22"
clap = { version = "4", features = ["derive"] }
crossbeam = "0.8"
netdev = "0.24"
regex = "1"
reqwest = { version = "0.11", features = ["json"] }
rocket = { version = "0.5", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
starship-battery = "0.8"
sysinfo = "0.30"
tauri = { version = "2.0", features = [
"devtools",
"macos-private-api",
Expand All @@ -29,15 +36,10 @@ tauri-plugin-dialog = "2.0"
tauri-plugin-http = "2.0"
tauri-plugin-shell = "2.0"
tauri-plugin-single-instance = "2.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
starship-battery = "0.8"
sysinfo = "0.30"
tokio = { version = "1.33", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
netdev = "0.24"
regex = "1"
uuid = { version = "1", features = ["v4"] }

[target.'cfg(target_os = "windows")'.dependencies]
komorebi-client = { git = "https://github.com/LGUG2Z/komorebi", tag = "v0.1.28" }
Expand Down
6 changes: 5 additions & 1 deletion packages/desktop/capabilities/widget.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"description": "Widget capabilities",
"windows": ["widget-*"],
"remote": {
"urls": ["http://asset.localhost", "asset://localhost"]
"urls": [
"http://asset.localhost",
"asset://localhost",
"http://127.0.0.1:6124"
]
},
"permissions": [
"core:app:default",
Expand Down
67 changes: 67 additions & 0 deletions packages/desktop/resources/initialization-script.js
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.
Loading

0 comments on commit f02cb00

Please sign in to comment.