Handle URL open exceptions

This commit is contained in:
Mo Bitar
2019-01-29 12:30:01 -06:00
parent b4bc55393d
commit e4ace132a7
4 changed files with 25 additions and 9 deletions

View File

@@ -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());
}
}

View File

@@ -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";

View File

@@ -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")},
}));
}

View File

@@ -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")},
}));
}