Fix browser launch on android

195034637fb11b9d198f6b09fb7ff1a3e5c88b88

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +11 -2Showing whitespace changes
default/config.yaml+1 -0
@@ -21,6 +21,7 @@ browserLaunch:
21 # Open the browser automatically on server startup.21 # Open the browser automatically on server startup.
22 enabled: true22 enabled: true
23 # Browser to use for opening the URL.23 # Browser to use for opening the URL.
24 # NOT SUPPORTED ON ANDROID DEVICES.
24 # - Use "default" to use the system default browser25 # - Use "default" to use the system default browser
25 # - Use "firefox", "chrome", "edge"26 # - Use "firefox", "chrome", "edge"
26 browser: 'default'27 browser: 'default'
src/server-main.js+10 -2
@@ -329,18 +329,26 @@ async function postSetupTasks(result) {
329329
330 if (cliArgs.browserLaunchEnabled) {330 if (cliArgs.browserLaunchEnabled) {
331 try {331 try {
332 const validBrowsers = {332 function getBrowsers() {
333 const isAndroid = process.platform === 'android';
334 if (isAndroid) {
335 return {};
336 }
337 return {
333 'firefox': apps.firefox,338 'firefox': apps.firefox,
334 'chrome': apps.chrome,339 'chrome': apps.chrome,
335 'edge': apps.edge,340 'edge': apps.edge,
336 };341 };
342 }
343
344 const validBrowsers = getBrowsers();
337 const appName = validBrowsers[browserLaunchApp.trim().toLowerCase()];345 const appName = validBrowsers[browserLaunchApp.trim().toLowerCase()];
338 const openOptions = appName ? { app: { name: appName } } : {};346 const openOptions = appName ? { app: { name: appName } } : {};
339347
340 console.log(`Launching in a browser: ${browserLaunchApp}...`);348 console.log(`Launching in a browser: ${browserLaunchApp}...`);
341 await open(browserLaunchUrl.toString(), openOptions);349 await open(browserLaunchUrl.toString(), openOptions);
342 } catch (error) {350 } catch (error) {
343 console.error('Failed to launch the browser. Open the URL manually.');351 console.error('Failed to launch the browser. Open the URL manually.', error);
344 }352 }
345 }353 }
346354