feat(main): if given file path as argument use it
- if existing file then populate default file with that file's state - if non-existing file create it and populate default file with that file
This commit is contained in:
+16
-1
@@ -37,7 +37,22 @@ fn boot() -> (State, Task<Message>) {
|
||||
..window::Settings::default()
|
||||
});
|
||||
|
||||
(state::State::new(id), open.map(Message::WindowOpened))
|
||||
let mut state = state::State::new(id);
|
||||
let mut tasks = vec![open.map(Message::WindowOpened)];
|
||||
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
|
||||
if args.len() > 1 {
|
||||
let path = std::path::PathBuf::from(&args[1]);
|
||||
|
||||
state.set_active_file_path(path.clone());
|
||||
|
||||
if path.exists() {
|
||||
tasks.push(Task::perform(io::load_file(path), Message::FileOpened));
|
||||
}
|
||||
}
|
||||
|
||||
(state, Task::batch(tasks))
|
||||
}
|
||||
|
||||
fn update(state: &mut State, message: Message) -> Task<Message> {
|
||||
|
||||
Reference in New Issue
Block a user