mirror of
https://github.com/XFox111/TabsAsideExtension.git
synced 2026-04-22 07:58:01 +03:00
feat: ability to disable cloud collection storage
This commit is contained in:
@@ -8,5 +8,6 @@ export const collectionStorage =
|
||||
localCollections: storage.defineItem<CollectionItem[]>("local:collections", { fallback: [] }),
|
||||
count: storage.defineItem<number>("local:count", { fallback: 0 }),
|
||||
graphics: storage.defineItem<GraphicsStorage>("local:graphics", { fallback: {} }),
|
||||
disableCloud: storage.defineItem<boolean>("sync:disableCloud", { fallback: false }),
|
||||
maxChunkCount: 12
|
||||
};
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import { CollectionItem } from "@/models/CollectionModels";
|
||||
import getLogger from "@/utils/getLogger";
|
||||
import { collectionStorage } from "./collectionStorage";
|
||||
import getCollectionsFromCloud from "./getCollectionsFromCloud";
|
||||
import getCollectionsFromLocal from "./getCollectionsFromLocal";
|
||||
import saveCollectionsToLocal from "./saveCollectionsToLocal";
|
||||
import getLogger from "@/utils/getLogger";
|
||||
|
||||
const logger = getLogger("getCollections");
|
||||
|
||||
export default async function getCollections(): Promise<[CollectionItem[], CloudStorageIssueType | null]>
|
||||
{
|
||||
if (await collectionStorage.disableCloud.getValue() === true)
|
||||
return [await getCollectionsFromLocal(), null];
|
||||
|
||||
const lastUpdatedLocal: number = await collectionStorage.localLastUpdated.getValue();
|
||||
const lastUpdatedSync: number = await collectionStorage.syncLastUpdated.getValue();
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { CollectionItem, GraphicsStorage } from "@/models/CollectionModels";
|
||||
import getLogger from "@/utils/getLogger";
|
||||
import sendNotification from "@/utils/sendNotification";
|
||||
import { collectionStorage } from "./collectionStorage";
|
||||
import saveCollectionsToCloud from "./saveCollectionsToCloud";
|
||||
import saveCollectionsToLocal from "./saveCollectionsToLocal";
|
||||
import updateGraphics from "./updateGraphics";
|
||||
@@ -16,7 +17,7 @@ export default async function saveCollections(
|
||||
const timestamp: number = Date.now();
|
||||
await saveCollectionsToLocal(collections, timestamp);
|
||||
|
||||
if (updateCloud)
|
||||
if (updateCloud && await collectionStorage.disableCloud.getValue() !== true)
|
||||
try
|
||||
{
|
||||
await saveCollectionsToCloud(collections, timestamp);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { collectionStorage } from "./collectionStorage";
|
||||
import saveCollectionsToCloud from "./saveCollectionsToCloud";
|
||||
|
||||
export default async function setCloudStorage(enable: boolean): Promise<void>
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
await collectionStorage.disableCloud.setValue(false);
|
||||
const collections = await collectionStorage.localCollections.getValue();
|
||||
const lastUpdated = await collectionStorage.localLastUpdated.getValue();
|
||||
await saveCollectionsToCloud(collections, lastUpdated);
|
||||
}
|
||||
else
|
||||
{
|
||||
await collectionStorage.disableCloud.setValue(true);
|
||||
await saveCollectionsToCloud([], 0);
|
||||
browser.runtime.reload();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user