saadtazi / firefox-profile-js

Firefox Profile creation using nodejs and CLI
MIT License
60 stars 30 forks source link

support ubuntu path (~/snap/...) #139

Closed saadtazi closed 7 months ago

saadtazi commented 7 months ago

if linux, check if default firefox/ dir is present, if not, use ubuntu path.

jrom99 commented 7 months ago

Mentioning the issue for easier access: https://github.com/saadtazi/firefox-profile-js/issues/136

jrom99 commented 7 months ago

This may be a dumb question, and totally unrelated to the issue, but is there any reason in particular to use Class.prototype instead of JS class syntax?

saadtazi commented 7 months ago

This may be a dumb question, and totally unrelated to the issue, but is there any reason in particular to use Class.prototype instead of JS class syntax?

good question: firefox-profile package was created in october 2013 (more than 10 years ago 👴 ), at that time, class and const/let didn't exist in nodejs. class was introduced in nodejs 4.0.0 (in 2015).

I no longer use this package, so I didn't take the time to update the code (nor the test/CI tools)

jrom99 commented 7 months ago

On second thought, I think process.env does not listen to snap or flatpak overrides for firefox.

In this case, I think the best behavior would be to assume that we can be dealing with a sandboxed or unsandboxed firefox install, where the normal home can still be a valid location for profile data, since both snap and flatpak seem to allow it.

So the code could be something like:

function locateLinuxDirectory() {
  userHomeDir = process.env.HOME;

  // look for a valid sandboxed profile dir
  homes = [
     path.join(userHomeDir, "snap/firefox/common"),
     path.join(userHomeDir, ".var/app/org.mozilla.firefox")
  ]
  for (home of homes) {
     dotDir = path.join(home, ".mozilla/firefox")
     xdgDir = path.join(home, ".config/mozilla/firefox")
     if (fs.existsSync(dotDir) {
       return dotDir
     } else if (fs.existsSync(xdgDir)) {
       return xdgDir
     }
  }

  // look in the next probable locations
  dotDir = path.join(userHomeDir, ".mozilla/firefox")
  xdgConfigDir = process.env.XDG_CONFIG_HOME || path.join(userHomedir, ".config")
  xdgDir = path.join(xdgConfigDir, "mozilla/firefox")
  return fs.existsSync(dotDir) ? dotDir : xdgDir;
}
saadtazi commented 7 months ago

sorry for the delay, I didn't have access to a computer... pushed some changes...

jrom99 commented 7 months ago

I think the logic is still inverted for global installs. The dot dir should be preferred if it exists, but it should not be the default directory.

Also, the XDG config dir doesn't need a leading dot.