From e4ace132a75200da941ddcbfcdac686a82dc60bf Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Tue, 29 Jan 2019 12:30:01 -0600 Subject: [PATCH] Handle URL open exceptions --- src/lib/ApplicationState.js | 18 +++++++++++++++++- .../Settings/Sections/CompanySection.js | 12 ++++++------ src/screens/SideMenu/MainSideMenu.js | 2 +- src/screens/SideMenu/NoteSideMenu.js | 2 +- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/lib/ApplicationState.js b/src/lib/ApplicationState.js index 76f664f8..808a608e 100644 --- a/src/lib/ApplicationState.js +++ b/src/lib/ApplicationState.js @@ -1,4 +1,4 @@ -import {AppState, Platform, NativeModules} from 'react-native' +import {AppState, Platform, NativeModules, Linking, Alert} from 'react-native' const { PlatformConstants } = NativeModules; import KeysManager from "@Lib/keysManager" import OptionsState from "@Lib/OptionsState" @@ -299,4 +299,20 @@ export default class ApplicationState { onAuthenticate: this.unlockApplication.bind(this) } } + + static openURL(url) { + let showAlert = () => { + Alert.alert("Unable to Open", `Unable to open URL ${url}.`); + } + + Linking.canOpenURL(url) + .then((supported) => { + if (!supported) { + showAlert(); + } else { + return Linking.openURL(url); + } + }) + .catch((err) => showAlert()); + } } diff --git a/src/screens/Settings/Sections/CompanySection.js b/src/screens/Settings/Sections/CompanySection.js index a26b0758..86bd9939 100644 --- a/src/screens/Settings/Sections/CompanySection.js +++ b/src/screens/Settings/Sections/CompanySection.js @@ -14,18 +14,18 @@ export default class CompanySection extends Component { onAction = (action) => { if(action == "feedback") { var platformString = Platform.OS == "android" ? "Android" : "iOS"; - Linking.openURL(`mailto:hello@standardnotes.org?subject=${platformString} app feedback (v${ApplicationState.version})`); + ApplicationState.openURL(`mailto:hello@standardnotes.org?subject=${platformString} app feedback (v${ApplicationState.version})`); } else if(action == "learn_more") { - Linking.openURL("https://standardnotes.org"); + ApplicationState.openURL("https://standardnotes.org"); } else if(action == "privacy") { - Linking.openURL("https://standardnotes.org/privacy"); + ApplicationState.openURL("https://standardnotes.org/privacy"); } else if(action == "help") { - Linking.openURL("https://standardnotes.org/help"); + ApplicationState.openURL("https://standardnotes.org/help"); } else if(action == "rate") { if(ApplicationState.isIOS) { - Linking.openURL("https://itunes.apple.com/us/app/standard-notes/id1285392450?ls=1&mt=8"); + ApplicationState.openURL("https://itunes.apple.com/us/app/standard-notes/id1285392450?ls=1&mt=8"); } else { - Linking.openURL("market://details?id=com.standardnotes"); + ApplicationState.openURL("market://details?id=com.standardnotes"); } } else if(action == "friend") { let title = "Standard Notes"; diff --git a/src/screens/SideMenu/MainSideMenu.js b/src/screens/SideMenu/MainSideMenu.js index fdafb5c2..76aeee45 100644 --- a/src/screens/SideMenu/MainSideMenu.js +++ b/src/screens/SideMenu/MainSideMenu.js @@ -124,7 +124,7 @@ export default class MainSideMenu extends AbstractSideMenu { side: "right", size: 17 }, - onSelect: () => { Linking.openURL("https://standardnotes.org/extensions")}, + onSelect: () => { ApplicationState.openURL("https://standardnotes.org/extensions")}, })); } diff --git a/src/screens/SideMenu/NoteSideMenu.js b/src/screens/SideMenu/NoteSideMenu.js index aeed4db2..ce0bd973 100644 --- a/src/screens/SideMenu/NoteSideMenu.js +++ b/src/screens/SideMenu/NoteSideMenu.js @@ -259,7 +259,7 @@ export default class NoteSideMenu extends AbstractSideMenu { side: "right", size: 17 }, - onSelect: () => { Linking.openURL("https://standardnotes.org/extensions")}, + onSelect: () => { ApplicationState.openURL("https://standardnotes.org/extensions")}, })); }