Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,10 @@ This acknowledgement does not imply official endorsement or affiliation.

## Third-party components

The Overview yearly-activity card is a port of **Rare UI**'s [GitHub Activity](https://rareui.com/components/githubactivity)
component (Copyright (c) 2026 Swami Malode, MIT + Commons Clause, attribution required).
The port keeps the upstream layout, week/month maths, tooltip and expandable panel, and
replaces the GitHub data source with local dictation counts. Source:
`openless-all/app/src/components/ui/GitHubActivity.tsx` and `github-activity.css`.
The same credit is shown in Settings → About → Component credits.
The Overview annual activity card adapts calendar and expandable-panel code from **Rare UI**'s
[GitHub Activity](https://rareui.com/components/githubactivity) (Copyright (c) 2026 Swami Malode).
OpenLess supplies its own dictation data, app ranking, and desktop icons. See the
[component attribution and license](docs/ATTRIBUTION.md). The credit is also shown in Settings → About → Component credits.

## License

Expand Down
8 changes: 3 additions & 5 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,9 @@ OpenLess 同样认可并感谢 LinuxDo 社区开放、务实、对开发者友

## 第三方组件

概览页的年度活动热力图移植自 **Rare UI** 的 [GitHub Activity](https://rareui.com/components/githubactivity)
组件(Copyright (c) 2026 Swami Malode,MIT + Commons Clause,要求署名)。移植保留上游的布局、
周/月换算、悬浮提示和可展开面板,只把 GitHub 数据源换成本地听写统计。源码位于
`openless-all/app/src/components/ui/GitHubActivity.tsx` 与 `github-activity.css`。
同一署名也出现在「设置 → 关于与更新 → 组件来源」。
概览页的年度活动卡片改编了 **Rare UI** 的 [GitHub Activity](https://rareui.com/components/githubactivity)
日历和可展开面板代码(Copyright (c) 2026 Swami Malode)。听写数据、应用排名与桌面图标由 OpenLess 提供。
详情见[组件署名与许可](docs/ATTRIBUTION.md);署名也可在「设置 → 关于与更新 → 组件来源」中查看。

## 许可证

Expand Down
10 changes: 4 additions & 6 deletions docs/ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

## Rare UI GitHub Activity

The overview yearly activity card is a port of Rare UI's GitHub Activity component.
The Overview annual activity card adapts the calendar and expandable-panel code from Rare UI's GitHub Activity component. OpenLess uses local dictation activity and native desktop app icons instead of GitHub data. The card also supports a fitted calendar and an in-flow ranking panel.

- Page: https://rareui.com/components/githubactivity
- Upstream: https://github.com/swamimalode07/rare-ui
- License: MIT License + Commons Clause
- Upstream source: [github-activity.tsx](https://github.com/swamimalode07/rare-ui/blob/main/components/ui/github-activity.tsx)
- Copyright (c) 2026 Swami Malode
- License: [MIT + Commons Clause + Attribution](../openless-all/app/public/licenses/rare-ui-LICENSE.txt)

The port keeps the original geometry: 11px cells, 3px gap, 28px corner radius, 16px padding, week and month layout, the hover tooltip, and the expandable bottom panel. Local dictation counts replace GitHub contributions. The software with the most voice input (name and count) replaces repositories. Cells are not redrawn or resized to fit a narrow column.

The in-app credit is Settings → About and updates → Component credits. The repository READMEs (`openless-all/README.md` and `openless-all/README.zh.md`) carry the same credit.
The adapted component lives in `openless-all/app/src/ui/controls/GitHubActivity.tsx`, with styles in `openless-all/app/src/ui/styles/github-activity.css`. The in-app credit is Settings → About and updates → Component credits.
10 changes: 8 additions & 2 deletions openless-all/app/crates/openless-core/src/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ use std::path::{Path, PathBuf};
use std::sync::Mutex;

const ACTIVITY_RETENTION_DAYS: usize = 731;
// Older Windows buckets contain arbitrary document titles with no recoverable app identity.
const ACTIVITY_APPS_FILE: &str = if cfg!(target_os = "windows") {
"activity-apps-v2.json"
} else {
"activity-apps.json"
};

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -109,7 +115,7 @@ impl ActivityStore {
}
pub fn at_path(path: PathBuf) -> Result<Self, BackendError> {
let days = read_days(&path)?;
let apps_path = path.with_file_name("activity-apps.json");
let apps_path = path.with_file_name(ACTIVITY_APPS_FILE);
let apps = match std::fs::read(&apps_path) {
Ok(bytes) => serde_json::from_slice(&bytes).ok(),
Err(error) if error.kind() == std::io::ErrorKind::NotFound => Some(BTreeMap::new()),
Expand Down Expand Up @@ -165,7 +171,7 @@ impl ActivityStore {
if let Some(path) = &self.path {
let bytes = serde_json::to_vec_pretty(&next)
.map_err(|_| persistence_error("encode application activity"))?;
atomic_write(&path.with_file_name("activity-apps.json"), &bytes)?;
atomic_write(&path.with_file_name(ACTIVITY_APPS_FILE), &bytes)?;
}
*state = Some(next);
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions openless-all/app/crates/openless-core/src/shared_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ pub struct FrontApp {
/// `FrontApp { name, bundle_id }`.
///
/// macOS composes `"Claude (com.anthropic.claudefordesktop)"`; Windows has
/// only window titles, no bundle id. History entries have separate
/// an executable name, not a bundle id. History entries have separate
/// `app_name` / `app_bundle_id` fields, so splitting lets the detail page
/// show a readable app name instead of gluing the whole bundle id into the
/// body text.
///
/// Only macOS labels are `"name (bundle.id)"`; on Windows parentheses are
/// part of the title. Callers must pass `is_macos` per platform (production
/// part of the label. Callers must pass `is_macos` per platform (production
/// goes through `split_front_app_opt`). Non-macOS labels and labels whose
/// bracket structure doesn't parse stay whole as the app name — better a
/// verbose display than misreading ordinary parentheses in a window title
Expand Down Expand Up @@ -231,7 +231,7 @@ pub fn split_front_app_label(label: &str, is_macos: bool) -> FrontApp {

/// `Option` convenience wrapper for `split_front_app_label`; keeps the
/// platform switch in one place: only macOS display strings are
/// `"name (bundle.id)"`; other platforms (Windows window titles, Linux)
/// `"name (bundle.id)"`; other platforms (Windows, Linux)
/// keep the whole string as the name and leave the bundle id empty.
pub fn split_front_app_opt(label: Option<&str>) -> FrontApp {
label
Expand Down
172 changes: 141 additions & 31 deletions openless-all/app/crates/openless-core/src/usage_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use std::sync::{
};
use uuid::Uuid;

const MAX_RECORDS: usize = 10_000;
const MAX_BYTES: u64 = 8 * 1024 * 1024;
mod retention;
use retention::{merge_retained_records, retention_key, EMPTY_DOCUMENT, MAX_BYTES, MAX_RECORDS};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -238,7 +238,7 @@ impl UsageRecord {
}
}

#[derive(Serialize, Deserialize)]
#[derive(Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
struct UsageDocument {
version: u32,
Expand Down Expand Up @@ -350,7 +350,7 @@ impl UsageRecorder {
impl UsageLedger {
/// Replacing an unreadable ledger requires an explicit user reset.
pub fn reset(path: PathBuf) -> Result<Self, BackendError> {
atomic_write(&path, br#"{"version":1,"records":[]}"#)?;
atomic_write(&path, EMPTY_DOCUMENT)?;
Self::open(path)
}

Expand All @@ -359,10 +359,10 @@ impl UsageLedger {
match std::fs::File::open(&path) {
Ok(file) => {
let mut bytes = Vec::new();
file.take(MAX_BYTES + 1)
file.take(MAX_BYTES as u64 + 1)
.read_to_end(&mut bytes)
.map_err(|_| persistence_error("read service usage"))?;
if bytes.len() as u64 > MAX_BYTES {
if bytes.len() > MAX_BYTES {
return Err(persistence_error("service usage too large"));
}
let document: UsageDocument = serde_json::from_slice(&bytes)
Expand All @@ -379,6 +379,7 @@ impl UsageLedger {
return Err(persistence_error("invalid service usage record"));
}
records = document.records;
records.sort_unstable_by_key(retention_key);
}
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
Err(_) => return Err(persistence_error("read service usage")),
Expand All @@ -399,33 +400,32 @@ impl UsageLedger {
expected_generation: u64,
record: UsageRecord,
) -> Result<bool, BackendError> {
if !record.valid() {
return Err(persistence_error("invalid service usage record"));
}
self.merge_records(expected_generation, [record])
}

fn merge_records(
&self,
expected_generation: u64,
records: impl IntoIterator<Item = UsageRecord>,
) -> Result<bool, BackendError> {
let mut state = self
.records
.lock()
.map_err(|_| persistence_error("lock service usage"))?;
if self.generation.load(Ordering::Acquire) != expected_generation {
return Ok(false);
}
let mut next = state
let current = state
.as_ref()
.ok_or_else(|| persistence_error("service usage needs reload"))?
.clone();
if next.iter().any(|existing| existing.id == record.id) {
.ok_or_else(|| persistence_error("service usage needs reload"))?;
let Some(update) = merge_retained_records(current, records)? else {
return Ok(false);
}
next.push(record);
next.sort_unstable_by_key(|record| record.occurred_at_ms);
if next.len() > MAX_RECORDS {
next.drain(..next.len() - MAX_RECORDS);
}
if let Err(error) = self.persist(&next) {
};
if let Err(error) = atomic_write(&self.path, &update.encoded) {
*state = None;
return Err(error);
}
*state = Some(next);
*state = Some(update.records);
Ok(true)
}

Expand All @@ -446,22 +446,13 @@ impl UsageLedger {
if state.is_none() {
return Err(persistence_error("service usage needs reload"));
}
if let Err(error) = self.persist(&[]) {
if let Err(error) = atomic_write(&self.path, EMPTY_DOCUMENT) {
*state = None;
return Err(error);
}
*state = Some(Vec::new());
Ok(())
}

fn persist(&self, records: &[UsageRecord]) -> Result<(), BackendError> {
let bytes = serde_json::to_vec(&UsageDocument {
version: 1,
records: records.to_vec(),
})
.map_err(|_| persistence_error("encode service usage"))?;
atomic_write(&self.path, &bytes)
}
}

#[cfg(test)]
Expand Down Expand Up @@ -510,6 +501,125 @@ mod tests {
std::fs::remove_dir_all(dir).unwrap();
}

#[test]
fn usage_record_union_is_idempotent_across_reopen_and_reversed_merges() {
let dir = std::env::temp_dir().join(format!("openless-usage-{}", Uuid::new_v4()));
let a_path = dir.join("a.json");
let b_path = dir.join("b.json");
let a = UsageLedger::open(a_path.clone()).unwrap();
let b = UsageLedger::open(b_path.clone()).unwrap();
let usage = |input_tokens| UsageRecord {
input_tokens: Some(input_tokens),
..record()
};
let merge = |target: &UsageLedger, source: &UsageLedger| {
target
.merge_records(target.generation(), source.list().unwrap())
.unwrap()
};
let total = |ledger: &UsageLedger| {
ledger
.list()
.unwrap()
.into_iter()
.map(|event| event.input_tokens.unwrap())
.sum::<u64>()
};
assert!(a.append(a.generation(), usage(10)).unwrap());
assert!(b.append(b.generation(), usage(7)).unwrap());
assert!(merge(&a, &b));
assert!(merge(&b, &a));
assert_eq!((total(&a), total(&b)), (17, 17));
let persisted = std::fs::read(&a_path).unwrap();
drop(a);
let a = UsageLedger::open(a_path.clone()).unwrap();
assert!(!merge(&a, &b));
assert!(!merge(&b, &a));
assert_eq!(std::fs::read(&a_path).unwrap(), persisted);
assert_eq!((total(&a), total(&b)), (17, 17));

assert!(a.append(a.generation(), usage(4)).unwrap());
assert!(b.append(b.generation(), usage(2)).unwrap());
assert!(merge(&b, &a));
assert!(!merge(&b, &a));
assert!(merge(&a, &b));
assert!(!merge(&a, &b));
assert_eq!((total(&a), total(&b)), (23, 23));
assert_eq!(
std::fs::read(a_path).unwrap(),
std::fs::read(b_path).unwrap()
);
std::fs::remove_dir_all(dir).unwrap();
}

#[test]
fn conflicting_usage_record_rejects_the_whole_batch() {
let dir = std::env::temp_dir().join(format!("openless-usage-{}", Uuid::new_v4()));
let path = dir.join("usage.json");
let ledger = UsageLedger::open(path.clone()).unwrap();
let original = record();
assert!(ledger
.append(ledger.generation(), original.clone())
.unwrap());
let before = std::fs::read(&path).unwrap();
let conflict = UsageRecord {
input_tokens: Some(1),
..original.clone()
};
assert!(ledger
.merge_records(ledger.generation(), [record(), conflict])
.is_err());
assert_eq!(ledger.list().unwrap(), vec![original]);
assert_eq!(std::fs::read(path).unwrap(), before);
std::fs::remove_dir_all(dir).unwrap();
}

#[test]
fn byte_retention_is_reopenable_deterministic_and_ignores_evicted_replays() {
let dir = std::env::temp_dir().join(format!("openless-usage-{}", Uuid::new_v4()));
let a_path = dir.join("a.json");
let b_path = dir.join("b.json");
let a = UsageLedger::open(a_path.clone()).unwrap();
let b = UsageLedger::open(b_path.clone()).unwrap();
let label = Some("x".repeat(160));
let template = UsageRecord {
provider: label.clone(),
service: label.clone(),
protocol: label.clone(),
channel: label.clone(),
model: label,
..record()
};
let records: Vec<_> = (1..=MAX_RECORDS)
.map(|i| UsageRecord {
id: Uuid::from_u128(i as u128),
..template.clone()
})
.collect();
assert!(a.merge_records(a.generation(), records.clone()).unwrap());
assert!(b
.merge_records(b.generation(), records.into_iter().rev())
.unwrap());
let bytes = std::fs::read(&a_path).unwrap();
assert!(bytes.len() <= MAX_BYTES);
assert_eq!(std::fs::read(b_path).unwrap(), bytes);
drop(a);
let a = UsageLedger::open(a_path).unwrap();
let saved = a.list().unwrap();
assert!(saved.len() < MAX_RECORDS);
assert_eq!(
saved.last().unwrap().id,
Uuid::from_u128(MAX_RECORDS as u128)
);
let evicted = UsageRecord {
id: Uuid::from_u128(1),
..template
};
assert!(!a.append(a.generation(), evicted).unwrap());
assert_eq!(a.list().unwrap(), saved);
std::fs::remove_dir_all(dir).unwrap();
}

#[test]
fn clear_invalidates_old_writers_and_unknown_files_are_preserved() {
let dir = std::env::temp_dir().join(format!("openless-usage-{}", Uuid::new_v4()));
Expand Down
Loading
Loading