Skip to content

Commit

Permalink
New: Check if there is a new version when starting OpenComic
Browse files Browse the repository at this point in the history
  • Loading branch information
ollm committed Aug 24, 2023
1 parent ae8e195 commit 82f1abd
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### 🚀 New Features

- Reload button in file list [`31675a5`](https://github.com/ollm/OpenComic/commit/31675a5a8334abedc056a09a5107f718dc5304e0)
- Check if there is a new version when starting OpenComic

### 🐛 Bug Fixes

- Improved local artwork assets support [`f21cccd`](https://github.com/ollm/OpenComic/commit/f21cccd9c2c943f7ad8735e106afff453397cfbf)
- Some errors on Tracking feature [`50d8487`](https://github.com/ollm/OpenComic/commit/50d84874ea99cdace27f2c3bfc994b3338f23a42)
- Updated snackbar to Material 3
- Updated snackbar to Material 3 [`ae8e195`](https://github.com/ollm/OpenComic/commit/ae8e1955dd10b9f54166dddd1af8281c67bb841a)

## [v1.0.0-beta.1](https://github.com/ollm/OpenComic/releases/tag/v1.0.0-beta.1) (22-08-2023)

Expand Down
12 changes: 11 additions & 1 deletion languages/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@
"others": {
"main": "Altres configuracions",
"startInFullScreen": "Inicia OpenComic a pantalla completa"
},
"releases": {
"main": "Comprovar noves versions",
"checkReleases": "Comprovar si hi ha una nova versió en iniciar OpenComic",
"checkPreReleases": "Mostrar versions preliminars (versions beta/alfa)"
}
},
"menu": {
Expand Down Expand Up @@ -164,14 +169,19 @@
"readingConfigName": "Nom de la configuració",
"readingConfigRemoveHeader": "Eliminar la configuració",
"readingConfigRemove": "Esteu segur que voleu eliminar aquesta configuració?"
},
"release": {
"title": "Nova versió disponible <b>{{releaseName}}</b>",
"body": "Podeu veure els canvis implementats des de la {{{linkStart}}}pàgina de llançament{{{linkEnd}}}"
}
},
"buttons": {
"cancel": "Cancel·lar",
"ok": "Ok",
"undo": "Desfer",
"dismiss": "Descarta",
"remove": "Eliminar"
"remove": "Eliminar",
"download": "Descarregar"
},
"error": {
"uncompress": {
Expand Down
12 changes: 11 additions & 1 deletion languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@
"others": {
"main": "Others settings",
"startInFullScreen": "Start OpenComic in full screen"
},
"releases": {
"main": "Check for new versions",
"checkReleases": "Check if there is a new version when starting OpenComic",
"checkPreReleases": "Show pre-release versions (beta/alpha versions)"
}
},
"menu": {
Expand Down Expand Up @@ -164,14 +169,19 @@
"readingConfigName": "Configuration name",
"readingConfigRemoveHeader": "Remove configuration",
"readingConfigRemove": "Are you sure you want to remove this configuration?"
},
"release": {
"title": "New version available <b>{{releaseName}}</b>",
"body": "You can see the implemented changes from the {{{linkStart}}}release page{{{linkEnd}}}"
}
},
"buttons": {
"cancel": "Cancel",
"ok": "Ok",
"undo": "Undo",
"dismiss": "Dismiss",
"remove": "Remove"
"remove": "Remove",
"download": "Download"
},
"error": {
"uncompress": {
Expand Down
12 changes: 11 additions & 1 deletion languages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@
"others": {
"main": "Otras ajustes",
"startInFullScreen": "Inicial OpenComic en pantalla completa"
},
"releases": {
"main": "Comprobar nuevas versiones",
"checkReleases": "Comprobar si existe una nueva versión al iniciar OpenComic",
"checkPreReleases": "Mostrar versiones preliminares (versiones beta/alfa)"
}
},
"menu": {
Expand Down Expand Up @@ -164,14 +169,19 @@
"readingConfigName": "Nombre de la configuración",
"readingConfigRemoveHeader": "Eliminar configuración",
"readingConfigRemove": "¿Seguro que quiere eliminar esta configuración?"
},
"release": {
"title": "Nueva versión disponible <b>{{releaseName}}</b>",
"body": "Puede ver los cambios implementados desde la {{{linkStart}}}página de lanzamiento{{{linkEnd}}}"
}
},
"buttons": {
"cancel": "Cancelar",
"ok": "Ok",
"undo": "Deshacer",
"dismiss": "Descartar",
"remove": "Eliminar"
"remove": "Eliminar",
"download": "Descargar"
},
"error": {
"uncompress": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "opencomic",
"productName": "OpenComic",
"version": "1.0.0",
"version": "1.0.0-beta.2",
"main": "scripts/main.js",
"keywords": [
"comics",
Expand Down
97 changes: 97 additions & 0 deletions scripts/check-releases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

function showReleaseDialog(release)
{
events.dialog({
header: hb.compile(language.dialog.release.title)({releaseName: release.name}),
width: 360,
height: false,
content: hb.compile(language.dialog.release.body)({linkStart: '<a href="javascript:void(0);" class="link" onclick="electron.shell.openExternal(\''+release.html_url+'\')">', linkEnd: '</a>'}),
buttons: [
{
text: language.buttons.dismiss,
function: 'events.closeDialog(); checkReleases.setLastCheckedRelease(\''+release.name+'\')',
},
{
text: language.buttons.download,
function: 'electron.shell.openExternal(\''+release.html_url+'\');',
}
],
});
}

function setLastCheckedRelease(name)
{
storage.updateVar('config', 'lastCheckedRelease', name);
}

function versionIsHigher(lowest, highest)
{
let l = lowest.replace(/^[a-z]+/iu, '').split(/[.-]/);
let h = highest.replace(/^[a-z]+/iu, '').split(/[.-]/);

for(let key in l)
{
if(l[key] > h[key] || (h[key] === undefined && !isNaN(l[key])))
break;
else if(h[key] === undefined || l[key] < h[key])
return true;
}

return false;
}

function check()
{
let now = Date.now();

if(now - config.lastCheckedReleaseTime < 3600000) // Check at most once an hour
return;

storage.updateVar('config', 'lastCheckedReleaseTime', now);

let options = {
headers:{
'User-Agent': window.navigator.userAgent,
},
};

console.log('Checking for new release');

fetch('https://api.github.com/repos/ollm/OpenComic/releases', options).then(async function(response){

let json = await response.json();

let lastRelease = false;

for(let key in json)
{
let release = json[key];

if(!release.draft && (config.checkPreReleases || !release.prerelease))
{
lastRelease = release;
break;
}
}

if(lastRelease)
{
if(lastRelease.name != config.lastCheckedRelease && lastRelease.name != _package.version && versionIsHigher(_package.version, lastRelease.name))
{
showReleaseDialog(lastRelease);

console.log('New release available');
}
else
{
console.log('Not new release available');
}
}

});
}

module.exports = {
check: check,
setLastCheckedRelease: setLastCheckedRelease,
};
4 changes: 4 additions & 0 deletions scripts/opencomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ const app = require(p.join(appDir, 'scripts/app.js')),
settings = require(p.join(appDir, 'scripts/settings.js')),
theme = require(p.join(appDir, 'scripts/theme.js')),
dragAndDrop = require(p.join(appDir, 'scripts/drag-and-drop.js')),
checkReleases = require(p.join(appDir, 'scripts/check-releases.js')),
tracking = require(p.join(appDir, 'scripts/tracking.js')),
trackingSites = require(p.join(appDir, 'scripts/tracking/tracking-sites.js'));

Expand Down Expand Up @@ -248,6 +249,9 @@ window.onload = function() {

function startApp()
{
if(config.checkReleases)
checkReleases.check();

template.loadContentRight('index.content.right.module.html', false);
template.loadHeader('index.header.html', false);
template.loadContentLeft('index.content.left.html', false);
Expand Down
15 changes: 15 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,26 @@ function setStartInFullScreen(value)
storage.updateVar('config', 'startInFullScreen', value);
}

function setCheckReleases(value)
{
storage.updateVar('config', 'checkReleases', value);

dom.query('.settings-check-prereleases').class(!value, 'disable-pointer');
}

function setCheckPreReleases(value)
{
storage.updateVar('config', 'checkPreReleases', value);
}


module.exports = {
start: start,
setMaxMargin: setMaxMargin,
setGlobalZoom: setGlobalZoom,
setShowFullPathLibrary: setShowFullPathLibrary,
setShowFullPathOpened: setShowFullPathOpened,
setStartInFullScreen: setStartInFullScreen,
setCheckReleases: setCheckReleases,
setCheckPreReleases: setCheckPreReleases,
};
6 changes: 5 additions & 1 deletion scripts/storage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var changes = 43; // Update this if readingPagesConfig is updated
var changes = 44; // Update this if readingPagesConfig is updated

var readingPagesConfig = {
readingConfigName: '',
Expand Down Expand Up @@ -67,6 +67,10 @@ var storageDefault = {
controllerDeadZone: 0.06,
startInFullScreen: false,
renderMaxWidth: 12000,
checkReleases: true,
checkPreReleases: true,
lastCheckedRelease: '',
lastCheckedReleaseTime: 0,
trackingSites: {
wildcard: {
favorite: false,
Expand Down
18 changes: 18 additions & 0 deletions templates/settings.content.right.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,22 @@ <h2 class="headline-small">{{language.settings.others.main}}</h2>
</div>
</div>

<h2 class="headline-small">{{language.settings.releases.main}}</h2>

<div class="menu-simple-text">
{{language.settings.releases.checkReleases}}
<div class="switch{{#if config.checkReleases}} a{{/if}}" on="settings.setCheckReleases(true)" off="settings.setCheckReleases(false)">
<div></div>
<svg viewBox="0 0 52 32"><path d="M 8,0 C 3.58,0 0,3.58 0,8 0,12.42 3.58,16 8,16 8,16 8,16 8,16 12.42,16 16,12.42 16,8 16,3.58 12.42,0 8,0 8,0 8,0 8,0 Z"></path></svg>
</div>
</div>

<div class="menu-simple-text settings-check-prereleases{{#unless config.checkReleases}} disable-pointer{{/unless}}">
{{language.settings.releases.checkPreReleases}}
<div class="switch{{#if config.checkPreReleases}} a{{/if}}" on="settings.setCheckPreReleases(true)" off="settings.setCheckPreReleases(false)">
<div></div>
<svg viewBox="0 0 52 32"><path d="M 8,0 C 3.58,0 0,3.58 0,8 0,12.42 3.58,16 8,16 8,16 8,16 8,16 12.42,16 16,12.42 16,8 16,3.58 12.42,0 8,0 8,0 8,0 8,0 Z"></path></svg>
</div>
</div>

</div>
14 changes: 10 additions & 4 deletions themes/material-design/actions.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

.link
{
color: var(--md-sys-color-primary);
text-decoration: none;
}

/* Buttons */

.floating-action-button
Expand Down Expand Up @@ -548,15 +554,15 @@
height: 32px;
padding: 0px 24px;
line-height: 32px;
transition: background-color 0.2s;
transition: background-color 0.2s, opacity 0.2s;
}

.menu-simple-text, .menu-simple-button
{
height: 52px;
padding: 0px 24px;
line-height: 52px;
transition: background-color 0.2s;
transition: background-color 0.2s, opacity 0.2s;
}

.menu-simple-text .switch
Expand Down Expand Up @@ -1067,15 +1073,15 @@
{
min-height: 64px;
padding: 0px 24px 15px 24px;
transition: background-color 0.2s;
transition: background-color 0.2s, opacity 0.2s;
box-sizing: border-box;
}

.simple-slider-text
{
min-height: 32px;
line-height: 32px;
transition: background-color 0.2s;
transition: background-color 0.2s, opacity 0.2s;
margin-bottom: 15px;
}

Expand Down
1 change: 1 addition & 0 deletions themes/material-design/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
max-width: 900px;
margin: auto;
padding-top: 30px;
padding-bottom: 60px;
}

.settings-body h1, .settings-body h2
Expand Down

0 comments on commit 82f1abd

Please sign in to comment.