A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: check github app version on launch
ammarahm-ed79e9ab282768
diff --git a/apps/mobile/app/components/launcher/index.js b/apps/mobile/app/components/launcher/index.jsindex 9db395c8e..3d30d04ee 100644--- a/apps/mobile/app/components/launcher/index.js+++ b/apps/mobile/app/components/launcher/index.js@@ -56,6 +56,7 @@ import Heading from "../ui/typography/heading";import Paragraph from "../ui/typography/paragraph";import { Walkthrough } from "../walkthroughs";import Config from "react-native-config";+import { getGithubVersion } from "../../utils/github-version";const Launcher = React.memo(function Launcher() {@@ -165,10 +166,13 @@ const Launcher = React.memo(}, [introCompleted]);const checkAppUpdateAvailable = async () => {- if (__DEV__ || Config.GITHUB_RELEASE === "true") return;+ if (__DEV__) return;try {- const version = await checkVersion();- if (!version.needsUpdate) return false;+ const version =+ Config.GITHUB_RELEASE !== "true"+ ? await getGithubVersion()+ : await checkVersion();+ if (!version || !version?.needsUpdate) return false;presentSheet({component: (ref) => <Update version={version} fwdRef={ref} />});diff --git a/apps/mobile/app/components/sheets/update/index.js b/apps/mobile/app/components/sheets/update/index.jsindex 05d02cc93..6d626685f 100644--- a/apps/mobile/app/components/sheets/update/index.js+++ b/apps/mobile/app/components/sheets/update/index.js@@ -156,6 +156,21 @@ export const Update = ({ version: appVersion, fwdRef }) => {}}><Heading size={SIZE.md}>Release notes:</Heading>++ {version.body ? (+ <Paragraph+ color={colors.icon}+ style={{+ marginBottom: 5,+ fontFamily: "monospace",+ fontSize: 12,+ lineHeight: 20,+ marginTop: 10+ }}+ >+ {version.body}+ </Paragraph>+ ) : null}{notes.map((item) => (<Paragraphkey={item}diff --git a/apps/mobile/app/utils/github-version.ts b/apps/mobile/app/utils/github-version.tsnew file mode 100644index 000000000..39d36ebdf--- /dev/null+++ b/apps/mobile/app/utils/github-version.ts@@ -0,0 +1,77 @@+/*+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 <http://www.gnu.org/licenses/>.+*/++import { getVersion } from "react-native-device-info";++export interface GithubRelease {+ url: string;+ assets_url: string;+ upload_url: string;+ html_url: string;+ id: number;+ author: unknown;+ node_id: string;+ tag_name: string;+ target_commitish: string;+ name: string;+ draft: boolean;+ prerelease: boolean;+ created_at: Date;+ published_at: Date;+ assets: unknown[];+ tarball_url: string;+ zipball_url: string;+ body: string;+ mentions_count: number;+ reactions: unknown;+ discussion_url: string;+}++export const getGithubVersion = async () => {+ const url = `https://api.github.com/repos/streetwriters/notesnook/releases`;+ let res;+ try {+ res = await fetch(url, {+ headers: {+ "User-Agent":+ "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36",+ "sec-fetch-site": "same-origin"+ }+ });+ } catch (e) {+ console.warn(e);+ }++ if (!res?.ok) return null;+ const data = (await res?.json()) as GithubRelease[];++ const versions = data?.filter((tag) => tag.tag_name.endsWith("android"));+ const latestVersion = versions[0];+ const version = latestVersion.tag_name.replace("-android", "");+ return {+ version: version || null,+ releasedAt: new Date(latestVersion.published_at).toISOString(),+ notes: "",+ body: latestVersion.body,+ url: latestVersion.url,+ lastChecked: new Date().toISOString(),+ needsUpdate: getVersion() !== version,+ current: getVersion()+ };+};