-
-
Notifications
You must be signed in to change notification settings - Fork 19
feat: Gérer un état 'stopped' local en plus de l'état synchronisé #60
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
WORKING: "w", | ||
}; | ||
|
||
async function updateIconStatus() { | ||
async function updateIconStatus(stopped) { | ||
return await browser.browserAction.setIcon({ | ||
path: { | ||
16: `../icons/vaccine-${stopped ? "black" : "color"}.svg`, | ||
|
@@ -57,7 +57,7 @@ | |
} | ||
|
||
async function executeNextJob() { | ||
const { stopped } = await browser.storage.sync.get({ | ||
const { stopped } = await browser.storage.local.get({ | ||
stopped: false, | ||
}); | ||
|
||
|
@@ -93,9 +93,7 @@ | |
} | ||
|
||
browser.storage.onChanged.addListener(async (change, areaName) => { | ||
if (areaName !== "sync") return; | ||
|
||
if (change.locations && change.locations.newValue) { | ||
if (areaName === "sync" && change.locations && change.locations.newValue) { | ||
Object.keys(locations).forEach((url) => { | ||
if (!change.locations.newValue[url]) { | ||
delete locations[url]; | ||
|
@@ -111,7 +109,14 @@ | |
}); | ||
} | ||
|
||
if (change.stopped) return await updateIconStatus(stopped); | ||
if (change.stopped) { | ||
await updateIconStatus(change.stopped.newValue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. la seconde partie du fix de l'icône There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arf, j'ai déjà fixé tout ca dans #48 |
||
if (areaName === "sync") { | ||
// Ça peut arriver de cette instance ou d'une autre instance de Firefox | ||
// -> mettons aussi à jour la valeur locale pour arrêter les checks locaux. | ||
await browser.storage.local.set({ stopped: true }); | ||
} | ||
} | ||
}); | ||
|
||
browser.runtime.onMessage.addListener(async (data) => { | ||
|
@@ -144,6 +149,7 @@ | |
break; | ||
|
||
case "booked": | ||
// Note: on met à jour la valeur locale dans onChanged au-dessus. | ||
await browser.storage.sync.set({ stopped: true }); | ||
|
||
await browser.tabs.create({ | ||
|
@@ -170,9 +176,18 @@ | |
} | ||
}); | ||
|
||
const { locations, stopped } = await browser.storage.sync.get({ | ||
locations: {}, | ||
stopped: false, | ||
// Le booléan "stopped" est à la fois stocké localement et synchronisé. En | ||
// effet, lorsqu'on arrive à booker un rdv dans un Firefox on veut arrêter les | ||
// checks dans toutes les instances. Mais un simple clic sur le bouton ne doit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On est sûr de ça ? À mon avis il vaut mieux arrêter partout. Cas d'usage :
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ben je pensais que tu étais d'accord d'après #56 (comment), c'est le but de ce PR à la base :-) En fait je comprends pas bien l'intérêt de faire tourner l'extension sur plusieurs ordinateurs à la fois. Le problème est qu'elle est installée automatiquement lorsqu'on se connecte avec son FxAccounts sur une autre installation... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Je pensais que tu voulais tout mettre en local storage (ce qui me va toujours). Je n'aime pas trop le mélange des deux, ça rend ça moins clair. Si rien n'est synchro, ça me semble plus logique que tu doives l'arrêter partout. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mais du coup, ce cas d'usage:
Et tu veux mettre les Désolé, j'essaie de bien comprendre ce qu'on veut faire :-) |
||
// déclencher d'arrêt que localement. | ||
const { locations, stopped: stoppedFromSync } = | ||
await browser.storage.sync.get({ | ||
locations: {}, | ||
stopped: false, | ||
}); | ||
|
||
const { stopped } = await browser.storage.local.get({ | ||
stopped: stoppedFromSync, | ||
}); | ||
|
||
await updateIconStatus(stopped); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,12 +62,13 @@ | |
document.getElementById(stopped ? "stop" : "start").style = "display: none"; | ||
} | ||
|
||
let { locations, stopped, autoBook } = await browser.storage.sync.get({ | ||
let { locations, autoBook } = await browser.storage.sync.get({ | ||
locations: {}, | ||
autoBook: false, | ||
stopped: false, | ||
}); | ||
|
||
let { stopped } = await browser.storage.local.get({ stopped: false }); | ||
|
||
let { localLocations } = await browser.storage.local.get({ locations: {} }); | ||
|
||
browser.storage.onChanged.addListener(async (change, areaName) => { | ||
|
@@ -79,6 +80,8 @@ | |
localLocations = change.locations.newValue; | ||
displayLocations(locations, localLocations); | ||
} | ||
|
||
if (change.stopped) displayStopStart(change.stopped.newValue || false); | ||
} | ||
|
||
if (areaName === "sync") { | ||
|
@@ -87,8 +90,6 @@ | |
displayLocations(locations, localLocations); | ||
} | ||
|
||
if (change.stopped) displayStopStart(change.stopped.newValue || false); | ||
|
||
if (change.autoBook) | ||
document.getElementById( | ||
change.autoBook.newValue || false | ||
|
@@ -99,13 +100,11 @@ | |
}); | ||
|
||
document.getElementById("stop").onclick = async () => { | ||
await browser.storage.sync.set({ stopped: true }); | ||
displayStopStart(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. La simplification minime dont je parlais: en effet, |
||
await browser.storage.local.set({ stopped: true }); | ||
}; | ||
|
||
document.getElementById("start").onclick = async () => { | ||
await browser.storage.sync.set({ stopped: false }); | ||
displayStopStart(false); | ||
await browser.storage.local.set({ stopped: false }); | ||
}; | ||
|
||
document.getElementById("reset").onclick = async () => { | ||
|
@@ -117,6 +116,7 @@ | |
return; | ||
|
||
await browser.storage.sync.clear(); | ||
await browser.storage.local.clear(); | ||
}; | ||
|
||
document.getElementById("disableAutoBook").onclick = async () => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
la première partie du fix de l'icône