diff --git a/desktop-app/src/main/main.ts b/desktop-app/src/main/main.ts index 494fa57f..e4f8084b 100644 --- a/desktop-app/src/main/main.ts +++ b/desktop-app/src/main/main.ts @@ -263,10 +263,6 @@ const createWindow = async () => { ipcMain.on('stop-watcher', async () => { await stopWatchFiles(); }); - - ipcMain.handle('get-app-version', () => { - return app.getVersion(); - }); }; app.on('open-url', async (event, url) => { diff --git a/desktop-app/src/renderer/components/Previewer/Device/Toolbar.tsx b/desktop-app/src/renderer/components/Previewer/Device/Toolbar.tsx index 1b4a5664..b793a342 100644 --- a/desktop-app/src/renderer/components/Previewer/Device/Toolbar.tsx +++ b/desktop-app/src/renderer/components/Previewer/Device/Toolbar.tsx @@ -1,5 +1,5 @@ import { Icon } from '@iconify/react'; -import { useEffect, useState } from 'react'; +import { useState } from 'react'; import Button from 'renderer/components/Button'; import useSound from 'use-sound'; import { ScreenshotArgs, ScreenshotResult } from 'main/screenshot'; @@ -8,9 +8,6 @@ import WebPage from 'main/screenshot/webpage'; import screenshotSfx from 'renderer/assets/sfx/screenshot.mp3'; import { updateWebViewHeightAndScale } from 'common/webViewUtils'; -import useCheckVersion from 'renderer/components/useCheckVersion/useCheckVersion'; -import { useDispatch } from 'react-redux'; -import { setNotifications } from 'renderer/store/features/renderer'; import { ColorBlindnessTools } from './ColorBlindnessTools'; interface Props { @@ -48,16 +45,6 @@ const Toolbar = ({ useState(false); const [rotated, setRotated] = useState(false); - const dispatch = useDispatch(); - - const { isNewVersionAvailable } = useCheckVersion(); - - useEffect(() => { - if (isNewVersionAvailable) { - dispatch(setNotifications(newVersionText)); - } - }, [dispatch, isNewVersionAvailable]); - const refreshView = () => { if (webview) { webview.reload(); diff --git a/desktop-app/src/renderer/components/useCheckVersion/useCheckVersion.tsx b/desktop-app/src/renderer/components/useCheckVersion/useCheckVersion.tsx deleted file mode 100644 index d864cf5e..00000000 --- a/desktop-app/src/renderer/components/useCheckVersion/useCheckVersion.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import { useState, useEffect } from 'react'; -import { gt } from 'semver'; -import useLocalStorage from '../useLocalStorage/useLocalStorage'; - -const fetchAssets = async () => { - try { - const response = await fetch( - 'https://api.github.com/repos/responsively-org/responsively-app-releases/releases/latest' - ); - const data = await response.json(); - return data.tag_name; - } catch (err) { - // eslint-disable-next-line no-console - console.error('Error getting assets', err); - return ''; - } -}; - -const getAppVersion = async () => { - try { - const version = await window.electron.ipcRenderer.invoke('get-app-version'); - return `v${version}`; - } catch (err) { - // eslint-disable-next-line no-console - console.error('Error getting app version', err); - return ''; - } -}; - -const useCheckVersion = () => { - const [isNewVersionAvailable, setIsNewVersionAvailable] = useState< - null | boolean - >(null); - const [latestVersion, setLatestVersion] = useLocalStorage( - 'latestVersion' - ); - const [currentVersion, setCurrentVersion] = useState(''); - const [lastCheck, setLastCheck] = useLocalStorage( - 'lastCheck' - ); - const biWeeklyCheckInMs = 1209600000; - - useEffect(() => { - const checkVersion = async () => { - const currentVersionResult = await getAppVersion(); - - setCurrentVersion(currentVersionResult); - - const now = Date.now(); - if (!latestVersion || !lastCheck || now - lastCheck > biWeeklyCheckInMs) { - const latestVersionResult = await fetchAssets(); - if (latestVersionResult) { - setLatestVersion(latestVersionResult); - setLastCheck(now); - } - } - const isNewVersion = - currentVersionResult && - latestVersion && - gt(latestVersion, currentVersionResult); - - setIsNewVersionAvailable(Boolean(isNewVersion)); - }; - - if (isNewVersionAvailable === null) { - checkVersion(); - } - }, [ - isNewVersionAvailable, - lastCheck, - latestVersion, - setLastCheck, - setLatestVersion, - ]); - - return { - isNewVersionAvailable, - currentVersion, - latestVersion, - }; -}; - -export default useCheckVersion;