Move App creation into its impl

This commit is contained in:
Sofía Aritz 2023-02-27 18:57:20 +01:00
parent e839770c9a
commit 19fe7a4ef5

View file

@ -10,7 +10,7 @@ use std::collections::{VecDeque};
use std::fs; use std::fs;
use std::time::SystemTime; use std::time::SystemTime;
use directories::ProjectDirs; use directories::ProjectDirs;
use eframe::Frame; use eframe::{CreationContext, Frame};
use egui::{Context, RichText, TextEdit, Widget}; use egui::{Context, RichText, TextEdit, Widget};
use log::info; use log::info;
use simple_logger::SimpleLogger; use simple_logger::SimpleLogger;
@ -41,6 +41,24 @@ struct App {
text_buffer: String, text_buffer: String,
} }
impl App {
fn new(_cc: &CreationContext<'_>, notes: Vec<Note>, saving: Saving) -> Self {
Self {
password: None,
update_notes_next: false,
tested_password: false,
notes,
mode: CurrentMode::PasswordInput,
saving,
password_buffer: String::new(),
title_buffer: String::new(),
text_buffer: String::new(),
}
}
}
fn main() { fn main() {
SimpleLogger::new().init().expect("failed to initialize logger"); SimpleLogger::new().init().expect("failed to initialize logger");
@ -65,24 +83,10 @@ fn main() {
let notes = saving.read_notes().unwrap(); let notes = saving.read_notes().unwrap();
info!("successfully read initial notes"); info!("successfully read initial notes");
let app = App {
password: None,
update_notes_next: false,
tested_password: false,
notes,
mode: CurrentMode::PasswordInput,
saving,
password_buffer: String::new(),
title_buffer: String::new(),
text_buffer: String::new(),
};
eframe::run_native( eframe::run_native(
"notes", "notes",
options, options,
Box::new(move |_cc| Box::new(app)) Box::new(move |cc| Box::new(App::new(cc, notes, saving)))
).expect("failed to run native"); ).expect("failed to run native");
info!("shutdown"); info!("shutdown");