Git Product home page Git Product logo

rust-sysbar's Introduction

rust-sysbar

Library for interacting with the system's taskbar / tray / statusbar. It aims to be cross-platform, but currently only supports macOS. If have some extra time and are interested in implementing this for other platforms, contributions would be greatly appreciated! This project is a fork of rs-barfly.

Example

let mut bar = sysbar::Sysbar::new("Foo");

bar.add_item(
    "Say 'bar'",
    Box::new(move || {
        println!("bar");
    }),
);

bar.add_quit_item("Quit");

bar.display();

Resulting screenshot of code above

See also

License

Licensed under either of

at your option.

rust-sysbar's People

Contributors

frewsxcv avatar jmquigs avatar sandmor avatar ssheldon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rust-sysbar's Issues

Clippy Warning: SysbarImpl is used but is an undeclared type or module

On including this package as a dependency in our project, we get this warning from clippy (which is configured to run as a pre-commit hook):

error[E0433]: failed to resolve: use of undeclared type or module `SysbarImpl`
  --> /home/amit_project/Code/amitu_heroku/.cargo/registry/src/github.com-1ecc6299db9ec823/sysbar-0.2.0/src/lib.rs:12:16
   |
12 |         Sysbar(SysbarImpl::new(name))
   |                ^^^^^^^^^^ use of undeclared type or module `SysbarImpl`

error[E0412]: cannot find type `SysbarImpl` in this scope
 --> /home/amit_project/Code/amitu_heroku/.cargo/registry/src/github.com-1ecc6299db9ec823/sysbar-0.2.0/src/lib.rs:8:19
  |
8 | pub struct Sysbar(SysbarImpl);
  |                   ^^^^^^^^^^ not found in this scope

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0412, E0433.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `sysbar`.

Tray icon support

Some systems only show the icon of the application, what is currently not possible to set.

Dynamic Content

Hey,

is there currently a way to have dynamic content? Like the time or something?

Thanks for the help.

Improve macOS code

The creator of connectr wrote me a message on reddit a while ago, thought I'd paste it here in case others find the information valuable:

If you're interested, I'd be happy to team up with you on making a nice sysbar library. Though I think it's more important to reach out to ones working on systray-rs and see if everyone can agree on one API that works for all three major OSs.

Feel free to take anything useful out of Connectr. As I said, it was my first Rust project and it was driven from an application need, so it didn't end up very clean. The current interface is here: https://github.com/mrmekon/connectr/blob/master/src/lib.rs#L82

The main thing I care about is that I've proven that it runs for 2+ weeks, clearing and rebuilding its menu every 30 seconds, without crashing or leaking memory.

The big things I learned from it:

  1. I don't like depending on tons of libraries, so I want to drop the 'cocoa' lib and use only the 'objc' libs. The cocoa lib is nice, but mixing the two ends up being a pain, and cocoa is missing a lot of functionality. It's less work to just implement it with 'objc' than to try to get upstream changes into 'cocoa'.

  2. Mixing 'cocoa' and 'objc' and 'objcid' leads to some things having Drop traits and some things not, and it gets confusing. My preference now is to use _only 'objc' and do all memory management manually.

  3. I assumed a flat menu design, which was dumb. I'm currently working on changing it to support recursive menus. Items should be added to menu objects, instead of to a global 'sysbar' instance.

  4. Every UI library, and some other libraries (like HTTP libs) assume they will get a run_forever() on the main thread. This makes it impossible to mix them. I went through great pains to make my mine support run_once(), and split that out into a separate library (fruitbasket: see the next item). I think this is important if it will ever be used seriously in bigger applications.

  5. Mac apps can run as standalone binaries or in app bundles, and behave differently. All of my handling for that, and the non-blocking application loop, was split out into fruitbasket. I'm plugging my own thing here, but i think this is the way to go for managing Mac main loops. It can bundle resources and self-package itself, so cargo run builds and executes an app bundle, and you can easily access icon and image resources in the bundle. See here: https://github.com/mrmekon/fruitbasket

  6. After making the menu bar stuff, I made touch bar support for Connectr. This is split out into another library (rubrail), and is much cleaner. It supports infinite recursion and loading images from various sources. If I did the menu bar API again, it would look more like that, but maybe with a Builder pattern and Drop traits to avoid memory leaks. That API is documented here: https://mrmekon.github.io/rubrail-rs/rubrail/trait.TTouchbar.html

  7. For tracing memory leaks, it's super convenient to subclass Obj-C classes and either print or add breakpoints to their retain/release/dealloc methods. I wrote a macro to do that: https://github.com/mrmekon/rubrail-rs/blob/master/src/wrapper.rs

  8. Where the systray/menubar UI isn't quite enough - like needing text input - I've taken to spawning a local web server that serves a static HTML form and returns key/value pairs. This is cross-platform enough. My plan was to split the menu bar stuff out into one library, the web config stuff into a separate library, and recommend using them together. Anyway, it's a strategy worth considering when building cross-platform apps in a world with no cross-platform GUIs: https://github.com/mrmekon/connectr/blob/master/src/settings/mod.rs#L65

Progress indicator

Hi, would be nice if this crate supports a progress indicator in the taskbar item, I'm unsure if macOS support it but Windows and Linux do

Audit macOS callback code

// SO.. some explanation is in order here. We want to allow closure callbacks that
// can modify their environment. But we can't keep them on the $name object because
// that is really just a stateless proxy for the objc object. So we store them
// as numeric pointers values in "ivar" fields on that object. But, if we store a pointer to the
// closure object, we'll run into issues with thin/fat pointer conversions (because
// closure objects are trait objects and thus fat pointers). So we wrap the closure in
// another boxed object ($cbs_name), which, since it doesn't use traits, is actually a
// regular "thin" pointer, and store THAT pointer in the ivar. But...so...oy.
struct CallbackState {
cb: Box<Fn() -> ()>,
}
impl Callback {
fn from(cb: Box<Fn() -> ()>) -> Id<Self> {
let cbs = CallbackState { cb: cb };
let bcbs = Box::new(cbs);
let ptr = Box::into_raw(bcbs);
let ptr = ptr as *mut c_void as usize;
println!("{}", ptr);
let mut oid = <Callback as INSObject>::new();
(*oid).setptr(ptr);
oid
}
fn setptr(&mut self, uptr: usize) {
unsafe {
let obj = &mut *(self as *mut _ as *mut ::objc::runtime::Object);
println!("setting the ptr: {}", uptr);
obj.set_ivar("_cbptr", uptr);
}
}
}
// TODO: Drop for $name doesn't get called, probably because objc manages the memory and
// releases it for us. so we leak the boxed callback right now.
impl INSObject for Callback {
fn class() -> &'static Class {
let cname = "Callback";
let mut klass = Class::get(cname);
if klass.is_none() {
println!("registering class for {}", cname);
let superclass = NSObject::class();
let mut decl = ClassDecl::new(&cname, superclass).unwrap();
decl.add_ivar::<usize>("_cbptr");
extern "C" fn sysbar_callback_call(this: &Object, _cmd: Sel) {
println!("callback, getting the pointer");
unsafe {
let pval: usize = *this.get_ivar("_cbptr");
let ptr = pval as *mut c_void;
let ptr = ptr as *mut CallbackState;
let bcbs: Box<CallbackState> = Box::from_raw(ptr);
{
println!("cb test from cb");
(*bcbs.cb)();
}
mem::forget(bcbs);
}
}
unsafe {
decl.add_method(
sel!(call),
sysbar_callback_call as extern "C" fn(&Object, Sel),
);
}
decl.register();
klass = Class::get(cname);
}
klass.unwrap()
}
}

this was inherited from rs-barfly and i'm not entirely sure what's going on here

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.