Skip to content
Permalink
Browse files

Add auto updates and messages

  • Loading branch information...
ironman5366 committed Apr 23, 2019
1 parent 0848813 commit ea04dce52e04d5d1ad9fe891e1713e46a47c8fa9
Showing with 69 additions and 12 deletions.
  1. +0 −1 README.md
  2. +23 −7 index.html
  3. +1 −1 package.json
  4. +45 −3 page.js
@@ -1,6 +1,5 @@
# KRLX Desktop [![Build Status](https://travis-ci.org/ironman5366/KRLXDesktop.svg?branch=master)](https://travis-ci.org/ironman5366/KRLXDesktop)
A desktop app for [KRLX](http://www.krlx.org/), written in Electron
![Screenshot]: (https://imgur.com/m8YdQyy)

## Features:
- Displays current show and information, pulling host info from Carleton directory
@@ -37,15 +37,31 @@ <h1>Currently On</h1>
<div class="col-md-12" id="currshow">
</div>
</div>
<div class="row"></div>
<div class="row">
<div class="col-md-12">
<div class="row">
<strong class="h1">Status: </strong></h4><span id="currstatus"><span class="badge badge-pill badge-info">Loading...</span></span>
</div>
<div class="row">
Made with ❤️ by Will Beddow '22 & Kristin Albright '22
<br>
&copy <script>document.write(new Date().getFullYear())</script>
<div id="message-card" class="card border-primary">
<div id="messages-title" class="card-header">
Status & Updates
</div>
<div class="card-body">
<h4 id="message-inner-title" class="card-title">Messages:</h4>
<p id="messages" class="card-text"></p>
<h4 id="updates-title" class="card-title">Updates</h4>
<p id="updates"></p>
<h4 class="card-title">Status: <span id="currstatus"><span class="badge badge-pill badge-info">Loading...</span></span></h4>

</div>
<div class="card-footer">
<div class="row">
Made with ❤️ by Will Beddow '22 & Kristin Albright '22
<br>
&copy <script>document.write(new Date().getFullYear())</script>
</div>
</div>
</div>

</div>
</div>

</div>
@@ -1,6 +1,6 @@
{
"name": "krlxdesktop",
"version": "1.0.0",
"version": "1.0.1",
"description": "A desktop player for KRLX",
"main": "index.js",
"scripts": {
48 page.js
@@ -1,7 +1,7 @@
const API_URL = 'http://live.krlx.org/data.php';
const SPOTIFY_API_URL = 'https://api.spotify.com/v1/search';
const SPOTIFY_AUTH_URL = 'https://accounts.spotify.com/api/token';
const { shell } = require('electron');
const { shell, remote } = require('electron');
const Base64 = require('./node_modules/js-base64').Base64;
const fs = require('fs');
const moment = require('./assets/moment.min.js');
@@ -10,6 +10,7 @@ const spotify_api = require('./spotify_api.json');
const DIR_REG = new RegExp('(<div class="email"><span class="icon">' +
'\\n{0,1}<\\/span>(\\w+)&nbsp;)|<span class="icon"><\\/span><a href="mailto:(\\w+)@carleton.edu">');
const HOST_REG = new RegExp('(\\S+) ([^\\s\\d]+ )+(\'(\\d\\d)?|)|(\\S+) (\\S+)');
const UPDATE_URL = 'https://willbeddow.com/app/krlx-desktop';
let curr_songs = [];
let spotify_auth = null;
let song_queries = {
@@ -310,6 +311,47 @@ function query_stream(){
});
}

/**
* Poll my website (willbeddow.com/app/krlx-desktop), for a JSON feed of status messages and app app update aviailability
* Please note: This is the **only** place this app communicates in the background with my servers.
*/
function check_updates(){
$.getJSON({
url: UPDATE_URL,
success: function(data){
console.log("Got update data");
console.log(data);
console.log(shell);
let curr_version = remote.app.getVersion();
let remote_version = data.updates.version;
let update_url = data.updates.update;
let status_message = data.status;
// Update available
if (curr_version === remote_version){
$("#updates-title")[0].style.display = 'none';
$("#updates")[0].innerHTML = "You're all up to date! Version "+curr_version+". <a href='#' onclick='check_updates()'>Check again</a>";
}
else{
$("#updates-title")[0].style.display = 'block';
$("#message-card").addClass("bg-warning");
$("#messages-title").innerHTML = "Update Available!";
$("#updates")[0].innerHTML = "<strong>Update available, <a href='#' onclick='shell.openExternal(\""+update_url+"\")'>get it here!</a>"
}
if (status_message){
$("#message-inner-title")[0].style.display = "block";
$("#message-card").removeClass("border-primary").addClass("border-info");
$("#messages")[0].innerHTML = status_message;
}
else{
$("#message-inner-title")[0].style.display = 'none';
}
},
error: function(jqXHR, textStatus, errorThrown){
console.log("Update check errror "+jqXHR+" "+textStatus+" "+errorThrown);
}
})
}

/**
* Log in with Spotify
*/
@@ -346,9 +388,9 @@ $(document).ready(function(){
spotify_basic_auth(spotify_api);
console.log("Starting interval");
query_stream();
// The handler for checking the KRLX API every 5 seconds
// The handler for checking the KRLX API every 30 seconds
setInterval(query_stream, 30000);
//query_stream();

check_updates();
});

0 comments on commit ea04dce

Please sign in to comment.
You can’t perform that action at this time.