1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#[allow(dead_code)]
#[allow(unused_variables)]
mod interface;
pub use interface::*;
#[allow(unused_imports)]
#[macro_use]
extern crate log;
#[cfg(target_os = "macos")]
#[cfg(feature = "private_api")]
#[macro_use]
extern crate objc;
#[cfg(target_os = "macos")]
#[cfg(feature = "private_api")]
#[macro_use]
mod touchbar;
#[cfg(target_os = "macos")]
#[cfg(feature = "private_api")]
pub use touchbar::Touchbar as Touchbar;
#[cfg(not(feature = "private_api"))]
mod dummy;
#[cfg(not(feature = "private_api"))]
pub use dummy::DummyTouchbar as Touchbar;
#[cfg(target_os = "macos")]
#[cfg(feature = "private_api")]
pub fn init_app() {
unsafe {
let cls = objc::runtime::Class::get("NSApplication").unwrap();
let app: *mut objc::runtime::Object = msg_send![cls, sharedApplication];
let _ = msg_send![app, setActivationPolicy: 1];
let cls = objc::runtime::Class::get("NSAutoreleasePool").unwrap();
let pool: *mut objc::runtime::Object = msg_send![cls, alloc];
let pool: *mut objc::runtime::Object = msg_send![pool, init];
let _ = pool;
}
}
#[cfg(not(feature = "private_api"))]
pub fn init_app() {}
#[cfg(target_os = "macos")]
#[cfg(feature = "private_api")]
pub fn run_forever() {
unsafe {
let cls = objc::runtime::Class::get("NSApplication").unwrap();
let app: *mut objc::runtime::Object = msg_send![cls, sharedApplication];
let _ = msg_send![app, run];
}
}
#[cfg(not(feature = "private_api"))]
pub fn run_forever() { loop {} }
pub fn quit() {
std::process::exit(0);
}
#[cfg(test)]
mod tests {
use Touchbar;
use interface::TouchbarTrait;
#[test]
fn test_alloc() {
let mut tb = Touchbar::alloc("test");
let _ = tb.create_bar();
tb.enable();
}
}