- {domain}
+
diff --git a/crates/shared/src/rpc.rs b/crates/shared/src/rpc.rs
index e4d142e39..1860a7338 100644
--- a/crates/shared/src/rpc.rs
+++ b/crates/shared/src/rpc.rs
@@ -31,6 +31,9 @@ pub trait Rpc {
#[rpc(name = "list_installed_lenses")]
fn list_installed_lenses(&self) -> BoxFuture
>>;
+ #[rpc(name = "recrawl_domain")]
+ fn recrawl_domain(&self, domain: String) -> BoxFuture>;
+
#[rpc(name = "search_docs")]
fn search_docs(&self, query: SearchParam) -> BoxFuture>;
diff --git a/crates/spyglass/src/api/mod.rs b/crates/spyglass/src/api/mod.rs
index cac18a252..2a2ae2934 100644
--- a/crates/spyglass/src/api/mod.rs
+++ b/crates/spyglass/src/api/mod.rs
@@ -37,6 +37,10 @@ impl Rpc for SpyglassRPC {
Box::pin(route::list_installed_lenses(self.state.clone()))
}
+ fn recrawl_domain(&self, domain: String) -> BoxFuture> {
+ Box::pin(route::recrawl_domain(self.state.clone(), domain))
+ }
+
fn search_docs(&self, query: SearchParam) -> BoxFuture> {
Box::pin(route::search(self.state.clone(), query))
}
diff --git a/crates/spyglass/src/api/route.rs b/crates/spyglass/src/api/route.rs
index f1ef9b5e5..cf6ef18a0 100644
--- a/crates/spyglass/src/api/route.rs
+++ b/crates/spyglass/src/api/route.rs
@@ -1,19 +1,18 @@
use std::collections::HashMap;
-use entities::sea_orm::prelude::*;
-use entities::sea_orm::QueryOrder;
-use entities::sea_orm::Set;
+use entities::models::crawl_queue::CrawlStatus;
use jsonrpc_core::{Error, ErrorCode, Result};
-use shared::response::LensResult;
use tracing::instrument;
use url::Url;
use shared::request;
use shared::response::{
- AppStatus, CrawlStats, QueueStatus, SearchLensesResp, SearchMeta, SearchResult, SearchResults,
+ AppStatus, CrawlStats, LensResult, QueueStatus, SearchLensesResp, SearchMeta, SearchResult,
+ SearchResults,
};
use entities::models::{crawl_queue, indexed_document, lens};
+use entities::sea_orm::{prelude::*, sea_query, QueryOrder, Set};
use libspyglass::search::Searcher;
use libspyglass::state::AppState;
@@ -158,18 +157,27 @@ pub async fn list_queue(state: AppState) -> Result {
}
#[instrument(skip(state))]
-pub async fn toggle_pause(state: AppState) -> jsonrpc_core::Result {
- // Scope so that the app_state mutex is correctly released.
- {
- let app_state = &state.app_state;
- let mut paused_status = app_state.get_mut("paused").unwrap();
+pub async fn recrawl_domain(state: AppState, domain: String) -> Result<()> {
+ log::info!("handling recrawl domain: {}", domain);
+ let db = &state.db;
- let current_status = paused_status.to_string() == "true";
- let updated_status = !current_status;
- *paused_status = updated_status.to_string();
+ let res = crawl_queue::Entity::update_many()
+ .col_expr(
+ crawl_queue::Column::Status,
+ sea_query::Expr::value(sea_query::Value::String(Some(Box::new(
+ CrawlStatus::Queued.to_string(),
+ )))),
+ )
+ .filter(crawl_queue::Column::Domain.eq(domain.clone()))
+ .exec(db)
+ .await;
+
+ // Log out issues
+ if let Err(e) = res {
+ log::error!("Error recrawling domain {}: {}", domain, e);
}
- _get_current_status(state.clone()).await
+ Ok(())
}
/// Search the user's indexed documents
@@ -255,3 +263,18 @@ pub async fn search_lenses(
Ok(SearchLensesResp { results })
}
+
+#[instrument(skip(state))]
+pub async fn toggle_pause(state: AppState) -> jsonrpc_core::Result {
+ // Scope so that the app_state mutex is correctly released.
+ {
+ let app_state = &state.app_state;
+ let mut paused_status = app_state.get_mut("paused").unwrap();
+
+ let current_status = paused_status.to_string() == "true";
+ let updated_status = !current_status;
+ *paused_status = updated_status.to_string();
+ }
+
+ _get_current_status(state.clone()).await
+}
diff --git a/crates/tauri/Cargo.toml b/crates/tauri/Cargo.toml
index afc925c25..b6ba244bf 100644
--- a/crates/tauri/Cargo.toml
+++ b/crates/tauri/Cargo.toml
@@ -26,7 +26,7 @@ ron = "0.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
shared = { path = "../shared" }
-tauri = { version = "1.0.0", features = ["api-all", "devtools", "notification", "system-tray", "updater"] }
+tauri = { version = "1.0.2", features = ["api-all", "devtools", "notification", "system-tray", "updater"] }
tokio = "1"
tokio-retry = "0.3"
tracing = "0.1"
diff --git a/crates/tauri/src/cmd.rs b/crates/tauri/src/cmd.rs
index 1d907e146..83ba7eae7 100644
--- a/crates/tauri/src/cmd.rs
+++ b/crates/tauri/src/cmd.rs
@@ -234,3 +234,26 @@ pub async fn network_change(
Ok(())
}
+
+#[tauri::command]
+pub async fn recrawl_domain(
+ _: tauri::Window,
+ rpc: State<'_, rpc::RpcMutex>,
+ domain: &str,
+) -> Result<(), String> {
+ log::info!("recrawling {}", domain);
+ let mut rpc = rpc.lock().await;
+
+ match rpc
+ .client
+ .call_method::<(String,), ()>("recrawl_domain", "", (domain.into(),))
+ .await
+ {
+ Ok(_) => Ok(()),
+ Err(err) => {
+ log::error!("Error sending RPC: {}", err);
+ rpc.reconnect().await;
+ Ok(())
+ }
+ }
+}
diff --git a/crates/tauri/src/constants.rs b/crates/tauri/src/constants.rs
index d132111bc..bf07ab233 100644
--- a/crates/tauri/src/constants.rs
+++ b/crates/tauri/src/constants.rs
@@ -1,11 +1,13 @@
pub const INPUT_WIDTH: f64 = 640.0;
pub const INPUT_Y: f64 = 128.0;
+// Check for a new version every 6 hours. 60 seconds * 60 minutes * 6 hours
+pub const VERSION_CHECK_INTERVAL_S: u64 = 60 * 60 * 6;
+
pub const APP_USER_AGENT: &str = "spyglass (github.com/a5huynh/spyglass)";
pub const DISCORD_JOIN_URL: &str = "https://discord.gg/663wPVBSTB";
pub const LENS_DIRECTORY_INDEX_URL: &str =
"https://raw.githubusercontent.com/spyglass-search/lens-box/main/index.ron";
-pub const VERSION_CHECK_URL: &str = "https://api.github.com/repos/a5huynh/spyglass/releases";
pub const STATS_WIN_NAME: &str = "crawl_stats";
pub const LENS_MANAGER_WIN_NAME: &str = "lens_manager";
diff --git a/crates/tauri/src/main.rs b/crates/tauri/src/main.rs
index d6d2bbbb5..0a0a5d837 100644
--- a/crates/tauri/src/main.rs
+++ b/crates/tauri/src/main.rs
@@ -6,15 +6,13 @@
use std::io;
use std::path::PathBuf;
use std::sync::Arc;
-use std::time::Duration;
use jsonrpc_core::Value;
use num_format::{Locale, ToFormattedString};
use rpc::RpcMutex;
-use serde::Deserialize;
-use tauri::{AppHandle, GlobalShortcutManager, Manager, SystemTray, SystemTrayEvent};
+use tauri::{AppHandle, GlobalShortcutManager, Manager, SystemTray, SystemTrayEvent, Window};
use tokio::sync::Mutex;
-use tokio::time;
+use tokio::{time, time::Duration};
use tracing_log::LogTracer;
use tracing_subscriber::{fmt, layer::SubscriberExt, EnvFilter};
@@ -51,7 +49,6 @@ fn main() -> Result<(), Box> {
LogTracer::init()?;
let ctx = tauri::generate_context!();
- let app_version = format!("v20{}", ctx.package_info().version);
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
@@ -64,12 +61,13 @@ fn main() -> Result<(), Box> {
cmd::network_change,
cmd::open_lens_folder,
cmd::open_result,
+ cmd::recrawl_domain,
cmd::resize_window,
cmd::search_docs,
cmd::search_lenses,
])
- .menu(menu::get_app_menu())
- .system_tray(SystemTray::new().with_menu(menu::get_tray_menu(&config)))
+ .menu(menu::get_app_menu(&ctx))
+ .system_tray(SystemTray::new().with_menu(menu::get_tray_menu(&ctx, &config)))
.setup(move |app| {
// macOS: hide from dock (also hides menu bar)
#[cfg(target_os = "macos")]
@@ -91,21 +89,9 @@ fn main() -> Result<(), Box> {
}
}
- // Check the release version against app version
- match tauri::async_runtime::block_on(check_version()) {
- Ok(release_ver) => {
- if release_ver.tag_name > app_version {
- // Update menu item
- let tray = app.tray_handle();
- let version_item = tray.get_item(menu::VERSION_MENU_ITEM);
-
- let _ = version_item.set_enabled(true);
- let _ = version_item.set_title("🎉 Update available!");
- app.manage(release_ver);
- }
- }
- Err(e) => log::error!("Unable to check version: {}", e),
- }
+ // Spawn a version checking background task. Check every couple hours
+ // for a new version.
+ tauri::async_runtime::spawn(check_version_interval(window.clone()));
// Wait for the server to boot up
let rpc = tauri::async_runtime::block_on(rpc::RpcClient::new());
@@ -176,11 +162,6 @@ fn main() -> Result<(), Box> {
item_handle.set_title(new_label).unwrap();
}
- menu::VERSION_MENU_ITEM => {
- if let Some(version) = app.try_state::() {
- let _ = open::that(&version.html_url);
- }
- }
menu::OPEN_LENS_MANAGER => {
show_lens_manager_window(app);
}
@@ -284,31 +265,12 @@ async fn update_tray_menu(app: &AppHandle) {
}
}
-#[derive(Clone, Deserialize)]
-pub struct ReleaseVersion {
- html_url: String,
- tag_name: String,
-}
-
-async fn check_version() -> anyhow::Result {
- let client = reqwest::Client::builder()
- .user_agent(constants::APP_USER_AGENT)
- .build()?;
-
- let res = client
- .get(constants::VERSION_CHECK_URL)
- .send()
- .await?
- .json::>()
- .await?;
-
- if res.is_empty() {
- return Err(anyhow::Error::msg("Empty version array"));
+async fn check_version_interval(window: Window) {
+ let mut interval =
+ tokio::time::interval(Duration::from_secs(constants::VERSION_CHECK_INTERVAL_S));
+ loop {
+ interval.tick().await;
+ log::info!("checking for update...");
+ window.trigger_global("tauri://update", None);
}
-
- let latest = res
- .first()
- .expect("Version array shouldn't be empty")
- .to_owned();
- Ok(latest)
}
diff --git a/crates/tauri/src/menu.rs b/crates/tauri/src/menu.rs
index 5d682386a..2ab181cfc 100644
--- a/crates/tauri/src/menu.rs
+++ b/crates/tauri/src/menu.rs
@@ -1,5 +1,8 @@
use shared::config::Config;
-use tauri::{CustomMenuItem, Menu, MenuItem, Submenu, SystemTrayMenu, SystemTrayMenuItem};
+use tauri::{
+ utils::assets::EmbeddedAssets, Context, CustomMenuItem, Menu, MenuItem, Submenu,
+ SystemTrayMenu, SystemTrayMenuItem,
+};
pub const VERSION_MENU_ITEM: &str = "version";
pub const QUIT_MENU_ITEM: &str = "quit";
@@ -16,9 +19,7 @@ pub const JOIN_DISCORD: &str = "join_discord";
pub const DEV_SHOW_CONSOLE: &str = "dev_show_console";
-pub fn get_tray_menu(config: &Config) -> SystemTrayMenu {
- let ctx = tauri::generate_context!();
-
+pub fn get_tray_menu(ctx: &Context, config: &Config) -> SystemTrayMenu {
let show = CustomMenuItem::new(SHOW_SEARCHBAR.to_string(), "Show search")
.accelerator(config.user_settings.shortcut.clone());
@@ -65,13 +66,11 @@ pub fn get_tray_menu(config: &Config) -> SystemTrayMenu {
.add_item(quit)
}
-pub fn get_app_menu() -> Menu {
+pub fn get_app_menu(ctx: &Context) -> Menu {
if cfg!(target_os = "linux") {
return Menu::new();
}
- let ctx = tauri::generate_context!();
-
Menu::new().add_submenu(Submenu::new(
&ctx.package_info().name,
Menu::new()
diff --git a/crates/tauri/tauri.conf.json b/crates/tauri/tauri.conf.json
index f7f9c0aed..329facd7d 100644
--- a/crates/tauri/tauri.conf.json
+++ b/crates/tauri/tauri.conf.json
@@ -1,7 +1,7 @@
{
"package": {
"productName": "Spyglass",
- "version": "22.6.5"
+ "version": "22.7.1"
},
"build": {
"distDir": "../client/dist",
@@ -48,6 +48,7 @@
"updater": {
"active": true,
"endpoints": [
+ "https://spyglass-update-check.spyglass.workers.dev",
"https://raw.githubusercontent.com/a5huynh/spyglass/main/VERSION.json"
],
"dialog": true,