Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buddy alarm #25

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
sdk/nodejs-sdk/node_modules
/.vscode
sdk/nodejs-sdk/node_modules
37 changes: 37 additions & 0 deletions desktop/apps/desktop.alarm/desktop.alarm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div id="window_alarm" data-window-type="alarm" class="abs window">
<div class="abs window_inner">
<div class="window_top">
<span class="float_left"> </span>
<span class="float_right">
<a href="#" class="window_min"></a>
<a href="#" class="window_resize"></a>
<a href="#icon_dock_login" class="window_close"></a>
</span>
</div>
<div class="abs window_content">
<div class="window_main">
<div class="splash">
<div class="table clock-wrapper">
<div class="cell">
<h2 id="clock" class="clock"></h2>

<select id="hours"></select>
<select id="minutes"></select>
<select id="seconds"></select>
<select id="ampm">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>

<p>
<button id="startstop">Set Alarm</button>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="abs window_bottom">Build: v4.20.69</div>
</div>
<span class="abs ui-resizable-handle ui-resizable-se"></span>
</div>
111 changes: 111 additions & 0 deletions desktop/apps/desktop.alarm/desktop.alarm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
desktop.app.alarm = {};
desktop.app.alarm.label = "Alarm";

desktop.app.alarm.load = function loadDesktopLogin() {
desktop.load.remoteAssets(
[
"alarm", // this loads the sibling desktop.app.alarm.html file into <div id="window_alarm"></div>
],
function () {
// if user clicks on top right menu, focus on alarm form
$(".alarmLink").on("click", function () {
$("#window_alarm").show();
});

// set our variables
var time,
alarm,
activeAlarm = false,
buddyStop = false;
/*
audio sound source: https://freesound.org/people/SieuAmThanh/sounds/397787/
*/

function loopAlarm () {
if(buddyStop === false) {
return desktop.play("alarm.mp3", false, loopAlarm);
}
}

// define a function to display the current time
function displayTime() {
var now = new Date();
time = now.toLocaleTimeString();
clock.textContent = time;
// time = "1:00:00 AM";
// watch for alarm
if (time === alarm) {
desktop.play(
"alarm.mp3"
, false, loopAlarm);
}
setTimeout(displayTime, 1000);
}
displayTime();

// add option values relative towards time
function addMinSecVals(id) {
var select = id;
var min = 59;

for (i = 0; i <= min; i++) {
// defined as new Option(text, value)
select.options[select.options.length] = new Option(
i < 10 ? "0" + i : i,
i < 10 ? "0" + i : i
);
}
}
function addHours(id) {
var select = id;
var hour = 12;

for (i = 1; i <= hour; i++) {
// defined as new Option(text, value)
select.options[select.options.length] = new Option(
i < 10 ? "0" + i : i,
i
);
}
}
addMinSecVals(minutes);
addMinSecVals(seconds);
addHours(hours);

// set and clear alarm
startstop.onclick = function () {
// set the alarm
if (activeAlarm === false) {
hours.disabled = true;
minutes.disabled = true;
seconds.disabled = true;
ampm.disabled = true;

alarm =
hours.value +
":" +
minutes.value +
":" +
seconds.value +
" " +
ampm.value;
this.textContent = "Clear Alarm";
activeAlarm = true;
buddyStop = false;
} else {
// clear the alarm
hours.disabled = false;
minutes.disabled = false;
seconds.disabled = false;
ampm.disabled = false;

sound.pause();
alarm = "01:00:00 AM";
this.textContent = "Set Alarm";
activeAlarm = false;
buddyStop = true;
}
};
}
);
};
Binary file added desktop/assets/audio/alarm.mp3
Binary file not shown.
Loading