Skip to content

Commit 5899b33

Browse files
author
bayashi
committed
add format2 field in config.json to switch clock formats
1 parent 6602b7c commit 5899b33

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ The countdown clock hasn't been tested enough though. Probably work if your conf
111111

112112
The `format` field is a date-time format string used to display the clock. To create a custom date-time format, please refer to [this formatting guide](https://momentjs.com/docs/#/parsing/string-format/).
113113

114+
#### format2
115+
116+
The `format2` field is same as `format`. These are switched each other by clicking the mclocks. The `format2` is optional field.
117+
114118
#### locale
115119

116120
The `locale` field determines the language settings for displaying the date-time. You can find [a list of supported locales here](https://github.com/kawanet/cdate-locale/blob/main/locales.yml).

src-tauri/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ struct AppConfig {
3030
#[serde(default)]
3131
format: String,
3232
#[serde(default)]
33+
format2: String,
34+
#[serde(default)]
3335
locale: String,
3436
#[serde(default)]
3537
forefront: bool,
@@ -120,6 +122,7 @@ fn merge_configs(old: OldAppConfig, new: AppConfig) -> AppConfig {
120122
} else {
121123
"MM-DD ddd HH:mm".to_string()
122124
},
125+
format2: new.format2,
123126
locale: if new.locale != "" {
124127
new.locale
125128
} else if old.locale_date_time != "" {

src/app.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ const currentPlatform = platform();
1010
let elClocks = document.querySelector("#mclocks");
1111
let Config;
1212
let ignoreOnMoved = false
13+
let switchFormat = false
1314

1415
window.addEventListener("DOMContentLoaded", async () => {
1516
elClocks.addEventListener("mousedown", async () => {
1617
await getCurrentWindow().startDragging();
1718
})
1819

20+
elClocks.addEventListener("click", async () => {
21+
if (!Config || !Config.format2) {
22+
return
23+
}
24+
switchFormat = !switchFormat
25+
adjustWindowSize()
26+
})
27+
1928
await getCurrentWindow().onMoved(() => {
2029
// Not support to save window-state onMoved for macOS.
2130
// Just save window-state on quit mclocks for macOS.
@@ -95,7 +104,11 @@ function tock(clock) {
95104
if (clock.target) {
96105
clock.el.innerHTML = escapeHTML(buildCountdown(clock.target, clock.timezone, clock.countdown));
97106
} else {
98-
clock.el.innerHTML = escapeHTML(clock.fn().format(Config.format));
107+
let format = Config.format
108+
if (switchFormat) {
109+
format = Config.format2
110+
}
111+
clock.el.innerHTML = escapeHTML(clock.fn().format(format));
99112
}
100113
}
101114

0 commit comments

Comments
 (0)