Skip to content

Commit

Permalink
refactor: rename config property refresh_interval_ms -> `refresh_in…
Browse files Browse the repository at this point in the history
…terval`
  • Loading branch information
lars-berger committed Feb 17, 2024
1 parent 320801e commit 446d207
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 53 deletions.
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
- [Templating language](#sub-topic-12)
4. [Providers](#Providers)

## ⚙️ Installation
## ⚙️ Installation

**Downloads for Windows, MacOS, and Linux are available in the [latest release](https://github.com/glzr-io/zebar/releases)**. After installing, you can run the default start script located at `%userprofile%/.glzr/zebar/start.bat` (Windows) or `$HOME/.glzr/zebar/start.sh` (MacOS/Linux).

The config file is located `%userprofile%/.glzr/zebar/config.yaml`. A default config is created on startup.

## ➡️ Migration from GlazeWM bar
## ➡️ Migration from GlazeWM bar

Modify the following GlazeWM config options (at `%userprofile%/.glaze-wm/config.yaml`):

Expand All @@ -36,7 +36,7 @@ bar:
enabled: false
```
## 🌟 Intro to Zebar
## 🌟 Intro to Zebar
There's 3 big differences that set Zebar apart from other similar projects:
Expand Down Expand Up @@ -216,7 +216,7 @@ window/example:
}
```

## 🧩 Providers
## 🧩 Providers

- [battery](#Battery)
- [cpu](#CPU)
Expand All @@ -234,9 +234,9 @@ window/example:

### Provider config

| Option | Description | Option type | Default value |
| --------------------- | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval_ms` | How often this provider refreshes in milliseconds. | `number` | `5000` |
| Option | Description | Option type | Default value |
| ------------------ | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval` | How often this provider refreshes in milliseconds. | `number` | `5000` |

### Variables

Expand All @@ -256,9 +256,9 @@ window/example:

### Provider config

| Option | Description | Option type | Default value |
| --------------------- | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval_ms` | How often this provider refreshes in milliseconds. | `number` | `5000` |
| Option | Description | Option type | Default value |
| ------------------ | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval` | How often this provider refreshes in milliseconds. | `number` | `5000` |

### Variables

Expand All @@ -274,9 +274,9 @@ window/example:

### Provider config

| Option | Description | Option type | Default value |
| --------------------- | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval_ms` | How often this provider refreshes in milliseconds. | `number` | `1000` |
| Option | Description | Option type | Default value |
| ------------------ | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval` | How often this provider refreshes in milliseconds. | `number` | `1000` |

### Variables

Expand Down Expand Up @@ -308,9 +308,9 @@ GlazeWM provider doesn't take any config options.

### Provider config

| Option | Description | Option type | Default value |
| --------------------- | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval_ms` | How often this provider refreshes in milliseconds. | `number` | `60000` |
| Option | Description | Option type | Default value |
| ------------------ | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval` | How often this provider refreshes in milliseconds. | `number` | `60000` |

### Variables

Expand All @@ -327,9 +327,9 @@ GlazeWM provider doesn't take any config options.

### Provider config

| Option | Description | Option type | Default value |
| --------------------- | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval_ms` | How often this provider refreshes in milliseconds. | `number` | `3600000` |
| Option | Description | Option type | Default value |
| ------------------ | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval` | How often this provider refreshes in milliseconds. | `number` | `3600000` |

### Variables

Expand All @@ -345,9 +345,9 @@ GlazeWM provider doesn't take any config options.

### Provider config

| Option | Description | Option type | Default value |
| --------------------- | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval_ms` | How often this provider refreshes in milliseconds. | `number` | `5000` |
| Option | Description | Option type | Default value |
| ------------------ | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval` | How often this provider refreshes in milliseconds. | `number` | `5000` |

### Variables

Expand Down Expand Up @@ -379,9 +379,9 @@ Monitors provider doesn't take any config options.

### Provider config

| Option | Description | Option type | Default value |
| --------------------- | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval_ms` | How often this provider refreshes in milliseconds. | `number` | `5000` |
| Option | Description | Option type | Default value |
| ------------------ | -------------------------------------------------- | ----------- | ------------- |
| `refresh_interval` | How often this provider refreshes in milliseconds. | `number` | `5000` |

### Variables

Expand Down Expand Up @@ -412,11 +412,11 @@ Self provider doesn't take any config options.

### Provider config

| Option | Description | Option type | Default value |
| --------------------- | ------------------------------------------------------------------------------------------------------ | --------------------- | ------------- |
| `refresh_interval_ms` | How often this provider refreshes in milliseconds. | `number` | `3600000` |
| `latitude` | Latitude to retrieve weather for. If not provided, latitude is instead estimated based on public IP. | `number \| undefined` | `undefined` |
| `longitude` | Longitude to retrieve weather for. If not provided, longitude is instead estimated based on public IP. | `number \| undefined` | `undefined` |
| Option | Description | Option type | Default value |
| ------------------ | ------------------------------------------------------------------------------------------------------ | --------------------- | ------------- |
| `refresh_interval` | How often this provider refreshes in milliseconds. | `number` | `3600000` |
| `latitude` | Latitude to retrieve weather for. If not provided, latitude is instead estimated based on public IP. | `number \| undefined` | `undefined` |
| `longitude` | Longitude to retrieve weather for. If not provided, longitude is instead estimated based on public IP. | `number \| undefined` | `undefined` |

### Variables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function createDateProvider(

const interval = setInterval(
() => setDateVariables(getDateVariables()),
config.refresh_interval_ms,
config.refresh_interval,
);

runWithOwner(owner, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function createWeatherProvider(
(ipProvider = await createIpProvider(
{
type: ProviderType.IP,
refresh_interval_ms: 60 * 60 * 1000,
refresh_interval: 60 * 60 * 1000,
},
owner,
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ProviderType } from '../provider-type.model';
export const BatteryProviderConfigSchema = z.object({
type: z.literal(ProviderType.BATTERY),

refresh_interval_ms: z.coerce.number().default(5 * 1000),
refresh_interval: z.coerce.number().default(5 * 1000),
});

export type BatteryProviderConfig = z.infer<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ProviderType } from '../provider-type.model';
export const CpuProviderConfigSchema = z.object({
type: z.literal(ProviderType.CPU),

refresh_interval_ms: z.coerce.number().default(5 * 1000),
refresh_interval: z.coerce.number().default(5 * 1000),
});

export type CpuProviderConfig = z.infer<typeof CpuProviderConfigSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ProviderType } from '../provider-type.model';
export const DateProviderConfigSchema = z.object({
type: z.literal(ProviderType.DATE),

refresh_interval_ms: z.coerce.number().default(1000),
refresh_interval: z.coerce.number().default(1000),

/**
* Either a UTC offset (eg. `UTC+8`) or an IANA timezone (eg.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ProviderType } from '../provider-type.model';
export const HostProviderConfigSchema = z.object({
type: z.literal(ProviderType.HOST),

refresh_interval_ms: z.coerce.number().default(60 * 1000),
refresh_interval: z.coerce.number().default(60 * 1000),
});

export type HostProviderConfig = z.infer<typeof HostProviderConfigSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ProviderType } from '../provider-type.model';
export const IpProviderConfigSchema = z.object({
type: z.literal(ProviderType.IP),

refresh_interval_ms: z.coerce.number().default(60 * 60 * 1000),
refresh_interval: z.coerce.number().default(60 * 60 * 1000),
});

export type IpProviderConfig = z.infer<typeof IpProviderConfigSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ProviderType } from '../provider-type.model';
export const MemoryProviderConfigSchema = z.object({
type: z.literal(ProviderType.MEMORY),

refresh_interval_ms: z.coerce.number().default(5 * 1000),
refresh_interval: z.coerce.number().default(5 * 1000),
});

export type MemoryProviderConfig = z.infer<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ProviderType } from '../provider-type.model';
export const NetworkProviderConfigSchema = z.object({
type: z.literal(ProviderType.NETWORK),

refresh_interval_ms: z.coerce.number().default(5 * 1000),
refresh_interval: z.coerce.number().default(5 * 1000),
});

export type NetworkProviderConfig = z.infer<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const WeatherProviderConfigSchema = z.object({
/**
* How often this component refreshes in milliseconds.
*/
refresh_interval_ms: z.coerce.number().default(60 * 60 * 1000),
refresh_interval: z.coerce.number().default(60 * 60 * 1000),
});

export type WeatherProviderConfig = z.infer<
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/providers/battery/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::impl_interval_config;
#[derive(Deserialize, Debug)]
#[serde(tag = "type", rename = "battery")]
pub struct BatteryProviderConfig {
pub refresh_interval_ms: u64,
pub refresh_interval: u64,
}

impl_interval_config!(BatteryProviderConfig);
2 changes: 1 addition & 1 deletion packages/desktop/src/providers/cpu/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::impl_interval_config;
#[derive(Deserialize, Debug)]
#[serde(tag = "type", rename = "cpu")]
pub struct CpuProviderConfig {
pub refresh_interval_ms: u64,
pub refresh_interval: u64,
}

impl_interval_config!(CpuProviderConfig);
2 changes: 1 addition & 1 deletion packages/desktop/src/providers/host/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::impl_interval_config;
#[derive(Deserialize, Debug)]
#[serde(tag = "type", rename = "host")]
pub struct HostProviderConfig {
pub refresh_interval_ms: u64,
pub refresh_interval: u64,
}

impl_interval_config!(HostProviderConfig);
11 changes: 5 additions & 6 deletions packages/desktop/src/providers/interval_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::{

/// Require interval providers to have a refresh interval in their config.
pub trait IntervalConfig {
fn refresh_interval_ms(&self) -> u64;
fn refresh_interval(&self) -> u64;
}

#[macro_export]
Expand All @@ -25,8 +25,8 @@ macro_rules! impl_interval_config {
use crate::providers::interval_provider::IntervalConfig;

impl IntervalConfig for $struct_name {
fn refresh_interval_ms(&self) -> u64 {
self.refresh_interval_ms
fn refresh_interval(&self) -> u64 {
self.refresh_interval
}
}
};
Expand Down Expand Up @@ -62,9 +62,8 @@ impl<T: IntervalProvider + Send> Provider for T {
let state = self.state();

let forever = task::spawn(async move {
let mut interval = time::interval(Duration::from_millis(
config.refresh_interval_ms(),
));
let mut interval =
time::interval(Duration::from_millis(config.refresh_interval()));

loop {
// The first tick fires immediately.
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/providers/ip/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::impl_interval_config;
#[derive(Deserialize, Debug)]
#[serde(tag = "type", rename = "ip")]
pub struct IpProviderConfig {
pub refresh_interval_ms: u64,
pub refresh_interval: u64,
}

impl_interval_config!(IpProviderConfig);
2 changes: 1 addition & 1 deletion packages/desktop/src/providers/memory/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::impl_interval_config;
#[derive(Deserialize, Debug)]
#[serde(tag = "type", rename = "memory")]
pub struct MemoryProviderConfig {
pub refresh_interval_ms: u64,
pub refresh_interval: u64,
}

impl_interval_config!(MemoryProviderConfig);
2 changes: 1 addition & 1 deletion packages/desktop/src/providers/network/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::impl_interval_config;
#[derive(Deserialize, Debug)]
#[serde(tag = "type", rename = "network")]
pub struct NetworkProviderConfig {
pub refresh_interval_ms: u64,
pub refresh_interval: u64,
}

impl_interval_config!(NetworkProviderConfig);
2 changes: 1 addition & 1 deletion packages/desktop/src/providers/weather/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::impl_interval_config;
#[derive(Deserialize, Debug)]
#[serde(tag = "type", rename = "weather")]
pub struct WeatherProviderConfig {
pub refresh_interval_ms: u64,
pub refresh_interval: u64,
pub latitude: f32,
pub longitude: f32,
}
Expand Down

0 comments on commit 446d207

Please sign in to comment.