Skip to content

Commit 82f1abd

Browse files
committed
New: Check if there is a new version when starting OpenComic
1 parent ae8e195 commit 82f1abd

File tree

12 files changed

+186
-10
lines changed

12 files changed

+186
-10
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
### 🚀 New Features
1010

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

1314
### 🐛 Bug Fixes
1415

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

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

languages/ca.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@
111111
"others": {
112112
"main": "Altres configuracions",
113113
"startInFullScreen": "Inicia OpenComic a pantalla completa"
114+
},
115+
"releases": {
116+
"main": "Comprovar noves versions",
117+
"checkReleases": "Comprovar si hi ha una nova versió en iniciar OpenComic",
118+
"checkPreReleases": "Mostrar versions preliminars (versions beta/alfa)"
114119
}
115120
},
116121
"menu": {
@@ -164,14 +169,19 @@
164169
"readingConfigName": "Nom de la configuració",
165170
"readingConfigRemoveHeader": "Eliminar la configuració",
166171
"readingConfigRemove": "Esteu segur que voleu eliminar aquesta configuració?"
172+
},
173+
"release": {
174+
"title": "Nova versió disponible <b>{{releaseName}}</b>",
175+
"body": "Podeu veure els canvis implementats des de la {{{linkStart}}}pàgina de llançament{{{linkEnd}}}"
167176
}
168177
},
169178
"buttons": {
170179
"cancel": "Cancel·lar",
171180
"ok": "Ok",
172181
"undo": "Desfer",
173182
"dismiss": "Descarta",
174-
"remove": "Eliminar"
183+
"remove": "Eliminar",
184+
"download": "Descarregar"
175185
},
176186
"error": {
177187
"uncompress": {

languages/en.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@
111111
"others": {
112112
"main": "Others settings",
113113
"startInFullScreen": "Start OpenComic in full screen"
114+
},
115+
"releases": {
116+
"main": "Check for new versions",
117+
"checkReleases": "Check if there is a new version when starting OpenComic",
118+
"checkPreReleases": "Show pre-release versions (beta/alpha versions)"
114119
}
115120
},
116121
"menu": {
@@ -164,14 +169,19 @@
164169
"readingConfigName": "Configuration name",
165170
"readingConfigRemoveHeader": "Remove configuration",
166171
"readingConfigRemove": "Are you sure you want to remove this configuration?"
172+
},
173+
"release": {
174+
"title": "New version available <b>{{releaseName}}</b>",
175+
"body": "You can see the implemented changes from the {{{linkStart}}}release page{{{linkEnd}}}"
167176
}
168177
},
169178
"buttons": {
170179
"cancel": "Cancel",
171180
"ok": "Ok",
172181
"undo": "Undo",
173182
"dismiss": "Dismiss",
174-
"remove": "Remove"
183+
"remove": "Remove",
184+
"download": "Download"
175185
},
176186
"error": {
177187
"uncompress": {

languages/es.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@
111111
"others": {
112112
"main": "Otras ajustes",
113113
"startInFullScreen": "Inicial OpenComic en pantalla completa"
114+
},
115+
"releases": {
116+
"main": "Comprobar nuevas versiones",
117+
"checkReleases": "Comprobar si existe una nueva versión al iniciar OpenComic",
118+
"checkPreReleases": "Mostrar versiones preliminares (versiones beta/alfa)"
114119
}
115120
},
116121
"menu": {
@@ -164,14 +169,19 @@
164169
"readingConfigName": "Nombre de la configuración",
165170
"readingConfigRemoveHeader": "Eliminar configuración",
166171
"readingConfigRemove": "¿Seguro que quiere eliminar esta configuración?"
172+
},
173+
"release": {
174+
"title": "Nueva versión disponible <b>{{releaseName}}</b>",
175+
"body": "Puede ver los cambios implementados desde la {{{linkStart}}}página de lanzamiento{{{linkEnd}}}"
167176
}
168177
},
169178
"buttons": {
170179
"cancel": "Cancelar",
171180
"ok": "Ok",
172181
"undo": "Deshacer",
173182
"dismiss": "Descartar",
174-
"remove": "Eliminar"
183+
"remove": "Eliminar",
184+
"download": "Descargar"
175185
},
176186
"error": {
177187
"uncompress": {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "opencomic",
33
"productName": "OpenComic",
4-
"version": "1.0.0",
4+
"version": "1.0.0-beta.2",
55
"main": "scripts/main.js",
66
"keywords": [
77
"comics",

scripts/check-releases.js

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
function showReleaseDialog(release)
3+
{
4+
events.dialog({
5+
header: hb.compile(language.dialog.release.title)({releaseName: release.name}),
6+
width: 360,
7+
height: false,
8+
content: hb.compile(language.dialog.release.body)({linkStart: '<a href="javascript:void(0);" class="link" onclick="electron.shell.openExternal(\''+release.html_url+'\')">', linkEnd: '</a>'}),
9+
buttons: [
10+
{
11+
text: language.buttons.dismiss,
12+
function: 'events.closeDialog(); checkReleases.setLastCheckedRelease(\''+release.name+'\')',
13+
},
14+
{
15+
text: language.buttons.download,
16+
function: 'electron.shell.openExternal(\''+release.html_url+'\');',
17+
}
18+
],
19+
});
20+
}
21+
22+
function setLastCheckedRelease(name)
23+
{
24+
storage.updateVar('config', 'lastCheckedRelease', name);
25+
}
26+
27+
function versionIsHigher(lowest, highest)
28+
{
29+
let l = lowest.replace(/^[a-z]+/iu, '').split(/[.-]/);
30+
let h = highest.replace(/^[a-z]+/iu, '').split(/[.-]/);
31+
32+
for(let key in l)
33+
{
34+
if(l[key] > h[key] || (h[key] === undefined && !isNaN(l[key])))
35+
break;
36+
else if(h[key] === undefined || l[key] < h[key])
37+
return true;
38+
}
39+
40+
return false;
41+
}
42+
43+
function check()
44+
{
45+
let now = Date.now();
46+
47+
if(now - config.lastCheckedReleaseTime < 3600000) // Check at most once an hour
48+
return;
49+
50+
storage.updateVar('config', 'lastCheckedReleaseTime', now);
51+
52+
let options = {
53+
headers:{
54+
'User-Agent': window.navigator.userAgent,
55+
},
56+
};
57+
58+
console.log('Checking for new release');
59+
60+
fetch('https://api.github.com/repos/ollm/OpenComic/releases', options).then(async function(response){
61+
62+
let json = await response.json();
63+
64+
let lastRelease = false;
65+
66+
for(let key in json)
67+
{
68+
let release = json[key];
69+
70+
if(!release.draft && (config.checkPreReleases || !release.prerelease))
71+
{
72+
lastRelease = release;
73+
break;
74+
}
75+
}
76+
77+
if(lastRelease)
78+
{
79+
if(lastRelease.name != config.lastCheckedRelease && lastRelease.name != _package.version && versionIsHigher(_package.version, lastRelease.name))
80+
{
81+
showReleaseDialog(lastRelease);
82+
83+
console.log('New release available');
84+
}
85+
else
86+
{
87+
console.log('Not new release available');
88+
}
89+
}
90+
91+
});
92+
}
93+
94+
module.exports = {
95+
check: check,
96+
setLastCheckedRelease: setLastCheckedRelease,
97+
};

scripts/opencomic.js

+4
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ const app = require(p.join(appDir, 'scripts/app.js')),
215215
settings = require(p.join(appDir, 'scripts/settings.js')),
216216
theme = require(p.join(appDir, 'scripts/theme.js')),
217217
dragAndDrop = require(p.join(appDir, 'scripts/drag-and-drop.js')),
218+
checkReleases = require(p.join(appDir, 'scripts/check-releases.js')),
218219
tracking = require(p.join(appDir, 'scripts/tracking.js')),
219220
trackingSites = require(p.join(appDir, 'scripts/tracking/tracking-sites.js'));
220221

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

249250
function startApp()
250251
{
252+
if(config.checkReleases)
253+
checkReleases.check();
254+
251255
template.loadContentRight('index.content.right.module.html', false);
252256
template.loadHeader('index.header.html', false);
253257
template.loadContentLeft('index.content.left.html', false);

scripts/settings.js

+15
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,26 @@ function setStartInFullScreen(value)
2828
storage.updateVar('config', 'startInFullScreen', value);
2929
}
3030

31+
function setCheckReleases(value)
32+
{
33+
storage.updateVar('config', 'checkReleases', value);
34+
35+
dom.query('.settings-check-prereleases').class(!value, 'disable-pointer');
36+
}
37+
38+
function setCheckPreReleases(value)
39+
{
40+
storage.updateVar('config', 'checkPreReleases', value);
41+
}
42+
43+
3144
module.exports = {
3245
start: start,
3346
setMaxMargin: setMaxMargin,
3447
setGlobalZoom: setGlobalZoom,
3548
setShowFullPathLibrary: setShowFullPathLibrary,
3649
setShowFullPathOpened: setShowFullPathOpened,
3750
setStartInFullScreen: setStartInFullScreen,
51+
setCheckReleases: setCheckReleases,
52+
setCheckPreReleases: setCheckPreReleases,
3853
};

scripts/storage.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var changes = 43; // Update this if readingPagesConfig is updated
1+
var changes = 44; // Update this if readingPagesConfig is updated
22

33
var readingPagesConfig = {
44
readingConfigName: '',
@@ -67,6 +67,10 @@ var storageDefault = {
6767
controllerDeadZone: 0.06,
6868
startInFullScreen: false,
6969
renderMaxWidth: 12000,
70+
checkReleases: true,
71+
checkPreReleases: true,
72+
lastCheckedRelease: '',
73+
lastCheckedReleaseTime: 0,
7074
trackingSites: {
7175
wildcard: {
7276
favorite: false,

templates/settings.content.right.html

+18
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,22 @@ <h2 class="headline-small">{{language.settings.others.main}}</h2>
5353
</div>
5454
</div>
5555

56+
<h2 class="headline-small">{{language.settings.releases.main}}</h2>
57+
58+
<div class="menu-simple-text">
59+
{{language.settings.releases.checkReleases}}
60+
<div class="switch{{#if config.checkReleases}} a{{/if}}" on="settings.setCheckReleases(true)" off="settings.setCheckReleases(false)">
61+
<div></div>
62+
<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>
63+
</div>
64+
</div>
65+
66+
<div class="menu-simple-text settings-check-prereleases{{#unless config.checkReleases}} disable-pointer{{/unless}}">
67+
{{language.settings.releases.checkPreReleases}}
68+
<div class="switch{{#if config.checkPreReleases}} a{{/if}}" on="settings.setCheckPreReleases(true)" off="settings.setCheckPreReleases(false)">
69+
<div></div>
70+
<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>
71+
</div>
72+
</div>
73+
5674
</div>

themes/material-design/actions.css

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
.link
3+
{
4+
color: var(--md-sys-color-primary);
5+
text-decoration: none;
6+
}
7+
28
/* Buttons */
39

410
.floating-action-button
@@ -548,15 +554,15 @@
548554
height: 32px;
549555
padding: 0px 24px;
550556
line-height: 32px;
551-
transition: background-color 0.2s;
557+
transition: background-color 0.2s, opacity 0.2s;
552558
}
553559

554560
.menu-simple-text, .menu-simple-button
555561
{
556562
height: 52px;
557563
padding: 0px 24px;
558564
line-height: 52px;
559-
transition: background-color 0.2s;
565+
transition: background-color 0.2s, opacity 0.2s;
560566
}
561567

562568
.menu-simple-text .switch
@@ -1067,15 +1073,15 @@
10671073
{
10681074
min-height: 64px;
10691075
padding: 0px 24px 15px 24px;
1070-
transition: background-color 0.2s;
1076+
transition: background-color 0.2s, opacity 0.2s;
10711077
box-sizing: border-box;
10721078
}
10731079

10741080
.simple-slider-text
10751081
{
10761082
min-height: 32px;
10771083
line-height: 32px;
1078-
transition: background-color 0.2s;
1084+
transition: background-color 0.2s, opacity 0.2s;
10791085
margin-bottom: 15px;
10801086
}
10811087

themes/material-design/settings.css

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
max-width: 900px;
55
margin: auto;
66
padding-top: 30px;
7+
padding-bottom: 60px;
78
}
89

910
.settings-body h1, .settings-body h2

0 commit comments

Comments
 (0)