aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorecajan <131694412+ecajan@users.noreply.github.com>2025-01-22 15:02:30 +0100
committerecajan <131694412+ecajan@users.noreply.github.com>2025-01-22 15:02:30 +0100
commit73437c8d1d525cc331454d336e5fbd81255976da (patch)
tree8c184a0132b04b3e9774574809f2d050b90f022d
parentdbfa3c8d9e6888b84a20dfb063656fd71327bafc (diff)
Improved Icon Code
-rw-r--r--src/main.cpp23
-rwxr-xr-xwebtrayctl7
2 files changed, 22 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 1ba4637..385d3c3 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -18,15 +18,21 @@ const QWebEnginePage::Feature features[] = {
QWebEnginePage::Feature::MediaVideoCapture,
};
-QString
-extract_url(const QStringList arguments)
+void
+extract_url(const QStringList arguments, QString *url, QString *icon)
{
+ int index = 0;
+
for (const auto &argument : arguments) {
if (!argument.endsWith("webtray") && !argument.startsWith("--")) {
- return argument;
+ if (index == 0) {
+ *url = argument;
+ } else {
+ *icon = argument;
+ }
+ index += 1;
}
}
- return "";
}
int
@@ -35,7 +41,8 @@ main(int argc, char **argv)
QApplication *app = new QApplication(argc, argv);
app->setQuitOnLastWindowClosed(false);
- QString url = extract_url(app->arguments());
+ QString url, iconpath;
+ extract_url(app->arguments(), &url, &iconpath);
if (url.isEmpty()) {
std::cerr << "webtray [--open-at-startup] <url>\n";
@@ -52,7 +59,11 @@ main(int argc, char **argv)
}
webwindow->connect_icon_changed([&](auto icon) {
- tray->setIcon(icon);
+ if (iconpath.isEmpty()) {
+ tray->setIcon(icon);
+ } else {
+ tray->setIcon(QIcon(iconpath));
+ }
tray->show();
});
diff --git a/webtrayctl b/webtrayctl
index a8ce7b6..3050a15 100755
--- a/webtrayctl
+++ b/webtrayctl
@@ -25,8 +25,11 @@ install_webapp() {
full_url_cancled=$(echo $full_url | sed 's/\//\\\//g')
# get the linkt to the icon by first searching for every <link> tag, containing a icon link
# then getting the string of the first href in the first link, and then appending the extended url to the beginning, if it is not a relative path (only works for http and https protocols)
- iconfile=$(curl -Ls "$url" | grep -o "<link[^>]*rel=[\"']\\(shortcut \\)\\?icon[\"'][^>]*>" | head -n 1 | sed "s/.*href=[\"']\\([^\"]*\\)[\"'].*/\\1/g" | sed "/^http/!s/.*/$full_url_cancled\\/&/")
-
+ if echo "$full_url" | grep 'x\.com' > /dev/null; then
+ iconfile='https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Logo_of_Twitter.svg/240px-Logo_of_Twitter.svg.png'
+ else
+ iconfile=$(curl -Ls "$url" | grep -o "<link[^>]*rel=[\"']\\(shortcut \\)\\?icon[\"'][^>]*>" | head -n 1 | sed "s/.*href=[\"']\\([^\"]*\\)[\"'].*/\\1/g" | sed "/^http/!s/.*/$full_url_cancled\\/&/")
+ fi
file_extension=$(echo "$iconfile" | grep -o '\.[^.]*$')
tmp_icon_name="$name$file_extension"