Skip to content

Commit

Permalink
Simple update checker
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicnessTwo committed Mar 20, 2024
1 parent 73bec8f commit e42a517
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
7 changes: 6 additions & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
<div class="p-3">
<div class="flex items-center justify-between">
<div class="flex flex-grow flex-col">
<h1 class="text-2xl font-semibold text-white">StreamLurker</h1>
<h1 class="text-2xl font-semibold text-white flex items-center">
StreamLurker
<span id="update-available" class="hidden ml-2 inline-flex items-center gap-x-1.5 rounded-md bg-green-100 dark:bg-green-700 px-2 py-1 text-xs font-medium text-green-700 dark:text-green-100">
An update is available!
</span>
</h1>
<p class="text-sm font-medium text-gray-200 dark:text-gray-400">Written by EpicKitty</p>
</div>
<div class="relative flex items-end">
Expand Down
4 changes: 4 additions & 0 deletions frontend/js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ ipcRenderer.on('is-syncing', (event, status) => {
document.getElementById('syncing').classList.toggle('opacity-100', status);
});

ipcRenderer.on('update-available', (event, status) => {
document.getElementById('update-available').classList.remove('hidden');
});

document.getElementById('addChannelButton').addEventListener('click', () => {
document.getElementById('add-channel').style.display = 'block';
document.getElementById('channel_name').focus();
Expand Down
41 changes: 40 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,38 @@ const streamStatuses = {};
const notificationTitle = 'Stream Lurker';
const gotTheLock = app.requestSingleInstanceLock();

/**
* Checks for updates on GitHub
* @returns {Promise<boolean>}
*/
async function hasUpdate () {
const currentVersion = app.getVersion();
const url = 'https://api.github.com/repos/EpicnessTwo/StreamLurker/releases/latest';

try {
const response = await axios.get(url, {
headers: { 'User-Agent': 'StreamLurker' }
});

const latestVersion = response.data.tag_name;
console.log(`Current version: ${currentVersion}, Latest version: ${latestVersion}`);

// Compare versions, assuming semantic versioning
return latestVersion !== currentVersion;
} catch (error) {
console.error('Error checking for updates:', error);
return false;
}
};

async function checkForUpdate() {
const updateAvailable = await hasUpdate();
if (updateAvailable) {
console.log('Update available');
win.webContents.send('update-available');
}
}

/**
* Loads the config from the store or config.json
* @returns {Promise<boolean>}
Expand Down Expand Up @@ -208,11 +240,18 @@ async function checkStreams(start) {
if (!token) return;

await processStreams(token);
await checkForUpdate();

if (start) {
// Main stream checking loop
setInterval(async () => {
await processStreams(token);
}, 60000); // Check every minute
}, 60000);

// Check for updates loop
setInterval(async () => {
await checkForUpdate();
}, 3600000);
}
}

Expand Down

0 comments on commit e42a517

Please sign in to comment.