Revert "Remove borrow from reveal_path()"

This commit is contained in:
Mikayla Maki 2023-02-24 09:39:52 -08:00 committed by GitHub
parent 2ec25bef84
commit 8656708de4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 12 deletions

View File

@ -191,7 +191,7 @@ impl App {
pub fn new(asset_source: impl AssetSource) -> Result<Self> { pub fn new(asset_source: impl AssetSource) -> Result<Self> {
let platform = platform::current::platform(); let platform = platform::current::platform();
let foreground = Rc::new(executor::Foreground::platform(platform.dispatcher())?); let foreground = Rc::new(executor::Foreground::platform(platform.dispatcher())?);
let foreground_platform = platform::current::foreground_platform(); let foreground_platform = platform::current::foreground_platform(foreground.clone());
let app = Self(Rc::new(RefCell::new(MutableAppContext::new( let app = Self(Rc::new(RefCell::new(MutableAppContext::new(
foreground, foreground,
Arc::new(executor::Background::new()), Arc::new(executor::Background::new()),

View File

@ -23,12 +23,16 @@ pub use renderer::Surface;
use std::{ops::Range, rc::Rc, sync::Arc}; use std::{ops::Range, rc::Rc, sync::Arc};
use window::Window; use window::Window;
use crate::executor;
pub(crate) fn platform() -> Arc<dyn super::Platform> { pub(crate) fn platform() -> Arc<dyn super::Platform> {
Arc::new(MacPlatform::new()) Arc::new(MacPlatform::new())
} }
pub(crate) fn foreground_platform() -> Rc<dyn super::ForegroundPlatform> { pub(crate) fn foreground_platform(
Rc::new(MacForegroundPlatform::new()) foreground: Rc<executor::Foreground>,
) -> Rc<dyn super::ForegroundPlatform> {
Rc::new(MacForegroundPlatform::new(foreground))
} }
trait BoolExt { trait BoolExt {

View File

@ -152,10 +152,11 @@ pub struct MacForegroundPlatformState {
open_urls: Option<Box<dyn FnMut(Vec<String>)>>, open_urls: Option<Box<dyn FnMut(Vec<String>)>>,
finish_launching: Option<Box<dyn FnOnce()>>, finish_launching: Option<Box<dyn FnOnce()>>,
menu_actions: Vec<Box<dyn Action>>, menu_actions: Vec<Box<dyn Action>>,
foreground: Rc<executor::Foreground>,
} }
impl MacForegroundPlatform { impl MacForegroundPlatform {
pub fn new() -> Self { pub fn new(foreground: Rc<executor::Foreground>) -> Self {
Self(RefCell::new(MacForegroundPlatformState { Self(RefCell::new(MacForegroundPlatformState {
become_active: Default::default(), become_active: Default::default(),
resign_active: Default::default(), resign_active: Default::default(),
@ -167,6 +168,7 @@ impl MacForegroundPlatform {
open_urls: Default::default(), open_urls: Default::default(),
finish_launching: Default::default(), finish_launching: Default::default(),
menu_actions: Default::default(), menu_actions: Default::default(),
foreground,
})) }))
} }
@ -454,14 +456,21 @@ impl platform::ForegroundPlatform for MacForegroundPlatform {
fn reveal_path(&self, path: &Path) { fn reveal_path(&self, path: &Path) {
unsafe { unsafe {
let full_path = ns_string(path.to_str().unwrap_or("")); let path = path.to_path_buf();
let root_full_path = ns_string(""); self.0
let workspace: id = msg_send![class!(NSWorkspace), sharedWorkspace]; .borrow()
let _: BOOL = msg_send![ .foreground
workspace, .spawn(async move {
selectFile: full_path let full_path = ns_string(path.to_str().unwrap_or(""));
inFileViewerRootedAtPath: root_full_path let root_full_path = ns_string("");
]; let workspace: id = msg_send![class!(NSWorkspace), sharedWorkspace];
let _: BOOL = msg_send![
workspace,
selectFile: full_path
inFileViewerRootedAtPath: root_full_path
];
})
.detach();
} }
} }
} }