diff --git a/package.json b/package.json index 4ab595a5..690980ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "movie-web", - "version": "3.0.1", + "version": "3.0.2", "private": true, "homepage": "https://movie.squeezebox.dev", "dependencies": { @@ -85,4 +85,4 @@ "vite-plugin-checker": "^0.5.6", "vite-plugin-package-version": "^1.0.2" } -} +} \ No newline at end of file diff --git a/src/setup/constants.ts b/src/setup/constants.ts index e5f499eb..ff2dffd7 100644 --- a/src/setup/constants.ts +++ b/src/setup/constants.ts @@ -1,3 +1,3 @@ export const DISCORD_LINK = "https://discord.gg/Jhqt4Xzpfb"; export const GITHUB_LINK = "https://github.com/movie-web/movie-web"; -export const APP_VERSION = "3.0.1"; +export const APP_VERSION = "3.0.2"; diff --git a/src/views/other/v2Migration.tsx b/src/views/other/v2Migration.tsx index 85f3685c..0f1e0424 100644 --- a/src/views/other/v2Migration.tsx +++ b/src/views/other/v2Migration.tsx @@ -11,6 +11,52 @@ function fromBinary(str: string): Uint8Array { return result; } +export function importV2Data({ data, time }: { data: any; time: Date }) { + const savedTime = localStorage.getItem("mw-migration-date"); + if (savedTime) { + if (new Date(savedTime) >= time) { + // has already migrated this or something newer, skip + return false; + } + } + + // restore migration data + if (data.bookmarks) + localStorage.setItem("mw-bookmarks", JSON.stringify(data.bookmarks)); + if (data.videoProgress) + localStorage.setItem("video-progress", JSON.stringify(data.videoProgress)); + + localStorage.setItem("mw-migration-date", time.toISOString()); + + return true; +} + +export function EmbedMigration() { + let hasReceivedMigrationData = false; + + const onMessage = (e: any) => { + const data = e.data; + if (data && data.isMigrationData && !hasReceivedMigrationData) { + hasReceivedMigrationData = true; + const didImport = importV2Data({ + data: data.data, + time: data.date, + }); + if (didImport) window.location.reload(); + } + }; + + useEffect(() => { + window.addEventListener("message", onMessage); + + return () => { + window.removeEventListener("message", onMessage); + }; + }); + + return