@@ -103,9 +103,7 @@ bool HostInstaller::checkIfProxyExists(const bool& proxy, const QString& locatio
103103void HostInstaller::installBrowser (SupportedBrowsers browser,
104104 const bool & enabled,
105105 const bool & proxy,
106- const QString& location,
107- const bool & customBrowser,
108- const QString& customBrowserPath)
106+ const QString& location)
109107{
110108 if (enabled) {
111109#ifdef Q_OS_WIN
@@ -115,15 +113,15 @@ void HostInstaller::installBrowser(SupportedBrowsers browser,
115113#endif
116114 // Always create the script file
117115 QJsonObject script = constructFile (browser, proxy, location);
118- if (!saveFile (browser, script, customBrowser, customBrowserPath )) {
116+ if (!saveFile (browser, script)) {
119117 QMessageBox::critical (nullptr ,
120118 tr (" KeePassXC: Cannot save file!" ),
121119 tr (" Cannot save the native messaging script file." ),
122120 QMessageBox::Ok);
123121 }
124122 } else {
125123 // Remove the script file
126- const QString fileName = customBrowser ? customBrowserPath : getPath (browser);
124+ const QString fileName = getPath (browser);
127125 QFile::remove (fileName);
128126#ifdef Q_OS_WIN
129127 // Remove the registry entry
@@ -141,14 +139,19 @@ void HostInstaller::installBrowser(SupportedBrowsers browser,
141139 */
142140void HostInstaller::updateBinaryPaths (const bool & proxy, const QString& location)
143141{
144- // Where 6 is the number of entries in the SupportedBrowsers enum declared in HostInstaller.h
145- for (int i = 0 ; i < 6 ; ++i) {
142+ for (int i = 0 ; i <= SupportedBrowsers::CUSTOM; ++i) {
146143 if (checkIfInstalled (static_cast <SupportedBrowsers>(i))) {
147144 installBrowser (static_cast <SupportedBrowsers>(i), true , proxy, location);
148145 }
149146 }
150147}
151148
149+ void HostInstaller::setCustomBrowserSettings (const QString& path, SupportedBrowsers browser)
150+ {
151+ m_customBrowserPath = path;
152+ m_customBrowserType = browser;
153+ }
154+
152155/* *
153156 * Returns the target path for each browser. Windows uses a registry path instead of a file path
154157 *
@@ -170,6 +173,8 @@ QString HostInstaller::getTargetPath(SupportedBrowsers browser) const
170173 return TARGET_DIR_TOR_BROWSER;
171174 case SupportedBrowsers::BRAVE:
172175 return TARGET_DIR_BRAVE;
176+ case SupportedBrowsers::CUSTOM:
177+ return m_customBrowserPath;
173178 default :
174179 return QString ();
175180 }
@@ -197,6 +202,8 @@ QString HostInstaller::getBrowserName(SupportedBrowsers browser) const
197202 return " tor-browser" ;
198203 case SupportedBrowsers::BRAVE:
199204 return " brave" ;
205+ case SupportedBrowsers::CUSTOM:
206+ return " custom" ;
200207 default :
201208 return QString ();
202209 }
@@ -225,6 +232,11 @@ QString HostInstaller::getPath(SupportedBrowsers browser) const
225232 return winPath;
226233#else
227234 const QString path = getTargetPath (browser);
235+
236+ if (browser == SupportedBrowsers::CUSTOM) {
237+ return QString (" %1/%2.json" ).arg (m_customBrowserPath, HOST_NAME);
238+ }
239+
228240 return QString (" %1%2/%3.json" ).arg (QDir::homePath (), path, HOST_NAME);
229241#endif
230242}
@@ -302,7 +314,8 @@ QJsonObject HostInstaller::constructFile(SupportedBrowsers browser, const bool&
302314 script[" type" ] = QString (" stdio" );
303315
304316 QJsonArray arr;
305- if (browser == SupportedBrowsers::FIREFOX || browser == SupportedBrowsers::TOR_BROWSER) {
317+ if (browser == SupportedBrowsers::FIREFOX || browser == SupportedBrowsers::TOR_BROWSER ||
318+ (browser == SupportedBrowsers::CUSTOM && m_customBrowserType == SupportedBrowsers::FIREFOX)) {
306319 for (const QString& extension : ALLOWED_EXTENSIONS) {
307320 arr.append (extension);
308321 }
@@ -335,16 +348,11 @@ bool HostInstaller::registryEntryFound(const QSettings& settings)
335348 * @param script JSON native messaging script object
336349 * @return bool Write succeeds
337350 */
338- bool HostInstaller::saveFile (SupportedBrowsers browser,
339- const QJsonObject& script,
340- const bool & customBrowser,
341- const QString& customBrowserPath)
351+ bool HostInstaller::saveFile (SupportedBrowsers browser, const QJsonObject& script)
342352{
343- const QString path = customBrowser ?
344- QString (" %1/%2.json" ).arg (customBrowserPath, HOST_NAME) :
345- getPath (browser);
353+ const QString path = getPath (browser);
346354 const QString installDir = getInstallDir (browser);
347- QDir dir (installDir);
355+ const QDir dir (installDir);
348356 if (!dir.exists ()) {
349357 QDir ().mkpath (installDir);
350358 }
0 commit comments