/* This file is part of the Notesnook project (https://notesnook.com/) * * Copyright (C) 2022 Streetwriters (Private) Limited * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import React, { useEffect, useState } from "react"; import { Linking, View } from "react-native"; import { checkVersion } from "react-native-check-version"; import Config from "react-native-config"; import deviceInfoModule from "react-native-device-info"; import { ScrollView } from "react-native-gesture-handler"; import { useThemeStore } from "../../../stores/use-theme-store"; import { STORE_LINK } from "../../../utils/constants"; import { SIZE } from "../../../utils/size"; import { Button } from "../../ui/button"; import Seperator from "../../ui/seperator"; import { SvgView } from "../../ui/svg"; import { ProgressBarComponent } from "../../ui/svg/lazy"; import Heading from "../../ui/typography/heading"; import Paragraph from "../../ui/typography/paragraph"; const UPDATE_SVG = (color) => ``; export const Update = ({ version: appVersion, fwdRef }) => { const colors = useThemeStore((state) => state.colors); const [version, setVersion] = useState(appVersion); let notes = version?.notes ? version.notes.replace("Thank you for using Notesnook!", "").split("- ") : ["Bug fixes and performance improvements"]; notes = notes?.map((n) => n.replace(/\n/g, "")); const isGithubRelease = Config.GITHUB_RELEASE === "true"; const getSupportedAbi = () => { let abi = deviceInfoModule.supportedAbisSync(); let armv8a = abi.find((a) => a === "arm64-v8a"); let armv7 = abi.find((a) => a === "armeabi-v7a"); return armv8a || armv7 || abi[0]; }; const GITHUB_URL = !version || !version.needsUpdate ? null : `https://github.com/streetwriters/notesnook/releases/download/${ version.version }-android/notesnook-${getSupportedAbi()}.apk`; const GITHUB_PAGE_URL = !version || !version.needsUpdate ? null : `https://github.com/streetwriters/notesnook/releases/tag/${version.version}-android`; useEffect(() => { if (!version) { (async () => { try { console.log("checking for new version"); let v = await checkVersion(); setVersion(v); } catch (e) { setVersion({ needsUpdate: false }); } })(); } }, []); return ( {!version || !version?.needsUpdate ? ( <> {!version ? ( <> Checking for new version ) : ( No new updates are available )} ) : ( <> Update available v{version.version} has been released{" "} {isGithubRelease ? "on Github" : ""} { fwdRef?.current?.handleChildScrollEnd(); }} style={{ width: "100%" }} > Release notes: {notes.map((item) => ( • {item} ))}