Fix two time run
This commit is contained in:
parent
10afc750e8
commit
e719535d2a
15
src/main.rs
15
src/main.rs
@ -40,14 +40,17 @@ fn main() {
|
||||
fn activate(app: >k::Application) {
|
||||
ui::UI.with(|ui_cell| {
|
||||
let mut ui = ui_cell.borrow_mut();
|
||||
ui.init(app);
|
||||
if !ui.initialized {
|
||||
ui.init(app);
|
||||
|
||||
let path = nvim_bin_path(std::env::args());
|
||||
let open_arg = open_arg();
|
||||
nvim::initialize(&mut *ui, path.as_ref(), open_arg.as_ref())
|
||||
.expect("Can't start nvim instance");
|
||||
let path = nvim_bin_path(std::env::args());
|
||||
nvim::initialize(&mut *ui, path.as_ref())
|
||||
.expect("Can't start nvim instance");
|
||||
|
||||
guard_dispatch_thread(&mut *ui);
|
||||
guard_dispatch_thread(&mut *ui);
|
||||
}
|
||||
|
||||
nvim::open_file(ui.nvim(), open_arg().as_ref());
|
||||
});
|
||||
}
|
||||
|
||||
|
13
src/nvim.rs
13
src/nvim.rs
@ -65,8 +65,7 @@ macro_rules! try_uint {
|
||||
}
|
||||
|
||||
pub fn initialize(ui: &mut Ui,
|
||||
nvim_bin_path: Option<&String>,
|
||||
open_arg: Option<&String>)
|
||||
nvim_bin_path: Option<&String>)
|
||||
-> Result<()> {
|
||||
let session = if let Some(path) = nvim_bin_path {
|
||||
Session::new_child_path(path)?
|
||||
@ -84,13 +83,15 @@ pub fn initialize(ui: &mut Ui,
|
||||
nvim.ui_attach(80, 24, UiAttachOptions::new()).map_err(|e| Error::new(ErrorKind::Other, e))?;
|
||||
nvim.command("runtime! ginit.vim").map_err(|e| Error::new(ErrorKind::Other, e))?;
|
||||
|
||||
if let Some(ref file) = open_arg {
|
||||
nvim.command(&format!("e {}", file)).report_err(nvim);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn open_file(nvim: &mut NeovimApi, file: Option<&String>) {
|
||||
if let Some(file_name) = file {
|
||||
nvim.command(&format!("e {}", file_name)).report_err(nvim);
|
||||
}
|
||||
}
|
||||
|
||||
fn nvim_cb(method: &str, params: Vec<Value>) {
|
||||
match method {
|
||||
"redraw" => {
|
||||
|
@ -46,6 +46,7 @@ enum NvimMode {
|
||||
|
||||
pub struct Ui {
|
||||
pub model: UiModel,
|
||||
pub initialized: bool,
|
||||
nvim: Option<Neovim>,
|
||||
drawing_area: DrawingArea,
|
||||
window: Option<ApplicationWindow>,
|
||||
@ -82,6 +83,7 @@ impl Ui {
|
||||
mouse_enabled: false,
|
||||
mouse_pressed: false,
|
||||
font_desc: FontDescription::from_string(FONT_NAME),
|
||||
initialized: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,6 +100,11 @@ impl Ui {
|
||||
}
|
||||
|
||||
pub fn init(&mut self, app: >k::Application) {
|
||||
if self.initialized {
|
||||
return
|
||||
}
|
||||
self.initialized = true;
|
||||
|
||||
SET.with(|settings| {
|
||||
let mut settings = settings.borrow_mut();
|
||||
settings.init(self);
|
||||
|
Loading…
Reference in New Issue
Block a user