GithubHelp home page GithubHelp logo

Comments (12)

CanadaHonk avatar CanadaHonk commented on September 14, 2024

Would be cool, currently is just in order of most preferred/usable by Gluon. Would likely use reg.exe directly to avoid external dependencies.

from gluon.

ThaUnknown avatar ThaUnknown commented on September 14, 2024

Would be cool, currently is just in order of most preferred/usable by Gluon. Would likely use reg.exe directly to avoid external dependencies.

winreg doesnt have any external dependencies, so I think it's a safe go, it's also been stable for a few years

from gluon.

CanadaHonk avatar CanadaHonk commented on September 14, 2024

I meant having a dependency at all, as you can make a wrapper for reg.exe in ~5 lines

from gluon.

ThaUnknown avatar ThaUnknown commented on September 14, 2024

I meant having a dependency at all, as you can make a wrapper for reg.exe in ~5 lines

hm, too bad, wanted to PR this using that lib, but making a wrapper for a windows executable and parsing errors isn't my forte, here's the code using winreg, util.promisify doesn't seem to work on it :/

import Registry from 'winreg'

const preferred = new Registry({
  hive: Registry.HKCU,
  key: '\\SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\URLAssociations\\https\\UserChoice'
})
preferred.get('ProgID', (_err, item) => {
  const ProgID = item.value
  const browser = new Registry({
    hive: Registry.HKLM,
    key: `\\SOFTWARE\\Classes\\${ProgID}\\shell\\open\\command`
  })
  browser.get(Registry.DEFAULT_VALUE, (_err, item) => {
    const shell = item.value
    console.log(shell)
  })
})

from gluon.

CanadaHonk avatar CanadaHonk commented on September 14, 2024

Oh, apologies. Code looks good and understandable, using a custom wrapper allows using promises as well so lol.

from gluon.

CanadaHonk avatar CanadaHonk commented on September 14, 2024

Possibly could be an easier idea to use file associations like .html instead. Dedicated command line tool for it on Windows so would be much simpler but unsure if some people/browsers don't set file associations.

from gluon.

steviegt6 avatar steviegt6 commented on September 14, 2024

Preferred file associations for .html would be a generally safe bet, but accessing based on https preferences may be the best way to go? Windows is a "little" aggressive with their promotion of Microsoft Edge, so they don't reliably change all file types when you update your preferences.

from gluon.

ThaUnknown avatar ThaUnknown commented on September 14, 2024

Preferred file associations for .html would be a generally safe bet, but accessing based on https preferences may be the best way to go? Windows is a "little" aggressive with their promotion of Microsoft Edge, so they don't reliably change all file types when you update your preferences.

.html is bad as it also lists text editors like vscode which are also in theory chromium, so i just went with https and browser detection

from gluon.

CanadaHonk avatar CanadaHonk commented on September 14, 2024

Yeah changed my mind, have an almost complete implementation which I'm leaving for 0.10.0, 0.9.0 should be releasing today with some new APIs.

from gluon.

bernardobelchior avatar bernardobelchior commented on September 14, 2024

On macOS I have found a way to obtain the default browser.

You can use plutil -convert json -o - ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist to obtain the mapping of schemes/protocols to bundle IDs. 1 2

From that, you get something like:

{
  "LSHandlers" : [
    { /* Other options */ }
    {
      "LSHandlerPreferredVersions" : {
        "LSHandlerRoleAll" : "-"
      },
      "LSHandlerRoleAll" : "org.mozilla.firefox",
      "LSHandlerURLScheme" : "https"
    },
    { /* Other options */ }
  ]
}

Parsing that JSON, you can search for the object whose property LSHandlerURLScheme equals "https" and obtain the value of the property LSHandlerRoleAll, which is the bundle identifier of the application -- in this case "org.mozilla.firefox".

Then, you can use mdfind kMDItemCFBundleIdentifier = "org.mozilla.firefox", which will return the path of the application that that identifier belongs to. In this case, for my setup, it returned /Applications/Firefox.app.

From this information, you can access the Info.plist, which is located in /Applications/Firefox.app/Contents/Info.plist and once again use plutil to fetch the executable file that should be run using plutil -extract CFBundleExecutable raw /Applications/Firefox.app/Contents/Info.plist.

This will return firefox, which means the final path is /Applications/Firefox.app/Contents/MacOS/firefox.

You can also use plutil -extract CFBundleName raw /Applications/Firefox.app/Contents/Info.plist to obtain the application name, which will return "Firefox" for Firefox and "Chrome" for Google Chrome. This can be useful to compare against the supported browsers for gluon.

Footnotes

  1. Taken from here. Note that the path differs for older versions of macOS.

  2. You can add the -r to get a prettified JSON response.

from gluon.

Eccenux avatar Eccenux commented on September 14, 2024

On Windows getting exe path from this is most universal: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\${ProgID}\shell\open\command. It will also work when users have non-standard path. Which would be more common for Firefox then Chrome probably.

from gluon.

ThaUnknown avatar ThaUnknown commented on September 14, 2024

On Windows getting exe path from this is most universal: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\${ProgID}\shell\open\command. It will also work when users have non-standard path. Which would be more common for Firefox then Chrome probably.

image
its legit in the original post

from gluon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.