sindresorhus/opn

Add app constants for popular apps #116

sindresorhus posted onGitHub

App binaries have different names on different platforms. This complicates opening a certain app in a cross-platform manner. We could add some constants for popular apps:

open('https://sindresorhus.com', {app: open.apps.chrome});

https://github.com/sindresorhus/opn/blob/5c525b5f4f2472e35ace19d6df746bb355b8060a/test.js#L5-L17

Feedback welcome on how it should look like.


@issuehunt has funded $40.00 to this issue.


posted by IssueHuntBot about 6 years ago

I propose to treat app/app[0] as string | () => (string | Iterable<string>) (typescript). Iterables could be just arrays, but it sounds like weird limitation. Then for example chrome app would be defined as

() => {
  if(isWsl) return ['Chrome'];
  switch(process.platform){
    case 'darwin': return 'google chrome canary';
    case 'win32': return 'Chrome';
    case 'linux': return ['google-chrome', 'google-chrome-stable', 'google-chrome-beta', 'google-chrome-dev'];
    default: throw new Error('platform ${process.platform} not supported');
  }
}

Note linux case, that's why iterable. (At least Arch linux doesn't have google-chrome unless simlinked manually. Guessing from value for darwin it might be the case for it too.)

(We can't provide Iterable without function, as in that case we won't be able to decide if app is app or [app, ...args].)

posted by stroncium about 6 years ago

@stroncium I do like your suggestion on it being just a function. I think the function should receive the target argument so it's possible to do custom behavior for different types of input.

Your proposal doesn't account for situations when the apps for different platforms require different arguments. How about we move from using an array to an object when app arguments are required? So instead of ['google-chrome', '--incognito'] it would be {name: 'google-chrome', arguments: '--incognito'}.

posted by sindresorhus about 6 years ago

@sindresorhus Well that was my first idea, but I was thinking about making it full backward compatible here. Anyhow...

app becomes string | string[] | (string[] => Iterable<string[]>) args is string[]

  1. for app string we go with exec([app, ...args])
  2. for app Array we go with exec([...app, ...args])
  3. for app function we go with for(list of app(args)) exec(list) until success

Do we want to handle 2 this way for backward compatibility or just make it an error or check for args and make an error if they do exist? In latter case we can reduce app type to string | (string[] => Iterable<string[]>)

posted by stroncium about 6 years ago

Backwards-compatibility seems complicated. We can do a major version.

I want:

So instead of ['google-chrome', '--incognito'] it would be {name: 'google-chrome', arguments: '--incognito'}.

posted by sindresorhus almost 6 years ago

Backwards-compatibility seems complicated. We can do a major version.

I want:

So instead of ['google-chrome', '--incognito'] it would be {name: 'google-chrome', arguments: '--incognito'}.

Do we still want app to accept a single string?

posted by Richienb about 4 years ago

Do we still want app to accept a single string?

I guess it doesn't hurt to continue supporting it. We can remove it from the docs though and comment in the code that it should be removed at some point.

posted by sindresorhus about 4 years ago

In the example, Linux has 4 different binaries to call. How will the code detect which one to use?

posted by Richienb about 4 years ago

Those are different Chrome editions. They would have different constants.

posted by sindresorhus about 4 years ago

Those are different Chrome editions. They would have different constants.

The first 2, google-chrome and google-chrome-stable are the same.

posted by Richienb about 4 years ago

I guess we'll have to open the most likely one and if it fails, try the second one.

posted by sindresorhus about 4 years ago

@sindresorhus has rewarded $36.00 to @richienb. See it on IssueHunt

  • :moneybag: Total deposit: $40.00
  • :tada: Repository reward(0%): $0.00
  • :wrench: Service fee(10%): $4.00
posted by issuehunt-app[bot] about 4 years ago
    case 'darwin': return 'google chrome canary';

Is it a typo to use Chrome Canary on macOS, while on other platforms it's just Chrome?

posted by sodatea about 4 years ago
    case 'darwin': return 'google chrome canary';

Is it a typo to use Chrome Canary on macOS, while on other platforms it's just Chrome?

It appears so. I'm on macOS 11.2.2 and google chrome canary doesn't work, but google chrome does. So using { app: apps.chrome } is broken for me on macOS.

posted by ammmze almost 4 years ago

Fund this Issue

$40.00
Rewarded

Rewarded pull request

Recent activities

richienb was rewarded by sindresorhus for sindresorhus/opn# 116
about 4 years ago
richienb submitted an output to  sindresorhus/ opn# 116
about 4 years ago