-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from trakout/linux-ksni-set_menu_item_label
Adds menu item update capability for Linux (KSNI)
- Loading branch information
Showing
5 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "linux-edit-menu-items" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
tray-item = { path = "../../", features = ["ksni"] } | ||
png = "0.16" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use {std::io::Cursor, std::sync::mpsc, tray_item::IconSource, tray_item::TrayItem}; | ||
|
||
enum Message { | ||
Quit, | ||
Update, | ||
} | ||
|
||
fn main() { | ||
let cursor_red = Cursor::new(include_bytes!("../../resources/tray_icon-red.png")); | ||
let decoder_red = png::Decoder::new(cursor_red); | ||
let (info_red, mut reader_red) = decoder_red.read_info().unwrap(); | ||
let mut buf_red = vec![0; info_red.buffer_size()]; | ||
reader_red.next_frame(&mut buf_red).unwrap(); | ||
|
||
let icon_red = IconSource::Data { | ||
data: buf_red, | ||
height: 32, | ||
width: 32, | ||
}; | ||
|
||
let mut tray = TrayItem::new("Tray Example", icon_red).unwrap(); | ||
|
||
tray.add_label("Tray Label").unwrap(); | ||
|
||
let (tx, rx) = mpsc::sync_channel::<Message>(2); | ||
let update_tx = tx.clone(); | ||
let id_menu = tray | ||
.inner_mut() | ||
.add_menu_item_with_id("Update Menu Item", move || { | ||
update_tx.send(Message::Update).unwrap(); | ||
}) | ||
.unwrap(); | ||
|
||
let quit_tx = tx.clone(); | ||
tray.add_menu_item("Quit", move || { | ||
quit_tx.send(Message::Quit).unwrap(); | ||
}) | ||
.unwrap(); | ||
|
||
loop { | ||
match rx.recv() { | ||
Ok(Message::Quit) => { | ||
println!("Quit"); | ||
break; | ||
} | ||
Ok(Message::Update) => { | ||
println!("Update Menu Item!"); | ||
tray.inner_mut() | ||
.set_menu_item_label("Menu Updated", id_menu) | ||
.unwrap(); | ||
} | ||
_ => {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters