Commit ea3cd83e authored by Duhoux Pierre-Louis's avatar Duhoux Pierre-Louis

[EVOL] Add option to pause updates for a week after last chapter found

parent 2918e83c
......@@ -241,6 +241,14 @@
"message": "Refresh now",
"description": "Button refresh mirrors list now"
},
"options_gen_stopupdateforaweek_opt": {
"message": "Pause updates for a week after new chapter",
"description": "Option to pause updates for a week after new chapter"
},
"options_gen_stopupdateforaweek_desc": {
"message": "When a new chapter is found, the next one will be released at least a week after. Check the box below to decide to pause updates for a manga during a week after a new chapter has been found. Doing that, updates will restart for two days (one before and one after) after a week. If no chapters are found, updates will be paused for another week and so on.",
"description": "Description of the functionning of the pause updates for a week after new chapter option"
},
"options_gen_checkmgstart_opt": {
"message": "Update on startup",
"description": "Option Update on startup"
......
......@@ -17,7 +17,7 @@ class Updater {
let frequency = store.state.options.updatechap;
if (lastUpdt + frequency < Date.now()) {
// time to refresh !
store.dispatch("updateChaptersLists");
store.dispatch("updateChaptersLists", {force: false}); // force to false to avoid updating if not necessary
}
setTimeout(this.checkChaptersUpdates.bind(this), 60 * 1000); // check every minutes
}
......
......@@ -33,7 +33,7 @@ IconHelper.setBlueIcon();
* If option update chapters lists on startup --> do it
*/
if (store.state.options.checkmgstart === 1) {
store.dispatch("updateChaptersLists");
store.dispatch("updateChaptersLists", {force: false}); // force to false to avoid updating if not necessary
}
// Starts message handling
......
......@@ -50,7 +50,7 @@ class HandleManga {
return store.dispatch("importSamples");
case "updateChaptersLists":
// updates all mangas lists (do it in background if called from popup because it requires jQuery)
return store.dispatch("updateChaptersLists");
return store.dispatch("updateChaptersLists"); // update is forced by default (mangas are updated even if chapters has been found recently (less than a week ago) and the pause for a week option is checked) but is done manually by the user (this case is called from options page or for timers page)
case "searchList":
return this.searchList(message);
case "getListChaps":
......
......@@ -140,6 +140,11 @@
</v-layout>
</v-container>
</div>
<!-- Stop updates for a week -->
<div class="subtitle">{{i18n('options_gen_stopupdateforaweek_desc')}}</div>
<v-checkbox v-model="stopupdateforaweek" @change="setOption('stopupdateforaweek')"
:label="i18n('options_gen_stopupdateforaweek_opt')"></v-checkbox>
<!-- Update mirrors list -->
<div class="subtitle">
<v-container fluid class="opt-container">
......@@ -345,7 +350,8 @@ const converters = {
"savebandwidth",
"displayzero",
"nocount",
"shownotifications"
"shownotifications",
"stopupdateforaweek"
]
}
};
......@@ -477,18 +483,18 @@ export default {
* Updates chapters lists
*/
async updateChaps() {
this.loadingChapters = true;
this.loadingChapters = true
//We don't call the store updateChaptersLists because when refreshing chapters, it will use jQuery (inside implementations), which is not loaded in the popup, let's do it in background
await browser.runtime.sendMessage({ action: "updateChaptersLists" });
this.loadingChapters = false;
await browser.runtime.sendMessage({ action: "updateChaptersLists" }) // update is forced by default (mangas are updated even if chapters has been found recently (less than a week ago) and the pause for a week option is checked) but is done manually by the user (this case is called from options page or for timers page)
this.loadingChapters = false
},
/**
* Update mirrors lists
*/
async updateMirrors() {
this.loadingMirrors = true;
await this.$store.dispatch("updateMirrorsLists");
this.loadingMirrors = false;
this.loadingMirrors = true
await this.$store.dispatch("updateMirrorsLists")
this.loadingMirrors = false
},
/**
* Return language name from code
......
......@@ -93,7 +93,7 @@ export default {
async updateChaps() {
this.loadingChapters = true
//We don't call the store updateChaptersLists because when refreshing chapters, it will use jQuery (inside implementations), which is not loaded in the popup, let's do it in background
await browser.runtime.sendMessage({ action: "updateChaptersLists" })
await browser.runtime.sendMessage({ action: "updateChaptersLists" }) // update is forced by default (mangas are updated even if chapters has been found recently (less than a week ago) and the pause for a week option is checked) but is done manually by the user (this case is called from options page or for timers page)
this.loadingChapters = false
},
/**
......
......@@ -273,9 +273,9 @@ const actions = {
/**
* Update all mangas chapters lists
* @param {*} param0
* @param {*} message
* @param {*} force force update if true. If false, check last time manga has been updated and take parameter pause for a week into account
*/
async updateChaptersLists({ dispatch, commit, getters, state, rootState }) {
async updateChaptersLists({ dispatch, commit, getters, state, rootState }, {force} = {force: true}) {
if (rootState.options.refreshspin === 1) {
// spin the badge
iconHelper.spinIcon();
......@@ -287,20 +287,41 @@ const actions = {
// refresh all mangas chapters lists
let refchaps = [];
for (let mg of state.all) {
// we catch the reject from the promise to prevent the Promise.all to fail due to a rejected promise. Thanks to that, Promise.all will wait that each manga is refreshed, even if it does not work
let mgupdate = Promise.resolve(
dispatch("refreshLastChapters", {url: mg.url})
.then(() => {
//save updated manga do not wait
dispatch('updateManga', mg);
//update badges and icon state
amrUpdater.refreshBadgeAndIcon();
})
.catch(e => e));
if (rootState.options.savebandwidth === 1) {
await mgupdate;
} else {
refchaps.push(mgupdate);
let doupdate = true;
// check if we are in a pause case (if pause for a week option is checked, we check updates only during 2 days (one before and one after) around each 7 days after last chapter found)
if (!force && rootState.options.stopupdateforaweek === 1 && mg.upts) {
let day = 1000 * 60 * 60 * 24
let week = day * 7
doupdate = false
// number of weeks since last update
let nbweeks = Math.floor((Date.now() - mg.upts) / week) + 1;
// check if we are in the gap between minus one day to plus one day compared to nbweeks weeks after last update
if (mg.upts + week * nbweeks - day <= Date.now() && Date.now() <= mg.upts + week * nbweeks + day) {
doupdate = true;
}
if (doupdate) {
utils.debug("Manga " + mg.key + " has been updated less than " + nbweeks + " ago. We are in the minus one day to plus one day gap for this week number. We update the chapters list.")
} else {
utils.debug("Manga " + mg.key + " has been updated less than " + nbweeks + " week ago. We are NOT in the minus one day to plus one day gap for this week number. We do not update the chapters list.")
}
}
// we update if it has been forced by the user (through option or timers page) or if we need to update
if (force || doupdate) {
// we catch the reject from the promise to prevent the Promise.all to fail due to a rejected promise. Thanks to that, Promise.all will wait that each manga is refreshed, even if it does not work
let mgupdate = Promise.resolve(
dispatch("refreshLastChapters", {url: mg.url})
.then(() => {
//save updated manga do not wait
dispatch('updateManga', mg);
//update badges and icon state
amrUpdater.refreshBadgeAndIcon();
})
.catch(e => e));
if (rootState.options.savebandwidth === 1) {
await mgupdate;
} else {
refchaps.push(mgupdate);
}
}
}
if (rootState.options.savebandwidth !== 1) {
......
......@@ -46,8 +46,9 @@ const default_options = {
groupmgs: 1, // group manga with similar name (one piece and One Piece)
/** Updates options */
updatechap: 3600000, // update chapters frequency
updatechap: 21600000, // update chapters frequency (6 hours default)
updatemg: 86400000, // update mirrors frequency
stopupdateforaweek: 1, // stop updates for a week after last chapter was found
checkmgstart: 0, // update chapters lists on startup
refreshspin: 1, // spin the icon while loading chapters
savebandwidth: 0, // save bandwidth while loading chapters
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment