Skip to content

Commit

Permalink
Migrate existing channel settings (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkelM authored Apr 24, 2023
1 parent c3382e0 commit c7a6a25
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# Changelog

## v1.5.0
## v1.5.1

<!--Releasenotes start-->
- Correctly migrate old channel settings to the new format.
- Small improvement to backend logic for channel settings.
<!--Releasenotes end-->

## v1.5.0

- Added three new options to the popup: You can now choose to only shuffle from...
- ...videos uploaded on or after a certain date.
- ...videos uploaded on or after the day another video was uploaded.
- ...the most recent x% of videos uploaded on the channel.
- Fixed a bug that might sometimes cause user settings to not get saved correctly.
<!--Releasenotes end-->

## v1.4.6

Expand Down
18 changes: 18 additions & 0 deletions extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,26 @@ async function handleExtensionUpdate(manifestData, previousVersion) {
}

async function handleVersionSpecificUpdates(previousVersion) {
// v1.5.0 added renamed some keys in the channelSettings object
if (previousVersion < "1.5.0") {
console.log("Updating channelSettings to v1.5.0 format...");

let configSyncValues = await chrome.storage.sync.get();

// For each object entry in channelSettings that has the "shufflePercentage" item, rename it to "percentageValue" and add a new key "activeOption": "percentageOption"
for (const [channelID, channelSetting] of Object.entries(configSyncValues["channelSettings"])) {
if (channelSetting["shufflePercentage"]) {
channelSetting["percentageValue"] = channelSetting["shufflePercentage"];
channelSetting["activeOption"] = "percentageOption";
delete channelSetting["shufflePercentage"];
}
}
await chrome.storage.sync.set(configSyncValues);
}

// v1.3.0 removed the "youtubeAPIKey" key from local storage, which was replaced by the "youtubeAPIKeys" key
if (previousVersion < "1.3.0") {
consolelog("Updating local storage to v1.3.0 format...");
const localStorageContents = await chrome.storage.local.get();
// Delete the youtubeAPIKey from local storage if it exists
if (localStorageContents["youtubeAPIKey"]) {
Expand Down
2 changes: 1 addition & 1 deletion extension/js/popup/domElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ async function setDomElemenEventListeners(domElements, configSync) {

// We only need to save the value if it's not the default of 100. If we have already saved a different one, we want to remove it
if (this.value != 100) {
await setChannelSetting(configSync.currentChannelId, "percentageValue", this.value);
await setChannelSetting(configSync.currentChannelId, "percentageValue", parseInt(this.value));
} else {
await removeChannelSetting(configSync.currentChannelId, "percentageValue");
}
Expand Down
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "Random YouTube Video",
"description": "Play a random video uploaded on the current YouTube channel.",
"version": "1.5.0",
"version": "1.5.1",
"icons": {
"16": "images/icon-16-red.png",
"32": "images/icon-32-red.png",
Expand Down

0 comments on commit c7a6a25

Please sign in to comment.