platform.rs

  1use crate::{
  2    AnyWindowHandle, BackgroundExecutor, CursorStyle, DisplayId, ForegroundExecutor, Platform,
  3    PlatformDisplay, PlatformTextSystem, TestDisplay, TestWindow, WindowOptions,
  4};
  5use anyhow::{anyhow, Result};
  6use parking_lot::Mutex;
  7use std::{rc::Rc, sync::Arc};
  8
  9pub struct TestPlatform {
 10    background_executor: BackgroundExecutor,
 11    foreground_executor: ForegroundExecutor,
 12
 13    active_window: Arc<Mutex<Option<AnyWindowHandle>>>,
 14    active_display: Rc<dyn PlatformDisplay>,
 15    active_cursor: Mutex<CursorStyle>,
 16}
 17
 18impl TestPlatform {
 19    pub fn new(executor: BackgroundExecutor, foreground_executor: ForegroundExecutor) -> Self {
 20        TestPlatform {
 21            background_executor: executor,
 22            foreground_executor,
 23
 24            active_cursor: Default::default(),
 25            active_display: Rc::new(TestDisplay::new()),
 26            active_window: Default::default(),
 27        }
 28    }
 29}
 30
 31// todo!("implement out what our tests needed in GPUI 1")
 32impl Platform for TestPlatform {
 33    fn background_executor(&self) -> BackgroundExecutor {
 34        self.background_executor.clone()
 35    }
 36
 37    fn foreground_executor(&self) -> ForegroundExecutor {
 38        self.foreground_executor.clone()
 39    }
 40
 41    fn text_system(&self) -> Arc<dyn PlatformTextSystem> {
 42        Arc::new(crate::platform::mac::MacTextSystem::new())
 43    }
 44
 45    fn run(&self, _on_finish_launching: Box<dyn FnOnce()>) {
 46        unimplemented!()
 47    }
 48
 49    fn quit(&self) {
 50        unimplemented!()
 51    }
 52
 53    fn restart(&self) {
 54        unimplemented!()
 55    }
 56
 57    fn activate(&self, _ignoring_other_apps: bool) {
 58        unimplemented!()
 59    }
 60
 61    fn hide(&self) {
 62        unimplemented!()
 63    }
 64
 65    fn hide_other_apps(&self) {
 66        unimplemented!()
 67    }
 68
 69    fn unhide_other_apps(&self) {
 70        unimplemented!()
 71    }
 72
 73    fn displays(&self) -> Vec<std::rc::Rc<dyn crate::PlatformDisplay>> {
 74        vec![self.active_display.clone()]
 75    }
 76
 77    fn display(&self, id: DisplayId) -> Option<std::rc::Rc<dyn crate::PlatformDisplay>> {
 78        self.displays().iter().find(|d| d.id() == id).cloned()
 79    }
 80
 81    fn main_window(&self) -> Option<crate::AnyWindowHandle> {
 82        unimplemented!()
 83    }
 84
 85    fn open_window(
 86        &self,
 87        handle: AnyWindowHandle,
 88        options: WindowOptions,
 89    ) -> Box<dyn crate::PlatformWindow> {
 90        *self.active_window.lock() = Some(handle);
 91        Box::new(TestWindow::new(options, self.active_display.clone()))
 92    }
 93
 94    fn set_display_link_output_callback(
 95        &self,
 96        _display_id: DisplayId,
 97        _callback: Box<dyn FnMut(&crate::VideoTimestamp, &crate::VideoTimestamp) + Send>,
 98    ) {
 99        unimplemented!()
100    }
101
102    fn start_display_link(&self, _display_id: DisplayId) {
103        unimplemented!()
104    }
105
106    fn stop_display_link(&self, _display_id: DisplayId) {
107        unimplemented!()
108    }
109
110    fn open_url(&self, _url: &str) {
111        unimplemented!()
112    }
113
114    fn on_open_urls(&self, _callback: Box<dyn FnMut(Vec<String>)>) {
115        unimplemented!()
116    }
117
118    fn prompt_for_paths(
119        &self,
120        _options: crate::PathPromptOptions,
121    ) -> futures::channel::oneshot::Receiver<Option<Vec<std::path::PathBuf>>> {
122        unimplemented!()
123    }
124
125    fn prompt_for_new_path(
126        &self,
127        _directory: &std::path::Path,
128    ) -> futures::channel::oneshot::Receiver<Option<std::path::PathBuf>> {
129        unimplemented!()
130    }
131
132    fn reveal_path(&self, _path: &std::path::Path) {
133        unimplemented!()
134    }
135
136    fn on_become_active(&self, _callback: Box<dyn FnMut()>) {
137        unimplemented!()
138    }
139
140    fn on_resign_active(&self, _callback: Box<dyn FnMut()>) {
141        unimplemented!()
142    }
143
144    fn on_quit(&self, _callback: Box<dyn FnMut()>) {
145        unimplemented!()
146    }
147
148    fn on_reopen(&self, _callback: Box<dyn FnMut()>) {
149        unimplemented!()
150    }
151
152    fn on_event(&self, _callback: Box<dyn FnMut(crate::InputEvent) -> bool>) {
153        unimplemented!()
154    }
155
156    fn os_name(&self) -> &'static str {
157        "test"
158    }
159
160    fn os_version(&self) -> Result<crate::SemanticVersion> {
161        Err(anyhow!("os_version called on TestPlatform"))
162    }
163
164    fn app_version(&self) -> Result<crate::SemanticVersion> {
165        Err(anyhow!("app_version called on TestPlatform"))
166    }
167
168    fn app_path(&self) -> Result<std::path::PathBuf> {
169        unimplemented!()
170    }
171
172    fn local_timezone(&self) -> time::UtcOffset {
173        unimplemented!()
174    }
175
176    fn path_for_auxiliary_executable(&self, _name: &str) -> Result<std::path::PathBuf> {
177        unimplemented!()
178    }
179
180    fn set_cursor_style(&self, style: crate::CursorStyle) {
181        *self.active_cursor.lock() = style;
182    }
183
184    fn should_auto_hide_scrollbars(&self) -> bool {
185        // todo()
186        true
187    }
188
189    fn write_to_clipboard(&self, _item: crate::ClipboardItem) {
190        unimplemented!()
191    }
192
193    fn read_from_clipboard(&self) -> Option<crate::ClipboardItem> {
194        unimplemented!()
195    }
196
197    fn write_credentials(&self, _url: &str, _username: &str, _password: &[u8]) -> Result<()> {
198        Ok(())
199    }
200
201    fn read_credentials(&self, _url: &str) -> Result<Option<(String, Vec<u8>)>> {
202        Ok(None)
203    }
204
205    fn delete_credentials(&self, _url: &str) -> Result<()> {
206        Ok(())
207    }
208}