Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d01c501ca
|
||
|
|
619ca9e33e
|
||
|
|
b2603d74ee
|
||
|
|
5392214361 | ||
|
|
a477a67936 | ||
|
|
7491866251 | ||
|
|
b28502a199 | ||
|
|
53862d42a8 | ||
|
|
d427dea70a | ||
|
|
f39896374c | ||
|
|
ac83c893eb |
@@ -0,0 +1,16 @@
|
||||
src-tauri/icons/128x128.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/[email protected] filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/Square71x71Logo.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/32x32.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/64x64.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/Square107x107Logo.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/Square142x142Logo.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/Square284x284Logo.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/Square44x44Logo.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/Square150x150Logo.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/StoreLogo.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/icon.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/Square89x89Logo.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/Square30x30Logo.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/Square310x310Logo.png filter=lfs diff=lfs merge=lfs -text
|
||||
src-tauri/icons/app-icon.png filter=lfs diff=lfs merge=lfs -text
|
||||
@@ -0,0 +1,46 @@
|
||||
pkgname=tauclock-git
|
||||
pkgver=0.1.0.r0.g0000000
|
||||
pkgrel=1
|
||||
pkgdesc="Keyboard-driven clock, alarm, timer, and stopwatch desktop app built with Tauri"
|
||||
arch=('x86_64')
|
||||
url="https://git.rumginger.org/kamat/tauclock.git"
|
||||
license=('MIT')
|
||||
depends=(
|
||||
'gtk3'
|
||||
'webkit2gtk-4.1'
|
||||
)
|
||||
makedepends=(
|
||||
'cargo'
|
||||
'git'
|
||||
'rust'
|
||||
)
|
||||
source=("git+${url}")
|
||||
sha256sums=('SKIP')
|
||||
|
||||
pkgver() {
|
||||
cd "${srcdir}/tauclock/src-tauri"
|
||||
local version
|
||||
version="$(grep -m1 '^version = ' Cargo.toml | cut -d'"' -f2)"
|
||||
printf '%s.r%s.g%s' "${version}" \
|
||||
"$(git rev-list --count HEAD)" \
|
||||
"$(git rev-parse --short HEAD)"
|
||||
}
|
||||
|
||||
build() {
|
||||
cd "${srcdir}/tauclock/src-tauri"
|
||||
export CARGO_TARGET_DIR="${srcdir}/target"
|
||||
cargo build --release --locked
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "${srcdir}/tauclock"
|
||||
|
||||
install -Dm755 "${srcdir}/target/release/tauclock" \
|
||||
"${pkgdir}/usr/bin/tauclock"
|
||||
install -Dm644 "tauclock.desktop" \
|
||||
"${pkgdir}/usr/share/applications/tauclock.desktop"
|
||||
install -Dm644 "src-tauri/icons/128x128.png" \
|
||||
"${pkgdir}/usr/share/icons/hicolor/128x128/apps/tauclock.png"
|
||||
install -Dm644 "LICENSE" \
|
||||
"${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
|
||||
}
|
||||
@@ -9,6 +9,7 @@ TauClockは、ローカル/UTC時計、アラーム、カウントダウンタ
|
||||
- 柔軟な入力形式に対応したカウントダウンタイマー(`5m30s`, `1:15`, `90` など)
|
||||
- ラップ記録つきストップウォッチと履歴リスト
|
||||
- キーボードショートカットと画面内に表示できるチートシート
|
||||
- アプリ説明・バージョン・ライセンス本文を確認できるAboutダイアログ
|
||||
- Tauri + Rust製の軽量クロスプラットフォームバイナリ
|
||||
|
||||
## キーボードショートカット
|
||||
@@ -16,6 +17,7 @@ TauClockは、ローカル/UTC時計、アラーム、カウントダウンタ
|
||||
| キー | 動作 |
|
||||
| ----- | ------------------------------------------ |
|
||||
| `H` | ショートカット一覧を開閉 |
|
||||
| `I` | Aboutダイアログを開閉 |
|
||||
| `A` | アラームの時刻入力欄にフォーカス |
|
||||
| `N` | アラームを追加 |
|
||||
| `T` | タイマーの時間入力欄にフォーカス |
|
||||
@@ -63,6 +65,24 @@ cargo tauri build
|
||||
|
||||
`src-tauri/target/release/` 以下に配布用バイナリが生成されます。
|
||||
|
||||
### 日付時刻ライブラリと依存監査
|
||||
|
||||
日時処理は、RUSTSEC-2026-0543で保守停止が告知されたChronoではなくJiff 1.xを使用します。
|
||||
日常のローカル時刻、UTC表示、アラームの暦日計算はJiffが担当します。互換性維持のため、
|
||||
夏時間の重複時刻は早い方を選び、存在しない時刻は従来どおりcivil timeをUTCとして解釈する
|
||||
fallbackを使います。保存済みアラームJSONの形式は変更しません。
|
||||
|
||||
```bash
|
||||
cd src-tauri
|
||||
cargo tree --locked -i chrono # active dependencyは表示されないこと
|
||||
cargo audit --deny warnings
|
||||
```
|
||||
|
||||
Tauriが利用するcrateの非有効なoptional dependencyとして、`Cargo.lock`にChronoが残る場合があります。
|
||||
`cargo tree`でactive dependencyではないことを確認してください。`cargo audit`はlockfile単位で検査するため、
|
||||
この非有効なentryもRUSTSEC-2026-0543として報告します。Tauri/Linux GUI由来のその他の
|
||||
warning-class advisoryは [Issue #9](https://git.rumginger.org/kamat/tauclock/issues/9) で追跡します。
|
||||
|
||||
## ライセンス
|
||||
|
||||
MIT License. 詳細は `LICENSE` を参照してください。
|
||||
|
||||
@@ -22,7 +22,7 @@ tauri = { version = "2", features = [] }
|
||||
tauri-plugin-opener = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
chrono = "0.4.42"
|
||||
jiff = "1"
|
||||
tauri-plugin-log = "2"
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
dirs = "5"
|
||||
|
||||
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 130 B |
|
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 130 B |
|
Before Width: | Height: | Size: 974 B After Width: | Height: | Size: 129 B |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 130 B |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 130 B |
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 130 B |
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 130 B |
|
Before Width: | Height: | Size: 903 B After Width: | Height: | Size: 129 B |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 130 B |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 129 B |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 129 B |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 130 B |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 129 B |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 131 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 7.8 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 250 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 20 KiB |
@@ -5,10 +5,21 @@
|
||||
mod state;
|
||||
|
||||
use log::LevelFilter;
|
||||
use serde::Serialize;
|
||||
use state::{AppState, FrontendState};
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
use tauri_plugin_log::{Target, TargetKind};
|
||||
|
||||
/// Metadata and legal text displayed by the frontend "About" dialog.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
struct AboutInfo {
|
||||
app_name: String,
|
||||
version: String,
|
||||
identifier: String,
|
||||
license_name: String,
|
||||
license_text: String,
|
||||
}
|
||||
|
||||
/// Returns the current frontend snapshot without mutating any state. Used for
|
||||
/// the initial UI bootstrap.
|
||||
#[tauri::command]
|
||||
@@ -107,6 +118,21 @@ fn reset_stopwatch(app_state: tauri::State<AppState>) -> FrontendState {
|
||||
app_state.reset_stopwatch()
|
||||
}
|
||||
|
||||
/// Returns static application metadata and the bundled MIT license text for
|
||||
/// display in the About dialog.
|
||||
#[tauri::command]
|
||||
fn get_about_info(app: tauri::AppHandle) -> AboutInfo {
|
||||
let package = app.package_info();
|
||||
let identifier = app.config().identifier.clone();
|
||||
AboutInfo {
|
||||
app_name: package.name.clone(),
|
||||
version: package.version.to_string(),
|
||||
identifier,
|
||||
license_name: "MIT".to_string(),
|
||||
license_text: include_str!("../../LICENSE").trim().to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes the Tauri runtime, configures plugins, and wires shared
|
||||
/// application state into every window.
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
@@ -139,7 +165,8 @@ pub fn run() {
|
||||
reset_timer,
|
||||
toggle_stopwatch,
|
||||
add_lap,
|
||||
reset_stopwatch
|
||||
reset_stopwatch,
|
||||
get_about_info
|
||||
])
|
||||
.setup(move |_| {
|
||||
log::info!("Tauclock backend ready; storage_path={}", storage_display);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use chrono::{
|
||||
DateTime, Datelike, Days, Local, LocalResult, NaiveDate, NaiveDateTime, NaiveTime, TimeZone,
|
||||
Timelike, Utc,
|
||||
use jiff::{
|
||||
tz::{AmbiguousOffset, TimeZone},
|
||||
Timestamp, ZonedDateTime,
|
||||
};
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -24,14 +24,21 @@ const TIMER_MIN_MS: u64 = 1000;
|
||||
pub struct AppState {
|
||||
inner: Mutex<StateInner>,
|
||||
storage_path: PathBuf,
|
||||
time_zone: TimeZone,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
/// Constructs a new state container and eagerly loads persisted alarms.
|
||||
pub fn new(storage_path: PathBuf) -> Self {
|
||||
Self::with_time_zone(storage_path, TimeZone::system())
|
||||
}
|
||||
|
||||
/// Constructs state using an explicit time zone. Production passes the
|
||||
/// operating system zone; tests can provide a named IANA zone.
|
||||
fn with_time_zone(storage_path: PathBuf, time_zone: TimeZone) -> Self {
|
||||
let mut inner = StateInner::default();
|
||||
if let Some(list) = load_alarms(&storage_path) {
|
||||
let now = Local::now();
|
||||
let now = now_in_time_zone(&time_zone);
|
||||
inner.alarms = list
|
||||
.into_iter()
|
||||
.map(|alarm| Alarm {
|
||||
@@ -48,6 +55,7 @@ impl AppState {
|
||||
Self {
|
||||
inner: Mutex::new(inner),
|
||||
storage_path,
|
||||
time_zone,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,15 +124,15 @@ impl AppState {
|
||||
/// snapshot generation, and persistence side effects.
|
||||
fn apply<F>(&self, mutator: F) -> FrontendState
|
||||
where
|
||||
F: FnOnce(&mut StateInner, i64, &DateTime<Local>),
|
||||
F: FnOnce(&mut StateInner, i64, &ZonedDateTime),
|
||||
{
|
||||
let now_local = Local::now();
|
||||
let now_ms = now_local.timestamp_millis();
|
||||
let now_local = now_in_time_zone(&self.time_zone);
|
||||
let now_ms = now_local.timestamp().as_millisecond();
|
||||
let mut guard = self.inner.lock().expect("state mutex poisoned");
|
||||
trace!("Running state mutation (now_ms={})", now_ms);
|
||||
mutator(&mut guard, now_ms, &now_local);
|
||||
guard.refresh(now_ms, &now_local);
|
||||
let snapshot = guard.to_frontend(&now_local);
|
||||
let snapshot = guard.build_frontend(&now_local);
|
||||
let persisted = if guard.alarms_dirty {
|
||||
Some(
|
||||
guard
|
||||
@@ -194,16 +202,16 @@ struct StateInner {
|
||||
|
||||
impl StateInner {
|
||||
/// Executes periodic tasks that should run on every mutation or tick.
|
||||
fn refresh(&mut self, now_ms: i64, now_local: &DateTime<Local>) {
|
||||
fn refresh(&mut self, now_ms: i64, now_local: &ZonedDateTime) {
|
||||
self.process_alarms(now_ms, now_local);
|
||||
self.update_timer(now_ms);
|
||||
self.expire_status(now_ms);
|
||||
}
|
||||
|
||||
/// Builds a full [`FrontendState`] representation of the current data.
|
||||
fn to_frontend(&mut self, now_local: &DateTime<Local>) -> FrontendState {
|
||||
let now_ms = now_local.timestamp_millis();
|
||||
let now_utc = now_local.with_timezone(&Utc);
|
||||
fn build_frontend(&mut self, now_local: &ZonedDateTime) -> FrontendState {
|
||||
let now_ms = now_local.timestamp().as_millisecond();
|
||||
let now_utc = now_local.timestamp().to_zoned_datetime(TimeZone::UTC);
|
||||
let clock = ClockState {
|
||||
local_time: format_time(now_local.hour(), now_local.minute(), now_local.second()),
|
||||
local_date: format_date(now_local.year(), now_local.month(), now_local.day()),
|
||||
@@ -231,7 +239,7 @@ impl StateInner {
|
||||
raw_time: &str,
|
||||
label: Option<&str>,
|
||||
now_ms: i64,
|
||||
now_local: &DateTime<Local>,
|
||||
now_local: &ZonedDateTime,
|
||||
) {
|
||||
let Some((hour, minute)) = parse_alarm_time(raw_time) else {
|
||||
warn!("Invalid alarm time input: {}", raw_time);
|
||||
@@ -261,7 +269,7 @@ impl StateInner {
|
||||
}
|
||||
|
||||
/// Toggles an alarm's active state and recalculates its next trigger.
|
||||
fn toggle_alarm(&mut self, id: &str, now_local: &DateTime<Local>) {
|
||||
fn toggle_alarm(&mut self, id: &str, now_local: &ZonedDateTime) {
|
||||
if let Some(alarm) = self.alarms.iter_mut().find(|alarm| alarm.id == id) {
|
||||
alarm.active = !alarm.active;
|
||||
alarm.ringing_until = None;
|
||||
@@ -412,7 +420,7 @@ impl StateInner {
|
||||
|
||||
/// Iterates configured alarms, triggering those scheduled for the current
|
||||
/// tick and scheduling their next activation.
|
||||
fn process_alarms(&mut self, now_ms: i64, now_local: &DateTime<Local>) {
|
||||
fn process_alarms(&mut self, now_ms: i64, now_local: &ZonedDateTime) {
|
||||
let mut triggered_labels = Vec::new();
|
||||
for alarm in &mut self.alarms {
|
||||
if let Some(until) = alarm.ringing_until {
|
||||
@@ -512,9 +520,7 @@ impl StateInner {
|
||||
|
||||
/// Builds the timer view model by formatting durations and button labels.
|
||||
fn build_timer_view(&self) -> TimerView {
|
||||
let display_ms = if self.timer.running {
|
||||
self.timer.remaining_ms
|
||||
} else if self.timer.remaining_ms > 0 {
|
||||
let display_ms = if self.timer.remaining_ms > 0 {
|
||||
self.timer.remaining_ms
|
||||
} else {
|
||||
self.timer.initial_ms
|
||||
@@ -733,12 +739,12 @@ fn load_alarms(path: &Path) -> Option<Vec<PersistedAlarm>> {
|
||||
}
|
||||
|
||||
/// Formats a timestamp as HH:MM:SS.
|
||||
fn format_time(hour: u32, minute: u32, second: u32) -> String {
|
||||
fn format_time(hour: i8, minute: i8, second: i8) -> String {
|
||||
format!("{:02}:{:02}:{:02}", hour, minute, second)
|
||||
}
|
||||
|
||||
/// Formats a date as YYYY-MM-DD.
|
||||
fn format_date(year: i32, month: u32, day: u32) -> String {
|
||||
fn format_date(year: i16, month: i8, day: i8) -> String {
|
||||
format!("{year:04}-{month:02}-{day:02}")
|
||||
}
|
||||
|
||||
@@ -768,7 +774,7 @@ fn format_relative(target_ms: i64, now_ms: i64) -> String {
|
||||
|
||||
/// Formats a duration for timer display, switching to HH:MM:SS when needed.
|
||||
fn format_duration(ms: u64) -> String {
|
||||
let total_seconds = (ms / 1000) as u64;
|
||||
let total_seconds = ms / 1000;
|
||||
let minutes = total_seconds / 60;
|
||||
let seconds = total_seconds % 60;
|
||||
let hundredths = (ms % 1000) / 10;
|
||||
@@ -870,27 +876,147 @@ fn parse_unit_duration(value: &str) -> Option<u64> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates the next trigger timestamp in milliseconds for an alarm.
|
||||
fn resolve_next_trigger(hour: u8, minute: u8, now_local: &DateTime<Local>) -> i64 {
|
||||
let naive_time = NaiveTime::from_hms_opt(hour as u32, minute as u32, 0)
|
||||
.unwrap_or_else(|| NaiveTime::from_hms_opt(0, 0, 0).unwrap());
|
||||
let mut candidate = combine_local(now_local.date_naive(), naive_time);
|
||||
if candidate.timestamp_millis() <= now_local.timestamp_millis() {
|
||||
let next_day = now_local.date_naive() + Days::new(1);
|
||||
candidate = combine_local(next_day, naive_time);
|
||||
}
|
||||
candidate.timestamp_millis()
|
||||
/// Returns the current system instant expressed in the requested zone.
|
||||
fn now_in_time_zone(time_zone: &TimeZone) -> ZonedDateTime {
|
||||
Timestamp::now().to_zoned_datetime(time_zone.clone())
|
||||
}
|
||||
|
||||
/// Safely combines a date and time within the Local timezone, falling back to
|
||||
/// UTC if the local conversion is ambiguous or invalid.
|
||||
fn combine_local(date: NaiveDate, time: NaiveTime) -> DateTime<Local> {
|
||||
let naive = NaiveDateTime::new(date, time);
|
||||
match Local.from_local_datetime(&naive) {
|
||||
LocalResult::Single(value) => value,
|
||||
LocalResult::Ambiguous(first, _second) => first,
|
||||
LocalResult::None => {
|
||||
DateTime::<Utc>::from_naive_utc_and_offset(naive, Utc).with_timezone(&Local)
|
||||
}
|
||||
/// Calculates the next trigger timestamp in milliseconds for an alarm while
|
||||
/// preserving the legacy local-time ambiguity policy. A fold selects the
|
||||
/// earlier occurrence. A gap interprets the nonexistent civil time as UTC
|
||||
/// before converting it back to the local zone.
|
||||
fn resolve_next_trigger(hour: u8, minute: u8, now_local: &ZonedDateTime) -> i64 {
|
||||
let time_zone = now_local.time_zone().clone();
|
||||
let mut candidate = combine_local(now_local.date(), hour, minute, &time_zone);
|
||||
if candidate.timestamp().as_millisecond() <= now_local.timestamp().as_millisecond() {
|
||||
candidate = combine_local(
|
||||
now_local
|
||||
.date()
|
||||
.tomorrow()
|
||||
.expect("tomorrow is representable"),
|
||||
hour,
|
||||
minute,
|
||||
&time_zone,
|
||||
);
|
||||
}
|
||||
candidate.timestamp().as_millisecond()
|
||||
}
|
||||
|
||||
fn combine_local(
|
||||
date: jiff::civil::Date,
|
||||
hour: u8,
|
||||
minute: u8,
|
||||
time_zone: &TimeZone,
|
||||
) -> ZonedDateTime {
|
||||
let civil = date.at(hour as i8, minute as i8, 0, 0);
|
||||
let ambiguous = time_zone.to_ambiguous_zoned_datetime(civil);
|
||||
if matches!(ambiguous.offset(), AmbiguousOffset::Gap { .. }) {
|
||||
return civil
|
||||
.to_zoned_datetime(TimeZone::UTC)
|
||||
.expect("alarm date is representable in UTC")
|
||||
.timestamp()
|
||||
.to_zoned_datetime(time_zone.clone());
|
||||
}
|
||||
ambiguous.compatible().expect("alarm date is representable")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn named_zone(name: &str) -> TimeZone {
|
||||
TimeZone::get(name).expect("named test time zone is available")
|
||||
}
|
||||
|
||||
fn zoned(instant: &str, time_zone: TimeZone) -> ZonedDateTime {
|
||||
instant
|
||||
.parse::<Timestamp>()
|
||||
.expect("valid test instant")
|
||||
.to_zoned_datetime(time_zone)
|
||||
}
|
||||
|
||||
fn milliseconds(instant: &str) -> i64 {
|
||||
instant
|
||||
.parse::<Timestamp>()
|
||||
.expect("valid expected instant")
|
||||
.as_millisecond()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formats_clock_labels_without_changing_the_ui_contract() {
|
||||
assert_eq!(format_date(2026, 11, 20), "2026-11-20");
|
||||
assert_eq!(format_time(7, 5, 9), "07:05:09");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn production_state_can_be_configured_with_a_named_test_zone() {
|
||||
let app = AppState::with_time_zone(
|
||||
PathBuf::from("missing-test-alarms.json"),
|
||||
named_zone("Asia/Tokyo"),
|
||||
);
|
||||
assert_eq!(app.time_zone.iana_name(), Some("Asia/Tokyo"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schedules_later_today_and_equal_time_tomorrow() {
|
||||
let utc = named_zone("UTC");
|
||||
let now = zoned("2024-01-15T09:30:00Z", utc.clone());
|
||||
assert_eq!(
|
||||
resolve_next_trigger(9, 31, &now),
|
||||
milliseconds("2024-01-15T09:31:00Z")
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_next_trigger(9, 30, &now),
|
||||
milliseconds("2024-01-16T09:30:00Z")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_york_fold_uses_the_earlier_occurrence() {
|
||||
let new_york = named_zone("America/New_York");
|
||||
let now = zoned("2024-11-03T00:00:00Z", new_york);
|
||||
assert_eq!(
|
||||
resolve_next_trigger(1, 30, &now),
|
||||
milliseconds("2024-11-03T05:30:00Z")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_york_gap_preserves_the_legacy_utc_fallback() {
|
||||
let new_york = named_zone("America/New_York");
|
||||
let gap_date: jiff::civil::Date = "2024-03-10".parse().expect("valid date");
|
||||
assert_eq!(
|
||||
combine_local(gap_date, 2, 30, &new_york)
|
||||
.timestamp()
|
||||
.as_millisecond(),
|
||||
milliseconds("2024-03-10T02:30:00Z")
|
||||
);
|
||||
|
||||
let now = zoned("2024-03-10T05:00:00Z", new_york);
|
||||
assert_eq!(
|
||||
resolve_next_trigger(2, 30, &now),
|
||||
milliseconds("2024-03-11T06:30:00Z")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_alarm_advances_by_calendar_day_across_dst() {
|
||||
let new_york = named_zone("America/New_York");
|
||||
let now = zoned("2024-03-09T08:30:01Z", new_york);
|
||||
let trigger = resolve_next_trigger(3, 30, &now);
|
||||
assert_eq!(trigger, milliseconds("2024-03-10T07:30:00Z"));
|
||||
assert_eq!(trigger - now.timestamp().as_millisecond(), 82_799_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn persisted_alarm_json_round_trips_without_schedule_fields() {
|
||||
let json =
|
||||
r#"{"alarms":[{"id":"wake","hour":7,"minute":30,"label":"Wake up","active":true}]}"#;
|
||||
let store: AlarmStore = serde_json::from_str(json).expect("stored alarm JSON parses");
|
||||
assert_eq!(store.alarms.len(), 1);
|
||||
assert_eq!(store.alarms[0].id, "wake");
|
||||
assert_eq!(store.alarms[0].hour, 7);
|
||||
assert_eq!(store.alarms[0].minute, 30);
|
||||
assert_eq!(serde_json::to_string(&store).unwrap(), json);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
</div>
|
||||
<div class="header-meta">
|
||||
<button type="button" id="shortcut-trigger" class="hint-button">ショートカット一覧 (H)</button>
|
||||
<button type="button" id="about-trigger" class="hint-button">About (I)</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -118,6 +119,8 @@
|
||||
<dl>
|
||||
<dt>H</dt>
|
||||
<dd>ショートカット一覧を表示/非表示</dd>
|
||||
<dt>I</dt>
|
||||
<dd>Aboutを表示/非表示</dd>
|
||||
<dt>A</dt>
|
||||
<dd>アラーム時刻入力へフォーカス</dd>
|
||||
<dt>N</dt>
|
||||
@@ -139,5 +142,26 @@
|
||||
</dl>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="about-overlay" class="about-overlay" hidden>
|
||||
<div class="about-card" role="dialog" aria-modal="true" aria-labelledby="about-heading" tabindex="-1">
|
||||
<header>
|
||||
<h2 id="about-heading">About TauClock</h2>
|
||||
<button type="button" id="about-close" class="ghost">閉じる (Esc)</button>
|
||||
</header>
|
||||
<dl class="about-meta">
|
||||
<dt>アプリ名</dt>
|
||||
<dd id="about-name">-</dd>
|
||||
<dt>バージョン</dt>
|
||||
<dd id="about-version">-</dd>
|
||||
<dt>識別子</dt>
|
||||
<dd id="about-identifier">-</dd>
|
||||
<dt>ライセンス</dt>
|
||||
<dd id="about-license-name">-</dd>
|
||||
</dl>
|
||||
<h3>ライセンス本文</h3>
|
||||
<pre id="about-license-text" class="about-license"></pre>
|
||||
</div>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -92,6 +92,7 @@ function resolveInvoke() {
|
||||
const elements = {};
|
||||
let tickInFlight = false;
|
||||
let latestState = null;
|
||||
let aboutInfo = null;
|
||||
|
||||
/** Keyboard shortcut handlers keyed by `KeyboardEvent.code`. */
|
||||
const SHORTCUTS = {
|
||||
@@ -104,6 +105,7 @@ const SHORTCUTS = {
|
||||
KeyL: () => requestState("add_lap"),
|
||||
KeyP: () => requestState("reset_stopwatch"),
|
||||
KeyH: () => toggleShortcutOverlay(),
|
||||
KeyI: () => toggleAboutOverlay(),
|
||||
};
|
||||
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
@@ -141,6 +143,14 @@ function cacheElements() {
|
||||
elements.shortcutOverlay = document.getElementById("shortcut-overlay");
|
||||
elements.shortcutClose = document.getElementById("shortcut-close");
|
||||
elements.shortcutTrigger = document.getElementById("shortcut-trigger");
|
||||
elements.aboutOverlay = document.getElementById("about-overlay");
|
||||
elements.aboutClose = document.getElementById("about-close");
|
||||
elements.aboutTrigger = document.getElementById("about-trigger");
|
||||
elements.aboutName = document.getElementById("about-name");
|
||||
elements.aboutVersion = document.getElementById("about-version");
|
||||
elements.aboutIdentifier = document.getElementById("about-identifier");
|
||||
elements.aboutLicenseName = document.getElementById("about-license-name");
|
||||
elements.aboutLicenseText = document.getElementById("about-license-text");
|
||||
const missing = Object.entries(elements)
|
||||
.filter(([, value]) => !value)
|
||||
.map(([key]) => key);
|
||||
@@ -198,6 +208,13 @@ function bindEvents() {
|
||||
if (elements.shortcutTrigger) {
|
||||
elements.shortcutTrigger.addEventListener("click", () => toggleShortcutOverlay(true));
|
||||
}
|
||||
elements.aboutClose.addEventListener("click", () => toggleAboutOverlay(false));
|
||||
elements.aboutOverlay.addEventListener("click", (event) => {
|
||||
if (event.target === elements.aboutOverlay) toggleAboutOverlay(false);
|
||||
});
|
||||
if (elements.aboutTrigger) {
|
||||
elements.aboutTrigger.addEventListener("click", () => toggleAboutOverlay(true));
|
||||
}
|
||||
|
||||
document.addEventListener("keydown", handleShortcuts, true);
|
||||
logInfo("Core UI events bound");
|
||||
@@ -209,11 +226,21 @@ function bindEvents() {
|
||||
*/
|
||||
async function bootstrap() {
|
||||
logInfo("Bootstrapping state");
|
||||
await requestState("get_state");
|
||||
await Promise.all([requestState("get_state"), loadAboutInfo()]);
|
||||
setInterval(runTick, 250);
|
||||
logInfo("Tick loop scheduled", { intervalMs: 250 });
|
||||
}
|
||||
|
||||
/** Loads application metadata used by the About dialog. */
|
||||
async function loadAboutInfo() {
|
||||
try {
|
||||
aboutInfo = await invoke("get_about_info");
|
||||
renderAboutInfo(aboutInfo);
|
||||
} catch (error) {
|
||||
logError("Failed to load About information", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a timer toggle from the backend, optionally forcing a reparse of
|
||||
* the duration input if the user explicitly pressed Enter inside the field.
|
||||
@@ -401,6 +428,9 @@ function toggleShortcutOverlay(force) {
|
||||
const overlay = elements.shortcutOverlay;
|
||||
if (!overlay) return;
|
||||
const next = typeof force === "boolean" ? force : overlay.hidden;
|
||||
if (next) {
|
||||
toggleAboutOverlay(false);
|
||||
}
|
||||
overlay.hidden = !next;
|
||||
logInfo("Shortcut overlay toggled", { visible: next });
|
||||
if (next) {
|
||||
@@ -408,13 +438,46 @@ function toggleShortcutOverlay(force) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the About dialog visibility and lazily refreshes metadata when
|
||||
* missing so the UI can recover from early load failures.
|
||||
*/
|
||||
function toggleAboutOverlay(force) {
|
||||
const overlay = elements.aboutOverlay;
|
||||
if (!overlay) return;
|
||||
const next = typeof force === "boolean" ? force : overlay.hidden;
|
||||
if (next) {
|
||||
toggleShortcutOverlay(false);
|
||||
if (!aboutInfo) {
|
||||
loadAboutInfo();
|
||||
}
|
||||
}
|
||||
overlay.hidden = !next;
|
||||
logInfo("About overlay toggled", { visible: next });
|
||||
if (next) {
|
||||
overlay.querySelector(".about-card")?.focus?.();
|
||||
}
|
||||
}
|
||||
|
||||
/** Applies About metadata fields into the dialog. */
|
||||
function renderAboutInfo(info) {
|
||||
if (!info) return;
|
||||
elements.aboutName.textContent = info.app_name || "-";
|
||||
elements.aboutVersion.textContent = info.version || "-";
|
||||
elements.aboutIdentifier.textContent = info.identifier || "-";
|
||||
elements.aboutLicenseName.textContent = info.license_name || "-";
|
||||
elements.aboutLicenseText.textContent = info.license_text || "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Global keyboard listener that translates single-key shortcuts into higher
|
||||
* level actions while respecting modifier keys, focus states, and overlays.
|
||||
*/
|
||||
function handleShortcuts(event) {
|
||||
if (event.defaultPrevented) return;
|
||||
const overlayVisible = elements.shortcutOverlay && !elements.shortcutOverlay.hidden;
|
||||
const shortcutOverlayVisible = elements.shortcutOverlay && !elements.shortcutOverlay.hidden;
|
||||
const aboutOverlayVisible = elements.aboutOverlay && !elements.aboutOverlay.hidden;
|
||||
const overlayVisible = shortcutOverlayVisible || aboutOverlayVisible;
|
||||
const trackedKey = Boolean(SHORTCUTS[event.code]) || event.key === "Escape";
|
||||
if (trackedKey) {
|
||||
logDebug("Shortcut event received", {
|
||||
@@ -425,11 +488,16 @@ function handleShortcuts(event) {
|
||||
});
|
||||
}
|
||||
if (event.key === "Escape") {
|
||||
if (overlayVisible) {
|
||||
if (shortcutOverlayVisible) {
|
||||
toggleShortcutOverlay(false);
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (aboutOverlayVisible) {
|
||||
toggleAboutOverlay(false);
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (document.activeElement && document.activeElement !== document.body) {
|
||||
document.activeElement.blur();
|
||||
event.preventDefault();
|
||||
@@ -437,7 +505,7 @@ function handleShortcuts(event) {
|
||||
return;
|
||||
}
|
||||
if (event.altKey || event.metaKey || event.ctrlKey) return;
|
||||
if (overlayVisible && event.code !== "KeyH") return;
|
||||
if (overlayVisible && event.code !== "KeyH" && event.code !== "KeyI") return;
|
||||
if (isTypingTarget(event.target)) return;
|
||||
const handler = SHORTCUTS[event.code];
|
||||
if (handler) {
|
||||
|
||||
@@ -77,6 +77,9 @@ h1 {
|
||||
.header-meta {
|
||||
font-size: 0.85rem;
|
||||
color: #b6c5ff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
|
||||
.hint {
|
||||
@@ -396,8 +399,9 @@ button.ghost {
|
||||
}
|
||||
}
|
||||
|
||||
/* Keyboard shortcut modal overlay */
|
||||
.shortcut-overlay {
|
||||
/* Keyboard shortcut/About modal overlay */
|
||||
.shortcut-overlay,
|
||||
.about-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
backdrop-filter: blur(8px);
|
||||
@@ -407,7 +411,8 @@ button.ghost {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.shortcut-card {
|
||||
.shortcut-card,
|
||||
.about-card {
|
||||
width: min(520px, 80vw);
|
||||
background: rgba(4, 8, 24, 0.92);
|
||||
border-radius: 1.5rem;
|
||||
@@ -416,7 +421,8 @@ button.ghost {
|
||||
box-shadow: 0 25px 70px rgba(0, 0, 0, 0.55);
|
||||
}
|
||||
|
||||
.shortcut-card header {
|
||||
.shortcut-card header,
|
||||
.about-card header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
@@ -441,6 +447,48 @@ button.ghost {
|
||||
color: #e5ebff;
|
||||
}
|
||||
|
||||
.about-card {
|
||||
width: min(760px, 92vw);
|
||||
max-height: min(84vh, 780px);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.about-meta {
|
||||
margin: 1rem 0;
|
||||
display: grid;
|
||||
grid-template-columns: minmax(120px, 180px) 1fr;
|
||||
gap: 0.3rem 0.75rem;
|
||||
}
|
||||
|
||||
.about-meta dt {
|
||||
color: #9dc0ff;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.about-meta dd {
|
||||
margin: 0;
|
||||
color: #e5ebff;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.about-card h3 {
|
||||
margin: 0.6rem 0 0.45rem;
|
||||
font-size: 0.95rem;
|
||||
color: #9dc0ff;
|
||||
}
|
||||
|
||||
.about-license {
|
||||
margin: 0;
|
||||
padding: 1rem;
|
||||
border-radius: 1rem;
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
background: rgba(1, 3, 11, 0.8);
|
||||
color: #d9e5ff;
|
||||
line-height: 1.45;
|
||||
white-space: pre-wrap;
|
||||
font-size: 0.84rem;
|
||||
}
|
||||
|
||||
/* Responsive adjustments for tablet/phone layouts */
|
||||
@media (max-width: 1180px) {
|
||||
.app-shell {
|
||||
@@ -482,4 +530,8 @@ button.ghost {
|
||||
.shortcut-card dl {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.about-meta {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=TauClock
|
||||
Comment=Keyboard-driven clock, alarm, timer, and stopwatch
|
||||
Exec=tauclock
|
||||
Icon=tauclock
|
||||
Terminal=false
|
||||
Categories=Utility;Clock;
|
||||
StartupNotify=true
|
||||