jellyfin-expo/utils/WebBrowser.js

33 lines
1011 B
JavaScript
Raw Permalink Normal View History

/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
2020-07-22 03:37:43 +00:00
import * as WebBrowser from 'expo-web-browser';
import Colors from '../constants/Colors';
export async function openBrowser(url, options) {
2020-07-22 03:37:43 +00:00
const finalOptions = Object.assign({
2020-12-30 19:22:46 +00:00
toolbarColor: Colors.blackish,
controlsColor: Colors.blue
2020-07-22 03:37:43 +00:00
}, options);
2020-07-22 03:37:43 +00:00
try {
await WebBrowser.openBrowserAsync(url, finalOptions);
} catch (err) {
// Workaround issue where swiping browser closed does not dismiss it.
// https://github.com/expo/expo/issues/6918
if (err.message === 'Another WebBrowser is already being presented.') {
try {
await WebBrowser.dismissBrowser();
return WebBrowser.openBrowserAsync(url, finalOptions);
} catch (retryErr) {
console.warn('Could not dismiss and reopen browser', retryErr);
}
} else {
console.warn('Could not open browser', err);
}
}
}