zumoshi / BrowserSelect

Browser Select is a utility to dynamically select the browser you want instead of just having one default for all links.
GNU General Public License v2.0
289 stars 39 forks source link

Edge (Chromium) multiple profiles #61

Open jonhil opened 4 years ago

jonhil commented 4 years ago

Hello,

BrowserSelect does not detect every profile in the new edge based on chromium. The app does only show the Browser itself and not every profile as it does with chrome.

miguel-ka commented 4 years ago

Is Edge handling profiles differently than Chromium, even if it is based on it? Would be a great feature.

JaspalX commented 4 years ago

Is Edge handling profiles differently than Chromium, even if it is based on it? Would be a great feature.

edge chromium profiles seem to be working the same as google chrome profiles (as in folder structure etc.) ...if that's what you're asking?

JaspalX commented 4 years ago

fwiw, I hacked browser.cs to find edge chromium profiles...it seems to be unable to work out the name of the profile when you've got a logged in microsoft account, but it does work. I'm too unfamiliar with github and c# coding to work out how to get this into the main code base, but if anyone wants the code here it is (replaces from line 131 to 178 in the original browser.cs file):

                //check for edge chromium profiles
                AddChromeProfiles(browsers, "Microsoft Edge", @"Microsoft\Edge\User Data", "Edge Profile.ico");

                //Check for Chrome Profiles
                AddChromeProfiles(browsers, "Google Chrome", @"Google\Chrome\User Data", "Google Profile.ico");

                System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(browsers));
                Properties.Settings.Default.BrowserList = JsonConvert.SerializeObject(browsers);
                Properties.Settings.Default.Save();
            }

            return browsers;
        }

        private static void AddChromeProfiles(List<Browser> browsers, string BrowserName, string VendorDataFolder, string IconFilename)
        {
            Browser BrowserChrome = browsers.FirstOrDefault(x => x.name == BrowserName);
            if (BrowserChrome != null)
            {
                string ChromeUserDataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), VendorDataFolder);
                List<string> ChromeProfiles = FindChromeProfiles(ChromeUserDataDir, IconFilename);

                if (ChromeProfiles.Count > 1)
                {
                    //add the Chrome instances and remove the default one
                    foreach (string Profile in ChromeProfiles)
                    {
                        browsers.Add(new Browser()
                        {
                            name = BrowserName + " (" + GetChromeProfileName(ChromeUserDataDir + "\\" + Profile) + ")",
                            exec = BrowserChrome.exec,
                            icon = icon2String(IconExtractor.fromFile(ChromeUserDataDir + "\\" + Profile + "\\" + IconFilename)),
                            additionalArgs = String.Format("--profile-directory={0}", Profile)
                        });
                    }
                    browsers.Remove(BrowserChrome);
                    browsers = browsers.OrderBy(x => x.name).ToList();
                }
            }
        }
        private static string GetChromeProfileName(string FullProfilePath)
        {
            dynamic ProfilePreferences = JObject.Parse(File.ReadAllText(FullProfilePath + @"\Preferences"));
            return ProfilePreferences.profile.name;
        }

        private static List<string> FindChromeProfiles(string ChromeUserDataDir, string IconFilename)
        {
            List<string> Profiles = new List<string>();
            var ProfileDirs = Directory.GetFiles(ChromeUserDataDir, IconFilename, SearchOption.AllDirectories).Select(Path.GetDirectoryName);
            foreach (var Profile in ProfileDirs)
            {
                Profiles.Add(Profile.Substring(ChromeUserDataDir.Length + 1));
            }
            return Profiles;
        }

@zumoshi fyi

JaspalX commented 4 years ago

...now if someone could show me how to fix it so that I could launch different browsers for the same domain but different url pattern+wildcard rather than just one domain= one browser that would be awesome :)

zumoshi commented 4 years ago

Thanks for looking into it. If you would create a pull request I will accept it and make an official release with your changes.

I'm too unfamiliar with github

There are some good resources on how to do that: https://opensource.com/article/19/7/create-pull-request-github https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request

same domain but different url

That is unrelated to this issue, please open a new one. But in short, the wildcard is already supported, (e.g. *.whatever.com), You just need to include the path in the string the rules are checked against. Somewhere around here. Check the Uri Class documentation for properties other than Host to check. The tricky part would be to make sure it won't break domain-only rules if say the domain name existed somewhere in the url's path. (e.g. something.com/link/somethingelse.com/ )