Skip to content

Commit 0378303

Browse files
author
bayashi
authored
Merge pull request #173 from bayashi/switch-display-seconds
add `format2` field in config.json to switch clock formats
2 parents 1856413 + 5899b33 commit 0378303

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
@@ -32,6 +32,8 @@ struct AppConfig {
3232
#[serde(default)]
3333
format: String,
3434
#[serde(default)]
35+
format2: String,
36+
#[serde(default)]
3537
locale: String,
3638
#[serde(default)]
3739
forefront: bool,
@@ -122,6 +124,7 @@ fn merge_configs(old: OldAppConfig, new: AppConfig) -> AppConfig {
122124
} else {
123125
"MM-DD ddd HH:mm".to_string()
124126
},
127+
format2: new.format2,
125128
locale: if new.locale != "" {
126129
new.locale
127130
} 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)