Skip to content

Commit 66b4b90

Browse files
committed
Revert "add screensaver (#17)"
This reverts commit 14e72a9.
1 parent 392e43b commit 66b4b90

File tree

7 files changed

+23
-166
lines changed

7 files changed

+23
-166
lines changed

client/idler.ts

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
import { ScreensaverUI } from "./uis/screensaver";
2-
31
export class Idler {
42
private _idle: boolean = false;
53
private _lastActivity: number = Date.now();
64
private _idleAfter: number = 300000; // 5 minutes
5+
private _takeActionAfter: number = 2520000; // 42 minutes
76
private _isLockScreen: boolean;
8-
private _screensaverUI: ScreensaverUI;
97

108
public constructor(isLockScreen: boolean = false) {
119
this._isLockScreen = isLockScreen;
12-
this._screensaverUI = new ScreensaverUI(isLockScreen);
1310

1411
// Listen for keyboard and mouse events
15-
window.addEventListener("keydown", this._stopIdling.bind(this));
16-
window.addEventListener("mousemove", this._stopIdling.bind(this));
17-
window.addEventListener("mousedown", this._stopIdling.bind(this));
12+
window.addEventListener("keydown", this._unidle.bind(this));
13+
window.addEventListener("mousemove", this._unidle.bind(this));
14+
window.addEventListener("mousedown", this._unidle.bind(this));
1815

1916
// Check for idle at a regular interval
2017
setInterval(this._checkIdle.bind(this), 1000);
@@ -28,41 +25,38 @@ export class Idler {
2825
return this._idle;
2926
}
3027

31-
/**
32-
* Start idling and show the screensaver.
33-
*/
34-
private _startIdling(): void {
35-
this._idle = true;
36-
this._screensaverUI.start();
28+
private _unidle(): void {
29+
this._lastActivity = Date.now();
30+
this._idle = false;
3731
}
3832

39-
/**
40-
* Stop the screensaver and reset the idle timer.
41-
* @param ev The event that triggered this function.
42-
*/
43-
private _stopIdling(ev: Event | null = null): void {
44-
this._lastActivity = Date.now();
33+
private _action(): void {
34+
// TODO: start screensaver?
35+
// Warning: this function is called from a setInterval, so it should return if the action is already running
36+
}
37+
38+
private _checkIfActionNeeded(): boolean {
4539
if (this._idle) {
46-
if (ev) {
47-
ev.preventDefault(); // Prevent the event from bubbling up and causing unwanted UI interactions
40+
// Check if we should take action
41+
if (Date.now() - this._lastActivity >= this._takeActionAfter) {
42+
this._action();
43+
return true;
4844
}
49-
this._screensaverUI.stop();
50-
this._idle = false;
5145
}
46+
return false;
5247
}
5348

54-
/**
55-
* Check if the computer is idling (e.g. no keyboard or mouse interactions for a certain amount of time).
56-
* @returns True if the computer is idling, false otherwise.
57-
*/
5849
private _checkIdle(): boolean {
5950
if (this._idle) {
51+
this._checkIfActionNeeded();
6052
return true;
6153
}
6254

6355
// Check if we're idle
6456
if (Date.now() - this._lastActivity >= this._idleAfter) {
65-
this._startIdling();
57+
this._idle = true;
58+
console.log("Now idling...");
59+
this._checkIfActionNeeded(); // Needed if idleAfter and takeActionAfter share the same value
6660
return true;
6761
}
6862
return false;

client/uis/screensaver.ts

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +0,0 @@
1-
import { BlankScreensaver } from "./screensavers/blank";
2-
3-
export class ScreensaverUI {
4-
private _canvasWrapper: HTMLElement;
5-
private _canvas: HTMLCanvasElement;
6-
private _isRunning: boolean = false;
7-
private _screensaver = new BlankScreensaver();
8-
private _isLockScreen: boolean;
9-
10-
public constructor(isLockScreen: boolean = false) {
11-
this._isLockScreen = isLockScreen;
12-
this._canvasWrapper = document.getElementById('screensaver-wrapper') as HTMLElement;
13-
this._canvas = document.getElementById('screensaver-canvas') as HTMLCanvasElement;
14-
}
15-
16-
/**
17-
* Draw 1 frame of the currently selected screensaver.
18-
*/
19-
private _draw(): void {
20-
if (!this._isRunning) {
21-
return;
22-
}
23-
24-
const ctx = this._canvas.getContext('2d');
25-
if (!ctx) {
26-
return;
27-
}
28-
29-
this._screensaver.draw(ctx, this._canvas.width, this._canvas.height);
30-
31-
if (this._isRunning && this._screensaver.getName() !== 'Blank') {
32-
requestAnimationFrame(this._draw.bind(this));
33-
}
34-
};
35-
36-
/**
37-
* Start running the screensaver.
38-
*/
39-
public start(): void {
40-
this._isRunning = true;
41-
this._canvasWrapper.classList.add('active');
42-
this._canvas.width = window.innerWidth;
43-
this._canvas.height = window.innerHeight;
44-
this._draw();
45-
};
46-
47-
/**
48-
* Stop running the screensaver.
49-
*/
50-
public stop(): void {
51-
this._isRunning = false;
52-
this._canvasWrapper.classList.remove('active');
53-
};
54-
}

client/uis/screensavers/base.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

client/uis/screensavers/blank.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build": "tsc",
88
"bundle": "webpack --mode=production",
99
"bundle-dev": "webpack --mode=development",
10-
"test": "open dist/index.html"
10+
"test": "echo \"Error: no test specified\" && exit 1"
1111
},
1212
"repository": {
1313
"type": "git",

static/index.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ <h3>This computer is reserved for an exam between <span id="exam-mode-start">...
9494
</div>
9595
</footer>
9696

97-
<!-- Screensaver -->
98-
<div id="screensaver-wrapper">
99-
<canvas id="screensaver-canvas" width="1920" height="1080"></canvas>
100-
</div>
101-
10297
<!-- Scripts (paths are relative to the dist folder) -->
10398
<script src="bundle.js"></script>
10499
</body>

static/styles.css

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -610,54 +610,3 @@ dialog.calendar-event-dialog .dialog-close-button {
610610
dialog.calendar-event-dialog .dialog-close-button:hover {
611611
color: var(--color-text-primary);
612612
}
613-
614-
/* ***************************************** */
615-
/* Screensaver */
616-
/* ***************************************** */
617-
618-
#screensaver-wrapper {
619-
display: block;
620-
position: fixed;
621-
top: 0;
622-
left: 0;
623-
width: 100%;
624-
height: 100%;
625-
background-color: var(--color-bg);
626-
z-index: 999;
627-
opacity: 0;
628-
pointer-events: none;
629-
/* play fade-out animation once */
630-
animation: fade-out 0.15s ease-in-out 0s 1 normal;
631-
}
632-
633-
#screensaver-wrapper.active {
634-
opacity: 1;
635-
pointer-events: all; /* take over the screen */
636-
/* play fade-in animation once */
637-
animation: fade-in 0.5s ease-in-out 0s 1 normal;
638-
cursor: none !important; /* hide cursor */
639-
}
640-
641-
@keyframes fade-in {
642-
0% {
643-
opacity: 0;
644-
}
645-
100% {
646-
opacity: 1;
647-
}
648-
}
649-
650-
@keyframes fade-out {
651-
0% {
652-
opacity: 1;
653-
}
654-
100% {
655-
opacity: 0;
656-
}
657-
}
658-
659-
#screensaver-canvas {
660-
width: 100%;
661-
height: 100%;
662-
object-fit: cover; /* in case the screen isn't perfectly 16:9 */
663-
}

0 commit comments

Comments
 (0)