diff --git a/package-lock.json b/package-lock.json index 275f9aa31..8959f8609 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@babel/runtime": "7.16.0", "@sentry/browser": "6.13.3", "@stremio/stremio-colors": "5.0.1", - "@stremio/stremio-core-web": "0.44.10", + "@stremio/stremio-core-web": "0.44.11", "@stremio/stremio-icons": "4.0.0", "@stremio/stremio-video": "0.0.24", "a-color-picker": "1.2.1", @@ -2699,9 +2699,9 @@ "integrity": "sha512-Dt3PYmy1DZ473QNs99KYXVWQPHtpIl37VUY0+gCEvvuCqE1fRrZIJtZ9KbysUKonvO7WwdQDztgcW0iGoc1dEA==" }, "node_modules/@stremio/stremio-core-web": { - "version": "0.44.10", - "resolved": "https://registry.npmjs.org/@stremio/stremio-core-web/-/stremio-core-web-0.44.10.tgz", - "integrity": "sha512-+AUJ3d5u5SH64lcuQIAtXPfeIaWzSNfdDL92HECXP29qat2TtCyM+ENLhTuMZzrbInD22SQrRhfIS3T8nFVQYg==", + "version": "0.44.11", + "resolved": "https://registry.npmjs.org/@stremio/stremio-core-web/-/stremio-core-web-0.44.11.tgz", + "integrity": "sha512-KkNEZenQ+94ylYEMl/AqvL1Md4p+xwqg/02FKuVxjFBEoKyXEDXCgOKOI7wbbXdZJe8tnvk+XFq39jzAiTinSw==", "dependencies": { "@babel/runtime": "7.16.0" } @@ -16716,9 +16716,9 @@ "integrity": "sha512-Dt3PYmy1DZ473QNs99KYXVWQPHtpIl37VUY0+gCEvvuCqE1fRrZIJtZ9KbysUKonvO7WwdQDztgcW0iGoc1dEA==" }, "@stremio/stremio-core-web": { - "version": "0.44.10", - "resolved": "https://registry.npmjs.org/@stremio/stremio-core-web/-/stremio-core-web-0.44.10.tgz", - "integrity": "sha512-+AUJ3d5u5SH64lcuQIAtXPfeIaWzSNfdDL92HECXP29qat2TtCyM+ENLhTuMZzrbInD22SQrRhfIS3T8nFVQYg==", + "version": "0.44.11", + "resolved": "https://registry.npmjs.org/@stremio/stremio-core-web/-/stremio-core-web-0.44.11.tgz", + "integrity": "sha512-KkNEZenQ+94ylYEMl/AqvL1Md4p+xwqg/02FKuVxjFBEoKyXEDXCgOKOI7wbbXdZJe8tnvk+XFq39jzAiTinSw==", "requires": { "@babel/runtime": "7.16.0" } diff --git a/package.json b/package.json index 6aff4873d..f570411c1 100755 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "@babel/runtime": "7.16.0", "@sentry/browser": "6.13.3", "@stremio/stremio-colors": "5.0.1", - "@stremio/stremio-core-web": "0.44.10", + "@stremio/stremio-core-web": "0.44.11", "@stremio/stremio-icons": "4.0.0", "@stremio/stremio-video": "0.0.24", "a-color-picker": "1.2.1", diff --git a/src/App/App.js b/src/App/App.js index c0a79b727..1735cee0d 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -90,7 +90,7 @@ const App = () => { }; }, []); React.useEffect(() => { - if (services.core.active) { + const onWindowFocus = () => { services.core.transport.dispatch({ action: 'Ctx', args: { @@ -109,7 +109,12 @@ const App = () => { action: 'SyncLibraryWithAPI' } }); + }; + if (services.core.active) { + onWindowFocus(); + window.addEventListener('focus', onWindowFocus); } + return () => window.removeEventListener('focus', onWindowFocus); }, [initialized]); return ( diff --git a/src/App/ServicesToaster.js b/src/App/ServicesToaster.js index 43b076c9a..d3fdd3461 100644 --- a/src/App/ServicesToaster.js +++ b/src/App/ServicesToaster.js @@ -19,6 +19,10 @@ const ServicesToaster = () => { break; } + if (args.error.type === 'Other' && args.error.code === 3 && args.source.event === 'AddonInstalled' && args.source.args.transport_url.startsWith('https://www.strem.io/trakt/addon')) { + break; + } + toast.show({ type: 'error', title: args.source.event, diff --git a/src/routes/Settings/Settings.js b/src/routes/Settings/Settings.js index 2188f5c3c..4bcee1a00 100644 --- a/src/routes/Settings/Settings.js +++ b/src/routes/Settings/Settings.js @@ -50,6 +50,11 @@ const Settings = () => { streamingServerUrlInput.onChange(configureServerUrlInputRef.current.value); closeConfigureServerUrlModal(); }, [streamingServerUrlInput]); + const [traktAuthStarted, setTraktAuthStarted] = React.useState(false); + const isTraktAuthenticated = React.useMemo(() => { + return profile.auth !== null && profile.auth.user !== null && profile.auth.user.trakt !== null && + (Date.now() / 1000) < (profile.auth.user.trakt.created_at + profile.auth.user.trakt.expires_in); + }, [profile.auth]); const configureServerUrlModalButtons = React.useMemo(() => { return [ { @@ -75,9 +80,19 @@ const Settings = () => { } }); }, []); - const authenticateTraktOnClick = React.useCallback(() => { - // TODO - }, []); + const toggleTraktOnClick = React.useCallback(() => { + if (!isTraktAuthenticated && profile.auth !== null && profile.auth.user !== null && typeof profile.auth.user._id === 'string') { + window.open(`https://www.strem.io/trakt/auth/${profile.auth.user._id}`); + setTraktAuthStarted(true); + } else { + core.transport.dispatch({ + action: 'Ctx', + args: { + action: 'LogoutTrakt' + } + }); + } + }, [isTraktAuthenticated, profile.auth]); const subscribeCalendarOnClick = React.useCallback(() => { const url = `webcal://www.strem.io/calendar/${profile.auth.user._id}.ics`; window.open(url); @@ -135,6 +150,17 @@ const Settings = () => { const sectionsContainerOnScorll = React.useCallback(throttle(() => { updateSelectedSectionId(); }, 50), []); + React.useEffect(() => { + if (isTraktAuthenticated && traktAuthStarted) { + core.transport.dispatch({ + action: 'Ctx', + args: { + action: 'InstallTraktAddon' + } + }); + setTraktAuthStarted(false); + } + }, [isTraktAuthenticated, traktAuthStarted]); React.useEffect(() => { if (dataExport.exportUrl !== null && typeof dataExport.exportUrl === 'string') { window.open(dataExport.exportUrl); @@ -228,9 +254,11 @@ const Settings = () => {
Trakt Scrobbling
-