pub unsafe fn shared_app() -> *mut c_voidExpand description
[NSApplication sharedApplication], pinned to the light appearance so that
rendering does not depend on the host’s system setting.
§Safety
AppKit must be loaded and this must run on the main thread, as every
NSApplication call must.
Examples found in repository?
examples/scenes.rs (line 237)
235 unsafe extern "C" fn inspect(_: *mut c_void) {
236 unsafe {
237 let app = objc::shared_app();
238
239 let windows = objc::send(app, objc::sel(c"windows"));
240 let n = count(windows);
241 println!("windows: {n}");
242 for i in 0..n {
243 let w = at(windows, i);
244 let title = text(objc::send(w, objc::sel(c"title")));
245 let visible = objc::send_ret_bool(w, objc::sel(c"isVisible"));
246 let class = objc::send(w, objc::sel(c"class"));
247 let kind = text(objc::send(class, objc::sel(c"description")));
248 println!(" {kind:<24} visible={visible:<5} {title:?}");
249 }
250
251 let menu = objc::send(app, objc::sel(c"mainMenu"));
252 let items = objc::send(menu, objc::sel(c"itemArray"));
253 let n = count(items);
254 println!("menu bar: {n} menus");
255 for i in 0..n {
256 let item = at(items, i);
257 let title = text(objc::send(item, objc::sel(c"title")));
258 let sub = objc::send(item, objc::sel(c"submenu"));
259 let kids = objc::send(sub, objc::sel(c"itemArray"));
260 let entries: Vec<String> = (0..count(kids))
261 .map(|j| text(objc::send(at(kids, j), objc::sel(c"title"))))
262 .filter(|t| !t.is_empty())
263 .collect();
264 println!(" {title:?}: {}", entries.join(" · "));
265 }
266
267 // The menu-bar extra is an `NSStatusItem`, not a window or a menu,
268 // so it is counted separately or it would look like nothing was
269 // built for it.
270 let bar = objc::class(c"OBJC_CLASS_$_NSStatusBar");
271 let system = objc::send(bar, objc::sel(c"systemStatusBar"));
272 println!(
273 "status bar thickness: {}",
274 objc::send_ret_f64(system, objc::sel(c"thickness")),
275 );
276
277 std::process::exit(0);
278 }
279 }