Skip to content

Commit

Permalink
Update openBrowser.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
yandeu committed Dec 3, 2024
1 parent a595c30 commit 07128ef
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/openBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,33 @@ export class OpenBrowser {
res = await this.open(target, browser[index])
}

const is_undefined_str = browser => typeof browser === 'string' && browser === 'undefined'

if (!res) {
if (typeof browser === 'string') {
if (browser === 'default') {
message.log(colors(`Could not open the default browser. Will abort!`, 'red'))
return
} else {
message.log(colors(`Could not open browser "${browser}". Trying the default browser next.`, 'yellow'))
if (!is_undefined_str(browser)) {
message.log(colors(`Could not open browser "${browser}". Trying the default browser next.`, 'yellow'))
}
await this.launchDefaultBrowser(target)
}
} else if (Array.isArray(browser)) {
if (typeof browser[index + 1] === 'undefined') {
message.log(colors(`Could not open browser "${browser[index]}". Trying the default browser next.`, 'yellow'))
if (!is_undefined_str(browser[index])) {
message.log(
colors(`Could not open browser "${browser[index]}". Trying the default browser next.`, 'yellow')
)
}
await this.launchDefaultBrowser(target)
} else {
message.log(
colors(`Could not open browser "${browser[index]}". Trying "${browser[index + 1]}" next.`, 'yellow')
)
if (!is_undefined_str(browser[index])) {
message.log(
colors(`Could not open browser "${browser[index]}". Trying "${browser[index + 1]}" next.`, 'yellow')
)
}
await this.launchBrowser(target, browser, index)
}
}
Expand Down

0 comments on commit 07128ef

Please sign in to comment.