Struct ksni::TrayService

source ·
pub struct TrayService<T> { /* private fields */ }
Expand description

Service of the tray

Implementations§

source§

impl<T: Tray + 'static> TrayService<T>

source

pub fn new(tray: T) -> Self

Create a new service

Examples found in repository?
examples/example.rs (lines 94-97)
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
fn main() {
    let service = ksni::TrayService::new(MyTray {
        selected_option: 0,
        checked: false,
    });
    let handle = service.handle();
    service.spawn();

    std::thread::sleep(std::time::Duration::from_secs(5));
    // We can modify the handle
    handle.update(|tray: &mut MyTray| {
        tray.checked = true;
    });
    // Run forever
    loop {
        std::thread::park();
    }
}
source

pub fn handle(&self) -> Handle<T>

Get a handle of the tray

Examples found in repository?
examples/example.rs (line 98)
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
fn main() {
    let service = ksni::TrayService::new(MyTray {
        selected_option: 0,
        checked: false,
    });
    let handle = service.handle();
    service.spawn();

    std::thread::sleep(std::time::Duration::from_secs(5));
    // We can modify the handle
    handle.update(|tray: &mut MyTray| {
        tray.checked = true;
    });
    // Run forever
    loop {
        std::thread::park();
    }
}
source

pub fn run(self) -> Result<(), Error>

Run the service in current thread

source

pub fn run_without_dbus_name(self) -> Result<(), Error>

Run the service in current thread, but not register new dbus name

Which is required for some sandboxed environments (flatpak) https://chromium-review.googlesource.com/c/chromium/src/+/4179380

source

pub fn spawn(self)
where T: Send,

Run the service in a new thread

Examples found in repository?
examples/example.rs (line 99)
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
fn main() {
    let service = ksni::TrayService::new(MyTray {
        selected_option: 0,
        checked: false,
    });
    let handle = service.handle();
    service.spawn();

    std::thread::sleep(std::time::Duration::from_secs(5));
    // We can modify the handle
    handle.update(|tray: &mut MyTray| {
        tray.checked = true;
    });
    // Run forever
    loop {
        std::thread::park();
    }
}
source

pub fn spawn_without_dbus_name(self)
where T: Send,

Run the service in a new thread, but not register new dbus name

Which is required for some sandboxed environments (flatpak) https://chromium-review.googlesource.com/c/chromium/src/+/4179380

Auto Trait Implementations§

§

impl<T> Freeze for TrayService<T>

§

impl<T> RefUnwindSafe for TrayService<T>

§

impl<T> Send for TrayService<T>
where T: Send,

§

impl<T> Sync for TrayService<T>
where T: Send,

§

impl<T> Unpin for TrayService<T>

§

impl<T> UnwindSafe for TrayService<T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.