Skip to content

Commit

Permalink
Improve tray icon images
Browse files Browse the repository at this point in the history
1. Adds generator script
2. This script uses special packer that forces png compression,
   reducing the resulting .ico file sizes tremendously
3. Also uses optipng to reduce the size around 20% more
4. Since the sizes are reduced, we generate the icons for all
   non-custom dpi scaling values
5. Renames favicon.ico to sunshine.ico, since it's now used in
   other places such as tray icon
  • Loading branch information
ns6089 committed Oct 11, 2023
1 parent 395d572 commit 1bc3242
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 4 deletions.
59 changes: 59 additions & 0 deletions scripts/icons/convert_and_pack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

if ! [ -x "$(command -v ./go-png2ico)" ]; then
echo "./go-png2ico not found"
echo "download the executable from https://github.com/J-Siu/go-png2ico"
echo "and drop it in this folder"
exit 1
fi

if ! [ -x "$(command -v optipng)" ]; then
echo "optipng executable not found"
exit 1
fi

if ! [ -x "$(command -v inkscape)" ]; then
echo "inkscape executable not found"
exit 1
fi

icon_base_sizes=(16 64)
icon_sizes_keys=() # associative array to prevent duplicates
icon_sizes_keys[256]=1

for icon_base_size in ${icon_base_sizes[@]}; do
# increment in 25% till 400%
icon_size_increment=$((icon_base_size / 4))
for ((i = 0; i <= 12; i++)); do
icon_sizes_keys[$((icon_base_size + i * icon_size_increment))]=1
done
done

# convert to normal array
icon_sizes=${!icon_sizes_keys[@]}

echo "using icon sizes:"
echo ${icon_sizes[@]}

src_vectors=("../../src_assets/common/assets/web/images/sunshine-locked.svg"
"../../src_assets/common/assets/web/images/sunshine-pausing.svg"
"../../src_assets/common/assets/web/images/sunshine-playing.svg"
"../../sunshine.svg")

echo "using sources vectors:"
echo ${src_vectors[@]}

for src_vector in ${src_vectors[@]}; do
file_name=`basename "$src_vector" .svg`
png_files=()
for icon_size in ${icon_sizes[@]}; do
png_file="${file_name}${icon_size}.png"
echo "converting ${png_file}"
inkscape -w $icon_size -h $icon_size "$src_vector" --export-filename "${png_file}" &&
optipng -o7 "${png_file}" &&
png_files+=("${png_file}")
done

echo "packing ${file_name}.ico"
./go-png2ico "${png_files[@]}" "${file_name}.ico"
done
4 changes: 2 additions & 2 deletions src/confighttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ namespace confighttp {
// todo - use mime_types map
print_req(request);

std::ifstream in(WEB_DIR "images/favicon.ico", std::ios::binary);
std::ifstream in(WEB_DIR "images/sunshine.ico", std::ios::binary);
SimpleWeb::CaseInsensitiveMultimap headers;
headers.emplace("Content-Type", "image/x-icon");
response->write(SimpleWeb::StatusCode::success_ok, in, headers);
Expand Down Expand Up @@ -755,7 +755,7 @@ namespace confighttp {
server.resource["^/api/clients/unpair$"]["POST"] = unpairAll;
server.resource["^/api/apps/close$"]["POST"] = closeApp;
server.resource["^/api/covers/upload$"]["POST"] = uploadCover;
server.resource["^/images/favicon.ico$"]["GET"] = getFaviconImage;
server.resource["^/images/sunshine.ico$"]["GET"] = getFaviconImage;
server.resource["^/images/logo-sunshine-45.png$"]["GET"] = getSunshineLogoImage;
server.resource["^/node_modules\\/.+$"]["GET"] = getNodeModules;
server.config.reuse_address = true;
Expand Down
2 changes: 1 addition & 1 deletion src/system_tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define WIN32_LEAN_AND_MEAN
#include <accctrl.h>
#include <aclapi.h>
#define TRAY_ICON WEB_DIR "images/favicon.ico"
#define TRAY_ICON WEB_DIR "images/sunshine.ico"
#define TRAY_ICON_PLAYING WEB_DIR "images/sunshine-playing.ico"
#define TRAY_ICON_PAUSING WEB_DIR "images/sunshine-pausing.ico"
#define TRAY_ICON_LOCKED WEB_DIR "images/sunshine-locked.ico"
Expand Down
2 changes: 1 addition & 1 deletion src_assets/common/assets/web/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sunshine</title>
<link rel="icon" type="image/x-icon" href="/images/favicon.ico">
<link rel="icon" type="image/x-icon" href="/images/sunshine.ico">
<link href="/node_modules/@fortawesome/fontawesome-free/css/all.min.css" rel="stylesheet">
<link href="/node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
Expand Down
Binary file removed src_assets/common/assets/web/images/favicon.ico
Binary file not shown.
Binary file modified src_assets/common/assets/web/images/sunshine-locked.ico
Binary file not shown.
Binary file modified src_assets/common/assets/web/images/sunshine-pausing.ico
Binary file not shown.
Binary file modified src_assets/common/assets/web/images/sunshine-playing.ico
Binary file not shown.
Binary file added src_assets/common/assets/web/images/sunshine.ico
Binary file not shown.

0 comments on commit 1bc3242

Please sign in to comment.