|
| 1 | +/* |
| 2 | + ------------------------------------------------------------------------------- |
| 3 | + This file is part of the Private Message Database. |
| 4 | + Copyright (C) 2025 Dirk Stolle |
| 5 | +
|
| 6 | + This program is free software: you can redistribute it and/or modify |
| 7 | + it under the terms of the GNU General Public License as published by |
| 8 | + the Free Software Foundation, either version 3 of the License, or |
| 9 | + (at your option) any later version. |
| 10 | +
|
| 11 | + This program is distributed in the hope that it will be useful, |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + GNU General Public License for more details. |
| 15 | +
|
| 16 | + You should have received a copy of the GNU General Public License |
| 17 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + ------------------------------------------------------------------------------- |
| 19 | +*/ |
| 20 | + |
| 21 | +#include "browser_detection.hpp" |
| 22 | + |
| 23 | +std::optional<BrowserInformation> detect_browser() |
| 24 | +{ |
| 25 | + #ifdef _WIN32 |
| 26 | + // TODO: Not implemented yet. |
| 27 | + return std::optional<BrowserInformation>(); |
| 28 | + #else |
| 29 | + // On Linux systems the paths are usually similar, depending on how the |
| 30 | + // browser was packaged. So it's easiest to just test some known paths. |
| 31 | + const std::vector<BrowserInformation> known_paths = { |
| 32 | + { "/usr/bin/firefox", Browser::Firefox }, |
| 33 | + { "/usr/bin/firefox-esr", Browser::Firefox }, |
| 34 | + { "/usr/bin/firefox-devedition", Browser::Firefox }, |
| 35 | + { "/usr/bin/chromium", Browser::Chromium }, |
| 36 | + { "/usr/bin/chromium-browser", Browser::Chromium }, |
| 37 | + }; |
| 38 | + |
| 39 | + for (const auto& element: known_paths) |
| 40 | + { |
| 41 | + std::error_code error; |
| 42 | + if (std::filesystem::is_regular_file(element.path, error) && !error) |
| 43 | + { |
| 44 | + return element; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + // No known browser found. |
| 49 | + return std::optional<BrowserInformation>(); |
| 50 | + #endif |
| 51 | +} |
| 52 | + |
| 53 | +std::vector<std::string> additional_parameters(const Browser type) |
| 54 | +{ |
| 55 | + switch(type) |
| 56 | + { |
| 57 | + case Browser::Firefox: |
| 58 | + return { "--private-window" }; |
| 59 | + case Browser::Chromium: |
| 60 | + return { "--incognito" }; |
| 61 | + default: |
| 62 | + return {}; |
| 63 | + } |
| 64 | +} |
0 commit comments