Skip to content

Commit

Permalink
Added function: automatically loop (linuxmint#3657)
Browse files Browse the repository at this point in the history
setting-schema.json
- add an item "auto-loop-enable" to page "General" to select loop on/off.

applet.js
- add variable "timerDurationLoop" to keep current timeDuration for loop .
- modify function "doStartTimer" to save current timeDuration value to new variable "timeDurationLoop".
- modify function "doTimerExpired" to recall the function "doStartTimer".
  • Loading branch information
kancolle386 committed Mar 1, 2021
1 parent 3093b04 commit c63c55c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ MyApplet.prototype = {
_init: function (orientation, panel_height, instance_id) {
Applet.TextIconApplet.prototype._init.call(this, orientation, panel_height, instance_id);
try {

if (this.versionCompare(GLib.getenv('CINNAMON_VERSION'), "3.2") >= 0) {
this.setAllowedLayout(Applet.AllowedLayout.BOTH);
}
this._init_settings();
this.on_orientation_changed(orientation);
this.timerDuration = 0;
this.timerDurationLoop = 0;
this.timerStopped = true;
this.alarmOn = false;
this.state = false;
Expand All @@ -64,7 +65,7 @@ MyApplet.prototype = {
this.doTick();
}
this.doUpdateUI();

}
catch (e) {
global.logError(e);
Expand Down Expand Up @@ -179,6 +180,7 @@ MyApplet.prototype = {
this.ShowMenuOn = this.settings.getValue("display-menu-enable");
this.SoundPath = this.settings.getValue("sound-file");
this.MessageStr = this.settings.getValue("display-message");
this.AutoLoopPromptOn = this.settings.getValue("auto-loop-enable");
this.on_orientation_changed(this._orientation);
},
on_applet_clicked: function (event) {
Expand Down Expand Up @@ -250,7 +252,7 @@ MyApplet.prototype = {
if (preset < 1)
continue;
let label = "";
if (preset_times[i].label) {
if (preset_times[i].label) {
label = preset_times[i].label;
} else {
let hr = Math.floor(preset / 3600);
Expand Down Expand Up @@ -308,6 +310,7 @@ MyApplet.prototype = {
this.timerStopped = false;
this.alarm_start = this.getCurrentTime();
this.alarm_end = this.alarm_start + this.timerDuration * 1000;
this.timerDurationLoop = this.timerDuration;

this.doTick();
this.doUpdateUI();
Expand Down Expand Up @@ -371,7 +374,7 @@ MyApplet.prototype = {
applet_label += durationShortStr;
if (this.alarmtime_display_enable)
applet_label += " " + alarmtimeStr;

this.timerMenuItem.label.text = durationLongStr + " " + alarmtimeExpectedStr;
this.set_applet_tooltip(_("Timer") + ":" + " " + durationShortStr + " " + alarmtimeStr);

Expand Down Expand Up @@ -415,6 +418,11 @@ MyApplet.prototype = {
this.confirm = new ConfirmDialog(message, Lang.bind(this, this.doClearAlarm));
this.confirm.open();
}

if (this.AutoLoopPromptOn) {
this.timerDuration = this.timerDurationLoop;
this.doStartTimer();
}
},

doClearAlarm: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"type": "page",
"title": "General",
"sections": ["section1"]
},
},
"page2": {
"type": "page",
"title": "Sounds",
"sections": ["section2"]
},
},
"page3": {
"type": "page",
"title": "Preset Times",
Expand All @@ -21,20 +21,21 @@
"type": "page",
"title": "Slider Intervals",
"sections": ["section4"]
},
},
"section1": {
"type": "section",
"title": "General Settings",
"keys": [
"confirm-prompt-enable",
"message-prompt-enable",
"display-message",
"display-menu-enable",
"confirm-prompt-enable",
"message-prompt-enable",
"display-message",
"display-menu-enable",
"duration-display-enable",
"alarmtime-display-enable",
"alarmtime-format-small",
"alarmtime-format-large",
"alarmtime-format-switchover"
"alarmtime-format-switchover",
"auto-loop-enable"
]
},
"section2": {
Expand All @@ -46,12 +47,12 @@
"type": "section",
"title": "Preset Times",
"keys": [ "preset_time"]
},
},
"section4": {
"type": "section",
"title": "Slider Intervals",
"keys": [ "slider_intervals"]
}
}
},
"confirm-prompt-enable" : {
"type" : "checkbox",
Expand Down Expand Up @@ -127,6 +128,12 @@
"description" : "Time when switching from small to large time format",
"tooltip" : "Switch over time between the two formats specified above"
},
"auto-loop-enable" : {
"type" : "checkbox",
"default" : false,
"description" : "Restart the timer automatically when time is elapsed",
"tooltip" : "Restart the timer automatically when time is elapsed"
},
"alarm_end" : {
"type" : "generic",
"default" : "",
Expand All @@ -144,7 +151,7 @@
"default" : "",
"description" : "Do not change, message being displayed when the current timer expires",
"tooltip" : "Do not change, message being displayed when the current timer expires"
},
},
"slider_intervals" : {
"type" : "list",
"description" : "Slider Intervals",
Expand All @@ -166,15 +173,15 @@
"columns" : [
{"id": "hours", "title": "Hours", "type": "integer", "min": 0, "max":500, "default": 0},
{"id": "minutes", "title": "Minutes", "type": "integer", "min": 0, "max":59, "default": 0},
{"id": "seconds", "title": "Seconds", "type": "integer", "min": 0, "max":59, "default": 0},
{"id": "seconds", "title": "Seconds", "type": "integer", "min": 0, "max":59, "default": 0},
{"id": "label", "title": "Label", "type": "string"},
{"id": "message", "title": "Custom Message (overrides global message)", "type": "string"}
],
"default": [
{"seconds": 0, "minutes": 0, "hours": 5},
{"seconds": 0, "minutes": 0, "hours": 5},
{"seconds": 0, "minutes": 0, "hours": 4},
{"seconds": 0, "minutes": 0, "hours": 3},
{"seconds": 0, "minutes": 0, "hours": 2},
{"seconds": 0, "minutes": 0, "hours": 3},
{"seconds": 0, "minutes": 0, "hours": 2},
{"seconds": 0, "hours":1, "minutes": 30},
{"seconds": 0, "minutes": 0, "hours": 1},
{"seconds": 0, "minutes": 45, "hours": 0},
Expand All @@ -187,6 +194,6 @@
{"seconds": 0, "minutes": 2, "hours": 0},
{"seconds": 0, "minutes": 1, "hours": 0},
{"seconds": 30, "minutes": 0, "hours": 0}
]
]
}
}

0 comments on commit c63c55c

Please sign in to comment.