WIP: Get everything compiling again and keep window open

This commit is contained in:
Nathan Sobo
2021-03-19 12:12:10 -06:00
parent 605bdd62dd
commit cfe3aae2de
10 changed files with 316 additions and 319 deletions
+40 -64
View File
@@ -1,80 +1,43 @@
use fs::OpenOptions;
use gpui::{
executor,
geometry::{rect::RectF, vector::vec2f},
platform::{current as platform, App as _, Runner as _, WindowOptions},
FontCache,
};
use gpui::platform::{current as platform, Runner as _};
use log::LevelFilter;
use simplelog::SimpleLogger;
use std::{fs, mem, rc::Rc, sync::Arc};
use std::{fs, mem, path::PathBuf};
use zed::{
editor, settings,
assets, editor, settings,
workspace::{self, OpenParams},
};
fn main() {
init_logger();
let platform = Arc::new(platform::app());
let app = gpui::App::new(assets::Assets).unwrap();
let (_, settings_rx) = settings::channel(&app.fonts()).unwrap();
let foreground = Rc::new(
executor::Foreground::platform(platform.dispatcher())
.expect("could not foreground create executor"),
);
{
let mut app = app.clone();
platform::runner()
.on_finish_launching(move || {
workspace::init(&mut app);
editor::init(&mut app);
let font_cache = FontCache::new();
if stdout_is_a_pty() {
app.platform().activate(true);
}
let (settings_tx, settings_rx) = settings::channel(&font_cache).unwrap();
let mut app = gpui::App::new(As).unwrap();
platform::runner()
.on_finish_launching(move || {
log::info!("finish launching");
workspace::init(&mut app);
editor::init(&mut app);
if stdout_is_a_pty() {
platform.activate(true);
}
let paths = std::env::args()
.skip(1)
.filter_map(|arg| match fs::canonicalize(arg) {
Ok(path) => Some(path),
Err(error) => {
log::error!("error parsing path argument: {}", error);
None
}
})
.collect::<Vec<_>>();
if !paths.is_empty() {
app.dispatch_global_action(
"workspace:open_paths",
OpenParams {
paths,
settings: settings_rx,
},
);
mem::forget(app); // This is here until we hold on to the app for some reason
}
// let window = platform
// .open_window(
// WindowOptions {
// bounds: RectF::new(vec2f(0., 0.), vec2f(1024., 768.)),
// title: Some("Zed"),
// },
// foreground,
// )
// .expect("error opening window");
// mem::forget(window); // Leak window for now so it doesn't close
})
.run();
let paths = collect_path_args();
if !paths.is_empty() {
app.dispatch_global_action(
"workspace:open_paths",
OpenParams {
paths,
settings: settings_rx,
},
);
}
})
.run();
}
}
fn init_logger() {
@@ -101,3 +64,16 @@ fn init_logger() {
fn stdout_is_a_pty() -> bool {
unsafe { libc::isatty(libc::STDOUT_FILENO as i32) != 0 }
}
fn collect_path_args() -> Vec<PathBuf> {
std::env::args()
.skip(1)
.filter_map(|arg| match fs::canonicalize(arg) {
Ok(path) => Some(path),
Err(error) => {
log::error!("error parsing path argument: {}", error);
None
}
})
.collect::<Vec<_>>()
}