mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-08-14 23:57:27 +00:00
Add better error messages for localStorage disabled.
This commit is contained in:
parent
d1c403765c
commit
6b9151e47f
6 changed files with 28 additions and 9 deletions
|
@ -195,7 +195,7 @@ export default {
|
|||
},
|
||||
});
|
||||
} else {
|
||||
this.handleLocalSubscriptions(this.channel.id);
|
||||
if (!this.handleLocalSubscriptions(this.channel.id)) return;
|
||||
}
|
||||
this.subscribed = !this.subscribed;
|
||||
},
|
||||
|
|
|
@ -158,7 +158,11 @@ export default {
|
|||
: [...new Set((this.getLocalSubscriptions() ?? []).concat(newChannels))];
|
||||
// Sort for better cache hits
|
||||
subscriptions.sort();
|
||||
try {
|
||||
localStorage.setItem("localSubscriptions", JSON.stringify(subscriptions));
|
||||
} catch (e) {
|
||||
alert(this.$t("info.local_storage"));
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -137,8 +137,8 @@ export default {
|
|||
shouldShowTrending(_this) {
|
||||
return _this.getPreferenceString("homepage", "trending") != "trending";
|
||||
},
|
||||
showSearchHistory() {
|
||||
return localStorage.getItem("searchHistory") && localStorage.getItem("search_history");
|
||||
showSearchHistory(_this) {
|
||||
return _this.getPreferenceBoolean("searchHistory", false) && localStorage.getItem("search_history");
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
|
|
@ -485,7 +485,7 @@ export default {
|
|||
},
|
||||
});
|
||||
} else {
|
||||
this.handleLocalSubscriptions(this.channelId);
|
||||
if (!this.handleLocalSubscriptions(this.channelId)) return;
|
||||
}
|
||||
this.subscribed = !this.subscribed;
|
||||
},
|
||||
|
|
|
@ -167,6 +167,7 @@
|
|||
"preferences_note": "Note: preferences are saved in the local storage of your browser. Deleting your browser data will reset them.",
|
||||
"page_not_found": "Page not found",
|
||||
"copied": "Copied!",
|
||||
"cannot_copy": "Can't copy!"
|
||||
"cannot_copy": "Can't copy!",
|
||||
"local_storage": "This action requires localStorage, are cookies enabled?"
|
||||
}
|
||||
}
|
||||
|
|
16
src/main.js
16
src/main.js
|
@ -119,7 +119,11 @@ const mixin = {
|
|||
return DOMPurify.sanitize(original);
|
||||
},
|
||||
setPreference(key, value) {
|
||||
if (localStorage) localStorage.setItem(key, value);
|
||||
try {
|
||||
localStorage.setItem(key, value);
|
||||
} catch {
|
||||
alert(this.$t("info.local_storage"));
|
||||
}
|
||||
},
|
||||
getPreferenceBoolean(key, defaultVal) {
|
||||
var value;
|
||||
|
@ -204,7 +208,11 @@ const mixin = {
|
|||
}
|
||||
},
|
||||
getLocalSubscriptions() {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem("localSubscriptions"));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
isSubscribedLocally(channelId) {
|
||||
const localSubscriptions = this.getLocalSubscriptions();
|
||||
|
@ -218,7 +226,13 @@ const mixin = {
|
|||
else localSubscriptions.push(channelId);
|
||||
// Sort for better cache hits
|
||||
localSubscriptions.sort();
|
||||
try {
|
||||
localStorage.setItem("localSubscriptions", JSON.stringify(localSubscriptions));
|
||||
return true;
|
||||
} catch {
|
||||
alert(this.$t("info.local_storage"));
|
||||
}
|
||||
return false;
|
||||
},
|
||||
getUnauthenticatedChannels() {
|
||||
const localSubscriptions = this.getLocalSubscriptions() ?? [];
|
||||
|
|
Loading…
Reference in a new issue