Skip to content

Commit

Permalink
adds ability to detect new releases
Browse files Browse the repository at this point in the history
  • Loading branch information
yamatt committed Nov 17, 2023
1 parent f905d20 commit 5244fb7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/js/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Shortcuts from "./shortcuts.js";
import Info from "./info.js";
import Media from "./media.js";
import Gestures from "./gestures.js";
import Updater from "./updater.js";


export default class StaticPlayer {
Expand All @@ -22,6 +23,8 @@ export default class StaticPlayer {

GESTURES = Gestures;

UPDATER = Updater;

#background_video;
#background;
#player_el;
Expand All @@ -31,6 +34,7 @@ export default class StaticPlayer {
#info;
#media;
#gestures;
#updater;


get background_video_el (){
Expand Down Expand Up @@ -96,11 +100,19 @@ export default class StaticPlayer {
return this.#gestures;
}

get updater () {
if(!this.#updater) {
this.#updater = new this.UPDATER(this);
}
return this.#updater;
}

run() {
this.shortcuts.setup();
this.player.start();
this.background.start();
this.media.start();
this.gestures.start();
this.updater.start();
}
}
50 changes: 50 additions & 0 deletions src/js/updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export default class Updater {
RELEASE_URL = "release"
RELESE_CHECK_SECONDS = 60 // low for testing

constructor (parent) {
this.parent = parent;

this.this_release = null;
this.check_loop = null;
}

get_release(url, callback) {
return fetch(url)
.then(function(response) {
if (!response.ok) {
throw new Error("HTTP error, status = " + response.status);
}
return response.text();
})
.then(callback.bind(this))
}

update_release(release) {
this.release = release;
}

start_check_loop() {
const delay = this.RELESE_CHECK_SECONDS * 1000 // in milliseconds

this.check_loop = setInterval(this.check_release.bind(this), delay);
}

check_release() {
let that = this;
this.get_release(this.RELEASE_URL, (latest_release) => {
if (latest_release != that.release) {
that.refresh_page()
}
})
}

refresh_page() {
window.location.reload();
}

start() {
this.get_release(this.RELEASE_URL, this.update_release)
.then(this.start_check_loop.bind(this));
}
}

0 comments on commit 5244fb7

Please sign in to comment.