Skip to content

Commit 91682d4

Browse files
committed
support diff notif sound for work and rest
1 parent 6499ad5 commit 91682d4

File tree

7 files changed

+116
-20
lines changed

7 files changed

+116
-20
lines changed

locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@
225225
"personalization-notify-sound": "Custom notify sound",
226226
"personalization-notify-sound-tip": "Define the notify sounds played. The sound you select will be played automatically for test.",
227227
"personalization-notify-sound-msg-time-end": "Time end: ",
228+
"personalization-notify-sound-msg-work-end": "Work end: ",
229+
"personalization-notify-sound-msg-rest-end": "Rest end: ",
228230
"personalization-notify-sound-msg-all-end": "All tasks end: ",
229231
"dark-or-white": "Appearance",
230232
"dropdown-auto-switch": "Auto switch",

locales/zh-CN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@
264264
"personalization-notify-sound": "通知铃声个性化",
265265
"personalization-notify-sound-tip": "自定义铃声,让它合你心意。将会自动播放以供测试。当提示音关闭时,此选项将被忽略。",
266266
"personalization-notify-sound-msg-time-end": "一段时间结束",
267+
"personalization-notify-sound-msg-work-end": "工作结束",
268+
"personalization-notify-sound-msg-rest-end": "休息结束",
267269
"personalization-notify-sound-msg-all-end": "整个计划结束",
268270
"global-settings": "3. 全局设置",
269271
"languages": "语言/Languages",

locales/zh-TW.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@
257257
"personalization-notify-sound": "通知鈴聲個性化",
258258
"personalization-notify-sound-tip": "自定義鈴聲,讓它合你心意。將會自動播放以供測試。當提示音關閉時,此選項將被忽略。",
259259
"personalization-notify-sound-msg-time-end": "一段時間結束",
260+
"personalization-notify-sound-msg-work-end": "工作結束",
261+
"personalization-notify-sound-msg-rest-end": "休息結束",
260262
"personalization-notify-sound-msg-all-end": "整個計劃結束",
261263
"global-settings": "3. 全局設置",
262264
"languages": "語言/Languages",

preferences-items.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,16 @@ function zoomRatioAfter(val) {
349349
function soundAfter(val) {
350350
let player = document.createElement('audio');
351351
amplifyMedia(player, amplifierList[val]);
352-
player.src = path.join(__dirname, '\\res\\sound\\' + (store.has('time-end-sound') ? store.get('time-end-sound') : 'tick') + '.mp3');
352+
let workSelection = store.has('work-time-end-sound') ? store.get('work-time-end-sound')
353+
: (store.has('time-end-sound') ? store.get('time-end-sound') : 'tick');
354+
if (workSelection !== i18n.__('custom'))
355+
player.src = path.join(__dirname, '\\res\\sound\\' + workSelection + '.mp3');
356+
else {
357+
let customWork = store.get('custom-work-time-end-sound');
358+
if (!customWork || customWork === '')
359+
customWork = path.join(__dirname, '\\res\\sound\\tick.mp3');
360+
player.src = customWork;
361+
}
353362
player.loop = false;
354363
player.play();
355364
}

preferences-renderer.js

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ function domString(type) {
373373
<div class="w-100 row align-items-center">
374374
<div class="col-7">
375375
<label>
376-
${ i18n.__("personalization-notify-sound-msg-time-end") }
376+
${ i18n.__("personalization-notify-sound-msg-work-end") }
377377
</label>
378378
</div>
379379
<div class="col-5 text-right">
@@ -400,6 +400,34 @@ function domString(type) {
400400
onkeyup="store.set('custom-work-time-end-sound',$('#custom-notify-sound-work-time-end').val());" />
401401
</div><br/>
402402
<div class="col-7">
403+
<label>
404+
${ i18n.__("personalization-notify-sound-msg-rest-end") }
405+
</label>
406+
</div>
407+
<div class="col-5 text-right">
408+
<div class="dropdown">
409+
<a aria-expanded="false"
410+
aria-haspopup="true" class="btn btn-outline-secondary dropdown-toggle"
411+
data-toggle="dropdown"
412+
id="rest-time-end-sound-dropdown-button">
413+
</a>
414+
<div aria-labelledby="rest-time-end-sound-dropdown-button" class="dropdown-menu"
415+
id="rest-time-end-sound-select">
416+
</div>
417+
</div><br/>
418+
</div>
419+
<div class="col-5 custom-notify-sound-rest-time-end">
420+
<label>
421+
${ i18n.__("custom-notify-sound") }
422+
</label>
423+
</div>
424+
<div class="col-7 text-right custom-notify-sound-rest-time-end">
425+
<input id="custom-notify-sound-rest-time-end" name="custom-notify-sound-rest-time-end"
426+
type="text" class="hotkey-set-input extreme-small text-right"
427+
placeholder="${ i18n.__('input-url') }"
428+
onkeyup="store.set('custom-rest-time-end-sound',$('#custom-notify-sound-rest-time-end').val());" />
429+
</div><br/>
430+
<div class="col-7">
403431
<label>
404432
${ i18n.__("personalization-notify-sound-msg-all-end") }
405433
</label>
@@ -788,34 +816,54 @@ function personalizedNotification() {
788816
function personalizationSoundInitializer() {
789817
if (store.has("custom-work-time-end-sound"))
790818
$("#custom-notify-sound-work-time-end").val(store.get("custom-work-time-end-sound"));
819+
if (store.has("custom-rest-time-end-sound"))
820+
$("#custom-notify-sound-rest-time-end").val(store.get("custom-rest-time-end-sound"));
791821
if (store.has("custom-all-time-end-sound"))
792-
$("#custom-notify-sound-all-time-end").val(store.get("custom-work-all-end-sound"));
822+
$("#custom-notify-sound-all-time-end").val(store.get("custom-all-time-end-sound"));
793823
let player = document.createElement("audio");//alert player
794824
let soundList = ['alarming', 'beep', 'clock', 'tick', 'trumpet', 'whistle', 'horns', 'magic', 'piano', i18n.__('custom')];
795825
for (let i in soundList) {
796826
$("#work-time-end-sound-select").append("\
797827
<a class='dropdown-item' href='javascript:workTimeEndSoundSetting(\"" + soundList[i] + "\")'>"
798828
+ soundList[i] + "</a>");
799829
}
800-
$("#work-time-end-sound-dropdown-button").text(store.has("time-end-sound") ? store.get("time-end-sound") : "tick");
801-
if (store.get("time-end-sound") === i18n.__('custom'))
802-
$(".custom-notify-sound-work-time-end").css("display", "inline-block");
803-
else
804-
$(".custom-notify-sound-work-time-end").css("display", "none");
805-
830+
for (let i in soundList) {
831+
$("#rest-time-end-sound-select").append("\
832+
<a class='dropdown-item' href='javascript:restTimeEndSoundSetting(\"" + soundList[i] + "\")'>"
833+
+ soundList[i] + "</a>");
834+
}
806835
for (let i in soundList) {
807836
$("#all-time-end-sound-select").append("\
808837
<a class='dropdown-item' href='javascript:allTimeEndSoundSetting(\"" + soundList[i] + "\")'>"
809838
+ soundList[i] + "</a>");
810839
}
811-
$("#all-time-end-sound-dropdown-button").text(store.has("all-end-sound") ? store.get("all-end-sound") : "piano");
812-
if (store.get("all-end-sound") === i18n.__('custom'))
840+
841+
let workSelection = store.has("work-time-end-sound") ? store.get("work-time-end-sound")
842+
: (store.has("time-end-sound") ? store.get("time-end-sound") : "tick");
843+
$("#work-time-end-sound-dropdown-button").text(workSelection);
844+
if (workSelection === i18n.__('custom'))
845+
$(".custom-notify-sound-work-time-end").css("display", "inline-block");
846+
else
847+
$(".custom-notify-sound-work-time-end").css("display", "none");
848+
849+
let restSelection = store.has("rest-time-end-sound") ? store.get("rest-time-end-sound")
850+
: (store.has("time-end-sound") ? store.get("time-end-sound") : "tick");
851+
$("#rest-time-end-sound-dropdown-button").text(restSelection);
852+
if (restSelection === i18n.__('custom'))
853+
$(".custom-notify-sound-rest-time-end").css("display", "inline-block");
854+
else
855+
$(".custom-notify-sound-rest-time-end").css("display", "none");
856+
857+
let allSelection = store.has("all-end-sound") ? store.get("all-end-sound") : "piano";
858+
$("#all-time-end-sound-dropdown-button").text(allSelection);
859+
if (allSelection === i18n.__('custom'))
813860
$(".custom-notify-sound-all-time-end").css("display", "inline-block");
814861
else
815862
$(".custom-notify-sound-all-time-end").css("display", "none");
816863
}
817864

818865
function workTimeEndSoundSetting(val) {
866+
store.set("work-time-end-sound", val);
819867
store.set("time-end-sound", val);
820868
$("#work-time-end-sound-dropdown-button").text(val);
821869
if (val !== i18n.__('custom'))
@@ -832,6 +880,23 @@ function workTimeEndSoundSetting(val) {
832880
$(".custom-notify-sound-work-time-end").css("display", "inline-block");
833881
}
834882

883+
function restTimeEndSoundSetting(val) {
884+
store.set("rest-time-end-sound", val);
885+
$("#rest-time-end-sound-dropdown-button").text(val);
886+
if (val !== i18n.__('custom'))
887+
try {
888+
$(".custom-notify-sound-rest-time-end").css("display", "none");
889+
let player = document.createElement("audio");//alert player
890+
player.src = path.join(__dirname, "\\res\\sound\\" + val + ".mp3");
891+
player.loop = false;
892+
player.play();
893+
} catch (e) {
894+
console.log(e);
895+
}
896+
else
897+
$(".custom-notify-sound-rest-time-end").css("display", "inline-block");
898+
}
899+
835900
function allTimeEndSoundSetting(val) {
836901
store.set("all-end-sound", val);
837902
$("#all-time-end-sound-dropdown-button").text(val);

supporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function isInDark() {
8585
'.switch-slide-label {background: #333;} ' +
8686
'.switch-slide-label:after {background: #ccc !important;}' +
8787
'.card {background-color: #191919; border: 1px solid rgba(255,255,255,.125);} ' +
88-
'.settings-title {color: #ddd; text-transform: uppercase;}' +
88+
'.settings-title {color: #ddd;}' +
8989
'#dialog-msg {color: #ccc;}' +
9090
'.dropdown-default {color: #aaa;}' +
9191
'.dropdown-toggle::before {color: #aaa;}' +

timer.html

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -836,14 +836,30 @@ <h3>
836836
timingData.set("last-recorded-hours-left", -1);
837837
let player = document.createElement('audio');
838838
amplifyMedia(player, amplifierList[store.get("sound")]);
839-
if (isend !== 0) {
840-
if (store.get("time-end-sound") !== i18n.__("custom"))
841-
player.src = path.join(__dirname, "\\res\\sound\\" + (store.has("time-end-sound") ? store.get("time-end-sound") : "tick") + ".mp3");
842-
else if ((!store.has("custom-work-time-end-sound") || store.get("custom-work-time-end-sound") === "")
843-
&& store.get("time-end-sound") === i18n.__("custom"))
844-
player.src = path.join(__dirname, "\\res\\sound\\tick.mp3");
845-
else
846-
player.src = store.get("custom-work-time-end-sound");
839+
if (isend === 1) {
840+
let workSelection = store.has("work-time-end-sound") ? store.get("work-time-end-sound")
841+
: (store.has("time-end-sound") ? store.get("time-end-sound") : "tick");
842+
if (workSelection !== i18n.__("custom"))
843+
player.src = path.join(__dirname, "\\res\\sound\\" + workSelection + ".mp3");
844+
else {
845+
let customWork = store.get("custom-work-time-end-sound");
846+
if (!customWork || customWork === "")
847+
customWork = path.join(__dirname, "\\res\\sound\\tick.mp3");
848+
player.src = customWork;
849+
}
850+
} else if (isend === 2) {
851+
let restSelection = store.has("rest-time-end-sound") ? store.get("rest-time-end-sound")
852+
: (store.has("time-end-sound") ? store.get("time-end-sound") : "tick");
853+
if (restSelection !== i18n.__("custom"))
854+
player.src = path.join(__dirname, "\\res\\sound\\" + restSelection + ".mp3");
855+
else {
856+
let customRest = store.get("custom-rest-time-end-sound");
857+
if (!customRest || customRest === "")
858+
customRest = store.get("custom-work-time-end-sound");
859+
if (!customRest || customRest === "")
860+
customRest = path.join(__dirname, "\\res\\sound\\tick.mp3");
861+
player.src = customRest;
862+
}
847863
} else {
848864
if (store.get("all-end-sound") !== i18n.__("custom"))
849865
player.src = path.join(__dirname, "\\res\\sound\\" + (store.has("all-end-sound") ? store.get("all-end-sound") : "piano") + ".mp3");

0 commit comments

Comments
 (0)