Skip to content

Commit

Permalink
feat: add toggle to switch from light to dark mode icons
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed May 19, 2023
1 parent de34a2e commit 08d098d
Show file tree
Hide file tree
Showing 21 changed files with 306 additions and 72 deletions.
120 changes: 118 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ anyhow = "1.0.70"
async-osc = "0.2.0"
cfg-if = "1.0.0"
chrono = "0.4.24"
clap = { version = "4.1.4", features = ["derive"] }
directories = "5.0.1"
env_logger = "0.10.0"
log = "0.4.17"
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ This is indicated in your tray bar through the `OSC` icon. When it's inactive, i
Via the tray icon menu you also have two options available:

- Exit the application
- Reload plugins: This will reload the entire plugin config in case you changed it on disk.
- Reload plugins: This will reload the entire plugin config in case you changed it on disk.

## Dark mode

Depending on your operating system theme, the default light icons might not be visible in your tray bar. You can switch
to icons for dark mode by passing `--dark-mode-icons` as command line argument.

## OS support

Expand Down
Binary file removed assets/icon-active.ico
Binary file not shown.
Binary file removed assets/icon-active.png
Binary file not shown.
Binary file added assets/icon-dark-active.ico
Binary file not shown.
Binary file added assets/icon-dark-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon-dark-inactive.ico
Binary file not shown.
Binary file added assets/icon-dark-inactive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/icon-inactive.ico
Binary file not shown.
Binary file removed assets/icon-inactive.png
Binary file not shown.
Binary file added assets/icon-light-active.ico
Binary file not shown.
Binary file added assets/icon-light-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon-light-inactive.ico
Binary file not shown.
Binary file added assets/icon-light-inactive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions assets/icons.rc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
app_icon ICON "icon-active.ico"
inactive-icon ICON "icon-inactive.ico"
active-icon ICON "icon-active.ico"
app_icon ICON "icon-light-active.ico"
dark_inactive_icon ICON "icon-dark-inactive.ico"
dark_active_icon ICON "icon-dark-active.ico"
light_inactive_icon ICON "icon-light-inactive.ico"
light_active_icon ICON "icon-light-active.ico"

114 changes: 73 additions & 41 deletions assets/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 22 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use image::Rgba;
use std::{env, fs, path::Path};
extern crate embed_resource;

const INACTIVE_PNG_ICON: &[u8] = include_bytes!("assets/icon-inactive.png");
const ACTIVE_PNG_ICON: &[u8] = include_bytes!("assets/icon-active.png");
const DARK_INACTIVE_PNG_ICON: &[u8] = include_bytes!("assets/icon-dark-inactive.png");
const DARK_ACTIVE_PNG_ICON: &[u8] = include_bytes!("assets/icon-dark-active.png");
const LIGHT_INACTIVE_PNG_ICON: &[u8] = include_bytes!("assets/icon-light-inactive.png");
const LIGHT_ACTIVE_PNG_ICON: &[u8] = include_bytes!("assets/icon-light-active.png");

fn convert(img: &[u8]) -> Result<Vec<u8>, image::ImageError> {
let img = image::load_from_memory(img)?;
Expand All @@ -22,13 +24,23 @@ fn main() {
let out_path = Path::new(out_dir);

fs::write(
out_path.join("linux-inactive-icon"),
convert(INACTIVE_PNG_ICON).unwrap(),
out_path.join("linux-dark-inactive-icon"),
convert(DARK_INACTIVE_PNG_ICON).unwrap(),
)
.unwrap();
fs::write(
out_path.join("linux-active-icon"),
convert(ACTIVE_PNG_ICON).unwrap(),
out_path.join("linux-dark-active-icon"),
convert(DARK_ACTIVE_PNG_ICON).unwrap(),
)
.unwrap();
fs::write(
out_path.join("linux-light-inactive-icon"),
convert(LIGHT_INACTIVE_PNG_ICON).unwrap(),
)
.unwrap();
fs::write(
out_path.join("linux-light-active-icon"),
convert(LIGHT_ACTIVE_PNG_ICON).unwrap(),
)
.unwrap();
}
Expand All @@ -38,7 +50,9 @@ fn main() {
}

println!("cargo:rerun-if-changed=assets/icons.rc");
println!("cargo:rerun-if-changed=assets/icon-inactive.ico");
println!("cargo:rerun-if-changed=assets/icon-active.ico");
println!("cargo:rerun-if-changed=assets/icon-dark-inactive.ico");
println!("cargo:rerun-if-changed=assets/icon-dark-active.ico");
println!("cargo:rerun-if-changed=assets/icon-light-inactive.ico");
println!("cargo:rerun-if-changed=assets/icon-light-active.ico");
println!("cargo:rerun-if-changed=build.rs");
}
12 changes: 12 additions & 0 deletions scripts/generate-icons.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

inkscape --actions="export-area:0:0:64:64; export-filename:assets/icon-dark-inactive.png; export-do" assets/icons.svg
inkscape --actions="export-area:64:0:128:64; export-filename:assets/icon-dark-active.png; export-do" assets/icons.svg
inkscape --actions="export-area:0:64:64:128; export-filename:assets/icon-light-inactive.png; export-do" assets/icons.svg
inkscape --actions="export-area:64:64:128:128; export-filename:assets/icon-light-active.png; export-do" assets/icons.svg

convert assets/icon-dark-inactive.png assets/icon-dark-inactive.ico
convert assets/icon-dark-active.png assets/icon-dark-active.ico
convert assets/icon-light-inactive.png assets/icon-light-inactive.ico
convert assets/icon-light-active.png assets/icon-light-active.ico

24 changes: 22 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod tray;
use crate::config::{load_config, Config};
use anyhow::Result;
use async_osc::OscMessage;
use clap::Parser;
use log::{debug, info};
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -98,6 +99,7 @@ struct Launcher {
config: Arc<Config>,
receiver_tx: broadcast::Sender<OscMessage>,
sender_tx: mpsc::Sender<OscMessage>,
dark_mode_icons: bool,
}

impl Launcher {
Expand All @@ -106,18 +108,20 @@ impl Launcher {
config: Arc<Config>,
receiver_tx: broadcast::Sender<OscMessage>,
sender_tx: mpsc::Sender<OscMessage>,
dark_mode_icons: bool,
) -> Self {
Self {
rx,
config,
receiver_tx,
sender_tx,
dark_mode_icons,
}
}

async fn wait(&mut self, subsys: &SubsystemHandle) -> Result<()> {
let (reload_tx, mut reload_rx) = mpsc::channel(4);
let mut tray = tray::Tray::new(reload_tx)?;
let mut tray = tray::Tray::new(reload_tx, self.dark_mode_icons)?;
let mut maybe_plugin_subsys: Option<NestedSubsystem> = None;

loop {
Expand Down Expand Up @@ -179,10 +183,19 @@ impl Launcher {
}
}

#[derive(Parser)]
struct Args {
/// Use icons optimized for dark mode
#[arg(long, default_value_t = false)]
dark_mode_icons: bool,
}

#[tokio::main]
async fn main() -> Result<()> {
env_logger::init();

let args = Args::parse();

let config = Arc::new(load_config().await?);
let (tx, rx) = mpsc::channel(2);

Expand All @@ -198,7 +211,14 @@ async fn main() -> Result<()> {
VrChatActivity::new(tx).run(subsys)
})
.start("Launcher", move |subsys| {
Launcher::new(rx, config, launcher_receiver_tx, sender_tx).run(subsys)
Launcher::new(
rx,
config,
launcher_receiver_tx,
sender_tx,
args.dark_mode_icons,
)
.run(subsys)
})
.start("OscSender", move |subsys| {
osc::Sender::new(sender_rx, send_port).run(subsys)
Expand Down
Loading

0 comments on commit 08d098d

Please sign in to comment.