diff --git a/apps/mobile/app/components/launcher/index.js b/apps/mobile/app/components/launcher/index.js index 81aa2b548..3d30d04ee 100644 --- a/apps/mobile/app/components/launcher/index.js +++ b/apps/mobile/app/components/launcher/index.js @@ -55,6 +55,8 @@ import { SvgView } from "../ui/svg"; 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() { @@ -166,8 +168,11 @@ const Launcher = React.memo( const checkAppUpdateAvailable = async () => { 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) => }); diff --git a/apps/mobile/app/components/sheets/update/index.js b/apps/mobile/app/components/sheets/update/index.js index 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 }) => { }} > Release notes: + + {version.body ? ( + + {version.body} + + ) : null} {notes.map((item) => ( { }, []); const onSyncComplete = useCallback(async () => { - console.log('Sync complete'); initAfterSync(); setLastSynced(await db.lastSynced()); eSendEvent(eCloseProgressDialog, "sync_progress"); diff --git a/apps/mobile/app/screens/settings/subscription.js b/apps/mobile/app/screens/settings/subscription.js index 3243ff974..30ecd25ee 100644 --- a/apps/mobile/app/screens/settings/subscription.js +++ b/apps/mobile/app/screens/settings/subscription.js @@ -34,7 +34,7 @@ import { } from "../../utils/constants"; import { eOpenPremiumDialog } from "../../utils/events"; import { SIZE } from "../../utils/size"; -import { Config } from "react-native-config"; +import Config from "react-native-config"; export const Subscription = () => { const user = useUserStore((state) => state.user); const monthlyPlan = usePricing("monthly"); diff --git a/apps/mobile/app/services/event-manager.ts b/apps/mobile/app/services/event-manager.ts index 63ae30d7c..6090aaa57 100644 --- a/apps/mobile/app/services/event-manager.ts +++ b/apps/mobile/app/services/event-manager.ts @@ -21,7 +21,7 @@ import Clipboard from "@react-native-clipboard/clipboard"; import EventManager from "@notesnook/core/utils/event-manager"; import { RefObject } from "react"; import ActionSheet from "react-native-actions-sheet"; -import { Config } from "react-native-config"; +import Config from "react-native-config"; import { eHideToast, eOnNoteEdited, diff --git a/apps/mobile/app/services/premium.js b/apps/mobile/app/services/premium.js index bdedcb685..b0ed74bee 100644 --- a/apps/mobile/app/services/premium.js +++ b/apps/mobile/app/services/premium.js @@ -20,6 +20,7 @@ along with this program. If not, see . import { CHECK_IDS } from "@notesnook/core/common"; import React from "react"; import { Platform } from "react-native"; +import Config from "react-native-config"; import * as RNIap from "react-native-iap"; import { db } from "../common/database"; import { MMKV } from "../common/database/mmkv"; @@ -35,10 +36,8 @@ import { eShowGetPremium } from "../utils/events"; import { eSendEvent, presentSheet, ToastEvent } from "./event-manager"; -import Config from "react-native-config"; import SettingsService from "./settings"; -import { sleep } from "../utils/time"; let premiumStatus = 0; let products = []; let user = null; @@ -61,16 +60,17 @@ async function setPremiumStatus() { } } catch (e) { premiumStatus = 0; - } finally { - if (get()) { - await subscriptions.clear(); - } - try { - await RNIap.initConnection(); - products = await RNIap.getSubscriptions(itemSkus); - } catch (e) { - console.log("subscriptions: ", e); - } + } + if (Config.GITHUB_RELEASE) return; + + if (get()) { + await subscriptions.clear(); + } + try { + await RNIap.initConnection(); + products = await RNIap.getSubscriptions(itemSkus); + } catch (e) { + console.log("subscriptions: ", e); } } diff --git a/apps/mobile/app/utils/github-version.ts b/apps/mobile/app/utils/github-version.ts new file mode 100644 index 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 . +*/ + +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() + }; +};