Skip to content

Commit

Permalink
bugfixes: use correct log directory + workaround migration warning (#126
Browse files Browse the repository at this point in the history
)

* bugfix: Point logs to the user selected data directory (if any)

* bugfix: workaround for issue where migrator sees an applied migration but doesn't detect the file
  • Loading branch information
a5huynh authored Jul 25, 2022
1 parent 42165b9 commit d520209
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
6 changes: 3 additions & 3 deletions crates/shared/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ impl Config {
self.data_dir().join("index")
}

pub fn logs_dir() -> PathBuf {
Self::default_data_dir().join("logs")
pub fn logs_dir(&self) -> PathBuf {
self.data_dir().join("logs")
}

pub fn prefs_dir() -> PathBuf {
Expand Down Expand Up @@ -276,7 +276,7 @@ impl Config {
let index_dir = config.index_dir();
fs::create_dir_all(&index_dir).expect("Unable to create index folder");

let logs_dir = Config::logs_dir();
let logs_dir = config.logs_dir();
fs::create_dir_all(&logs_dir).expect("Unable to create logs folder");

let lenses_dir = config.lenses_dir();
Expand Down
17 changes: 11 additions & 6 deletions crates/spyglass/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ mod api;
use crate::api::start_api_ipc;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let file_appender = tracing_appender::rolling::daily(Config::logs_dir(), "server.log");
let config = Config::new();
let file_appender = tracing_appender::rolling::daily(config.logs_dir(), "server.log");
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);

let subscriber = tracing_subscriber::registry()
Expand Down Expand Up @@ -53,10 +54,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
match rt.block_on(Migrator::up(&state.db, None)) {
Ok(_) => {}
Err(e) => {
// Ruh-oh something went wrong
log::error!("Unable to migrate database - {:?}", e);
// Exit from app
return Ok(());
let msg = e.to_string();
// This is ok, just the migrator being funky
if !msg.contains("been applied but its file is missing") {
// Ruh-oh something went wrong
log::error!("Unable to migrate database - {}", e.to_string());
// Exit from app
return Ok(());
}
}
}

Expand Down Expand Up @@ -173,5 +178,5 @@ async fn start_backend(state: &mut AppState, config: &Config) {
}
}

let _ = tokio::join!(manager_handle, worker_handle);
let _ = tokio::join!(manager_handle, worker_handle, pm_handle);
}
2 changes: 1 addition & 1 deletion crates/spyglass/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub async fn plugin_manager(
res = cmd_queue.recv() => res,
_ = interval.tick() => Some(PluginCommand::CheckForUpdate),
_ = shutdown_rx.recv() => {
log::info!("🛑 Shutting down worker");
log::info!("🛑 Shutting down plugin manager");
return;
}
};
Expand Down
12 changes: 7 additions & 5 deletions crates/tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use window::{show_crawl_stats_window, show_lens_manager_window, show_plugin_mana
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new();

let file_appender = tracing_appender::rolling::daily(Config::logs_dir(), "client.log");
let file_appender = tracing_appender::rolling::daily(config.logs_dir(), "client.log");
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);

let subscriber = tracing_subscriber::registry()
Expand All @@ -53,7 +53,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
LogTracer::init()?;

let ctx = tauri::generate_context!();

let config_copy = config.clone();
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
cmd::crawl_stats,
Expand All @@ -75,8 +75,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
cmd::toggle_plugin,
])
.menu(menu::get_app_menu(&ctx))
.system_tray(SystemTray::new().with_menu(menu::get_tray_menu(&ctx, &config)))
.system_tray(SystemTray::new().with_menu(menu::get_tray_menu(&ctx, &config.clone())))
.setup(move |app| {
let config = config_copy;
// Copy default plugins to data directory to be picked up by the backend
if let Err(e) = copy_plugins(&config, app.path_resolver()) {
log::error!("Unable to copy default plugins: {}", e);
Expand Down Expand Up @@ -158,7 +159,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
})
.on_system_tray_event(|app, event| {
.on_system_tray_event(move |app, event| {
let config = config.clone();
if let SystemTrayEvent::MenuItemClick { id, .. } = event {
let item_handle = app.tray_handle().get_item(&id);
let window = app.get_window("main").unwrap();
Expand All @@ -179,7 +181,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
MenuID::OPEN_LENS_MANAGER => { show_lens_manager_window(app); },
MenuID::OPEN_PLUGIN_MANAGER => { show_plugin_manager(app); },
MenuID::OPEN_LOGS_FOLDER => open_folder(Config::logs_dir()),
MenuID::OPEN_LOGS_FOLDER => open_folder(config.logs_dir()),
MenuID::OPEN_SETTINGS_FOLDER => open_folder(Config::prefs_dir()),
MenuID::SHOW_CRAWL_STATUS => {
show_crawl_stats_window(app);
Expand Down

0 comments on commit d520209

Please sign in to comment.