Skip to content

Commit

Permalink
make custom local notify sound
Browse files Browse the repository at this point in the history
  • Loading branch information
RoderickQiu committed Mar 14, 2023
1 parent c6e0561 commit 8ecb2e1
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 41 deletions.
15 changes: 9 additions & 6 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,13 @@
"theme-color-positive" : "Stopwatch (default green): ",
"autostarttask" : "Auto start default task",
"autostarttask-tip" : "When a default task is set and this setting is on, wnr will automatically start the default task every time this app is opened. ",
"withdraw-timing": "Withdraw timing",
"fail-to-withdraw": "You cannot withdraw timing currently. ",
"statistics-enter": "Enter statistics",
"today-total": "Today ",
"can-redo-title": "You've been pausing long",
"can-redo-msg": "Does that mean you want to restart this period of timing? "
"withdraw-timing" : "Withdraw timing",
"fail-to-withdraw" : "You cannot withdraw timing currently. ",
"statistics-enter" : "Enter statistics",
"today-total" : "Today ",
"can-redo-title" : "You've been pausing long",
"can-redo-msg" : "Does that mean you want to restart this period of timing? ",
"custom" : "custom",
"custom-notify-sound" : "Custom notify sound: ",
"input-url" : "Input file url"
}
15 changes: 9 additions & 6 deletions locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,13 @@
"theme-color-positive" : "正计时(默认绿色):",
"autostarttask" : "自动开始默认预设",
"autostarttask-tip" : "当设置了默认预设且开启了此选项后,将在每次打开 wnr 软件时自动开始默认预设的计时,以提升强力水平。",
"withdraw-timing": "提前退出计时",
"fail-to-withdraw": "当前不能提前退出。",
"statistics-enter": "进入统计界面",
"today-total": "今日 ",
"can-redo-title": "你已经暂停了很久",
"can-redo-msg": "是否需要对当前段时间进行重新计时?"
"withdraw-timing" : "提前退出计时",
"fail-to-withdraw" : "当前不能提前退出。",
"statistics-enter" : "进入统计界面",
"today-total" : "今日 ",
"can-redo-title" : "你已经暂停了很久",
"can-redo-msg" : "是否需要对当前段时间进行重新计时?",
"custom" : "自定义",
"custom-notify-sound" : "自定义提示音",
"input-url" : "输入路径"
}
13 changes: 8 additions & 5 deletions locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,12 @@
"autostarttask" : "自動開始默認預設",
"autostarttask-tip" : "當設置了默認預設且開啟了此選項後,將在每次打開 wnr 軟件時自動開始默認預設的計時,以提升強力水平。",
"withdraw-timing": "提前退出計時",
"fail-to-withdraw": "當前不能提前退出。",
"statistics-enter": "進入統計界面",
"today-total": "今日 ",
"can-redo-title": "你已經暫停了很久",
"can-redo-msg": "是否需要對當前段時間進行重新計時?"
"fail-to-withdraw" : "當前不能提前退出。",
"statistics-enter" : "進入統計界面",
"today-total" : "今日 ",
"can-redo-title" : "你已經暫停了很久",
"can-redo-msg" : "是否需要對當前段時間進行重新計時?",
"custom" : "自定義",
"custom-notify-sound" : "自定義提示音",
"input-url" : "輸入路徑"
}
84 changes: 63 additions & 21 deletions preferences-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,17 @@ function domString(type) {
</div>
</div><br/>
</div>
<div class="col-5 custom-notify-sound-work-time-end">
<label>
${ i18n.__("custom-notify-sound") }
</label>
</div>
<div class="col-7 text-right custom-notify-sound-work-time-end">
<input id="custom-notify-sound-work-time-end" name="custom-notify-sound-work-time-end"
type="text" class="hotkey-set-input extreme-small text-right"
placeholder="${ i18n.__('input-url') }"
onkeyup="store.set('custom-work-time-end-sound',$('#custom-notify-sound-work-time-end').val());" />
</div><br/>
<div class="col-7">
<label>
${ i18n.__("personalization-notify-sound-msg-all-end") }
Expand All @@ -400,6 +411,17 @@ function domString(type) {
</div>
</div><br/>
</div>
<div class="col-5 custom-notify-sound-all-time-end">
<label>
${ i18n.__("custom-notify-sound") }
</label>
</div>
<div class="col-7 text-right custom-notify-sound-all-time-end">
<input id="custom-notify-sound-all-time-end" name="custom-notify-sound-all-time-end" type="text"
class="hotkey-set-input extreme-small text-right"
placeholder="${ i18n.__('input-url') }"
onkeyup="store.set('custom-all-time-end-sound',$('#custom-notify-sound-all-time-end').val());"/>
</div><br/>
</div><br/>`;
break;
case "i18n":
Expand Down Expand Up @@ -760,47 +782,67 @@ function personalizedNotification() {

//personalization sound
function personalizationSoundInitializer() {
if (store.has("custom-work-time-end-sound"))
$("#custom-notify-sound-work-time-end").val(store.get("custom-work-time-end-sound"));
if (store.has("custom-all-time-end-sound"))
$("#custom-notify-sound-all-time-end").val(store.get("custom-work-all-end-sound"));
let player = document.createElement("audio");//alert player
let soundList = ['alarming', 'beep', 'clock', 'tick', 'trumpet', 'whistle', 'horns', 'magic', 'piano'];
let soundList = ['alarming', 'beep', 'clock', 'tick', 'trumpet', 'whistle', 'horns', 'magic', 'piano', i18n.__('custom')];
for (let i in soundList) {
$("#work-time-end-sound-select").append("\
<a class='dropdown-item' href='javascript:workTimeEndSoundSetting(\"" + soundList[i] + "\")'>"
+ soundList[i] + "</a>");
}
$("#work-time-end-sound-dropdown-button").text(store.has("time-end-sound") ? store.get("time-end-sound") : "tick");
if (store.get("time-end-sound") === i18n.__('custom'))
$(".custom-notify-sound-work-time-end").css("display", "inline-block");
else
$(".custom-notify-sound-work-time-end").css("display", "none");

for (let i in soundList) {
$("#all-time-end-sound-select").append("\
<a class='dropdown-item' href='javascript:allTimeEndSoundSetting(\"" + soundList[i] + "\")'>"
+ soundList[i] + "</a>");
}
$("#all-time-end-sound-dropdown-button").text(store.has("all-end-sound") ? store.get("all-end-sound") : "piano");
if (store.get("all-end-sound") === i18n.__('custom'))
$(".custom-notify-sound-all-time-end").css("display", "inline-block");
else
$(".custom-notify-sound-all-time-end").css("display", "none");
}

function workTimeEndSoundSetting(val) {
try {
let player = document.createElement("audio");//alert player
store.set("time-end-sound", val);
$("#work-time-end-sound-dropdown-button").text(val);
player.src = path.join(__dirname, "\\res\\sound\\" + val + ".mp3");
player.loop = false;
player.play();
} catch (e) {
console.log(e);
}
store.set("time-end-sound", val);
$("#work-time-end-sound-dropdown-button").text(val);
if (val !== i18n.__('custom'))
try {
$(".custom-notify-sound-work-time-end").css("display", "none");
let player = document.createElement("audio");//alert player
player.src = path.join(__dirname, "\\res\\sound\\" + val + ".mp3");
player.loop = false;
player.play();
} catch (e) {
console.log(e);
}
else
$(".custom-notify-sound-work-time-end").css("display", "inline-block");
}

function allTimeEndSoundSetting(val) {
try {
let player = document.createElement("audio");//alert player
store.set("all-end-sound", val);
$("#all-time-end-sound-dropdown-button").text(val);
player.src = path.join(__dirname, "\\res\\sound\\" + val + ".mp3");
player.loop = false;
player.play();
} catch (e) {
console.log(e);
}
store.set("all-end-sound", val);
$("#all-time-end-sound-dropdown-button").text(val);
if (val !== i18n.__('custom'))
try {
$(".custom-notify-sound-all-time-end").css("display", "none");
let player = document.createElement("audio");//alert player
player.src = path.join(__dirname, "\\res\\sound\\" + val + ".mp3");
player.loop = false;
player.play();
} catch (e) {
console.log(e);
}
else
$(".custom-notify-sound-all-time-end").css("display", "inline-block");
}

//language settings
Expand Down
24 changes: 21 additions & 3 deletions timer.html
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,21 @@ <h3>
let player = document.createElement('audio');
amplifyMedia(player, amplifierList[store.get("sound")]);
if (isend !== 0) {
player.src = path.join(__dirname, "\\res\\sound\\" + (store.has("time-end-sound") ? store.get("time-end-sound") : "tick") + ".mp3");
if (store.get("time-end-sound") !== i18n.__("custom"))
player.src = path.join(__dirname, "\\res\\sound\\" + (store.has("time-end-sound") ? store.get("time-end-sound") : "tick") + ".mp3");
else if ((!store.has("custom-work-time-end-sound") || store.get("custom-work-time-end-sound") === "")
&& store.get("time-end-sound") === i18n.__("custom"))
player.src = path.join(__dirname, "\\res\\sound\\tick.mp3");
else
player.src = store.get("custom-work-time-end-sound");
} else {
player.src = path.join(__dirname, "\\res\\sound\\" + (store.has("all-end-sound") ? store.get("all-end-sound") : "piano") + ".mp3");
if (store.get("all-end-sound") !== i18n.__("custom"))
player.src = path.join(__dirname, "\\res\\sound\\" + (store.has("all-end-sound") ? store.get("all-end-sound") : "piano") + ".mp3");
else if ((!store.has("custom-all-time-end-sound") || store.get("custom-all-time-end-sound") === "")
&& store.get("all-end-sound") === i18n.__("custom"))
player.src = path.join(__dirname, "\\res\\sound\\piano.mp3");
else
player.src = store.get("custom-all-time-end-sound");
}
player.loop = true;
player.play();
Expand Down Expand Up @@ -931,7 +943,13 @@ <h3>
//if continueloop then only play once and no other thing
let player = document.createElement('audio');
amplifyMedia(player, amplifierList[store.get("sound")]);
player.src = path.join(__dirname, "\\res\\sound\\" + (store.has("time-end-sound") ? store.get("time-end-sound") : "tick") + ".mp3");
if (store.get("time-end-sound") !== i18n.__("custom"))
player.src = path.join(__dirname, "\\res\\sound\\" + (store.has("time-end-sound") ? store.get("time-end-sound") : "tick") + ".mp3");
else if ((!store.has("custom-work-time-end-sound") || store.get("custom-work-time-end-sound") === "")
&& store.get("time-end-sound") === i18n.__("custom"))
player.src = path.join(__dirname, "\\res\\sound\\tick.mp3");
else
player.src = store.get("custom-work-time-end-sound");
player.loop = false;
player.play();
} else {
Expand Down

0 comments on commit 8ecb2e1

Please sign in to comment.