Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
a5huynh committed Jan 25, 2023
2 parents 2eefb77 + 4e1ea71 commit c6184ea
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 21 deletions.
2 changes: 1 addition & 1 deletion assets/plugins/local-file-indexer/manifest.ron
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
),
"EXTS_LIST": (
label: "File Types",
value: "[\"md\", \"txt\"]",
value: "[\"docx\", \"html\", \"md\", \"txt\", \"ods\", \"xls\", \"xlsx\"]",
form_type: StringList,
help_text: Some("List of supported file types that will be indexed.")
)
Expand Down
2 changes: 1 addition & 1 deletion crates/client/public/main.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/client/src/pages/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn settings_page(props: &SettingsPageProps) -> Html {
});

html! {
<div class="text-white flex">
<div class="text-white flex h-screen">
<div class="flex-col w-48 min-w-max bg-stone-900 p-4 top-0 left-0 z-40 sticky h-screen">
<div class="mb-6">
<div class="uppercase mb-2 text-xs text-gray-500 font-bold">
Expand Down
11 changes: 9 additions & 2 deletions crates/client/src/pages/wizard/menubar_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@ use yew::prelude::*;
/// Confused about where the tray icon is?
#[function_component(MenubarHelpPage)]
pub fn menubar_help() -> Html {
let (example_img, menubar_name) = match get_os() {
let os = get_os();

let (example_img, menubar_name) = match os {
OsName::Linux | OsName::MacOS | OsName::Unknown => ("macos-menubar-example.svg", "menubar"),
OsName::Windows => ("windows-menubar-example.svg", "system tray"),
};

let click_str = match os {
OsName::MacOS => "Left click",
_ => "Right click",
};

html! {
<div class="my-auto">
<img src={example_img} alt="Location of the menubar menu" class="h-[128px] mx-auto my-6"/>
<div class="font-bold text-lg">{format!("Spyglass lives in your {}.", menubar_name)}</div>
<div class="text-sm text-neutral-400 px-8">
{"Click on the icon to access your library, discover new lenses, and adjust your settings."}
{format!("{click_str} on the icon to access your library, discover new lenses, and adjust your settings.")}
</div>
</div>
}
Expand Down
10 changes: 5 additions & 5 deletions crates/client/src/pages/wizard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn wizard_page(props: &WizardProps) -> Html {
nav_clone.push(&Route::Wizard { stage: next_stage });
});

let tfi_state = toggle_file_indexer;
let tfi_state = toggle_file_indexer.clone();
let handle_onchange = Callback::from(move |event: SettingChangeEvent| {
if let Ok(new_value) = serde_json::from_str::<bool>(&event.new_value) {
tfi_state.set(new_value);
Expand All @@ -78,15 +78,15 @@ pub fn wizard_page(props: &WizardProps) -> Html {
html! { <menubar_help::MenubarHelpPage /> }
}
WizardStage::DisplaySearchbarHelp => {
next_label = "Indexing files, web content, & more".into();
next_label = "Create your library".into();
html! { <display_searchbar::DisplaySearchbarPage /> }
}
WizardStage::IndexFiles => {
next_label = "Indexing Cloud Accounts".into();
html! { <indexing_help::IndexFilesHelp onchange={handle_onchange} /> }
next_label = "Connect your cloud".into();
html! { <indexing_help::IndexFilesHelp toggle_file_indexer={*toggle_file_indexer} onchange={handle_onchange} /> }
}
WizardStage::IndexCloud => {
next_label = "Indexing Web Content".into();
next_label = "Add web content".into();
html! { <indexing_help::IndexCloudHelp /> }
}
WizardStage::IndexWeb => {
Expand Down
2 changes: 1 addition & 1 deletion crates/shared/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct UserSettings {
pub inflight_crawl_limit: Limit,
/// Number of in-flight crawls allowed per domain.
pub inflight_domain_limit: Limit,
/// Have we run the wizard?
/// Have we run the wizard? false will run it again on startup.
pub run_wizard: bool,
/// Domains explicitly allowed, regardless of what's in the blocklist.
pub allow_list: Vec<String>,
Expand Down
14 changes: 14 additions & 0 deletions crates/shared/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;

use crate::config::UserSettings;
use crate::form::SettingOpts;

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
Expand Down Expand Up @@ -40,4 +41,17 @@ impl PluginConfig {
.expect("Unable to find parent plugin directory")
.join("data")
}

/// Update the plugin config based on user settings
pub fn set_user_config(&mut self, user_settings: &UserSettings) {
let plugin_user_settings = &user_settings.plugin_settings;
if let Some(settings) = plugin_user_settings.get(&self.name) {
// Loop through plugin settings and use any user overrides found.
for (key, setting) in self.user_settings.iter_mut() {
if let Some(value) = settings.get(key) {
setting.value = value.to_string();
}
}
}
}
}
5 changes: 5 additions & 0 deletions crates/spyglass/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ pub async fn plugin_event_loop(
let manager = state.plugin_manager.lock().await;
if let Some(plugin) = manager.find_by_name(plugin_name) {
if let Some(mut instance) = manager.plugins.get_mut(&plugin.id) {
// Reload configuration for this plugin & initialize.
if let Ok(user_settings) = Config::load_user_settings() {
config.user_settings = user_settings;
instance.config.set_user_config(&config.user_settings);
}
instance.config.is_enabled = true;
// Re-initialize plugin
let _ = cmd_writer
Expand Down
9 changes: 7 additions & 2 deletions crates/tauri/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use tauri::api::dialog::FileDialogBuilder;
use tauri::Manager;
use tauri::State;

use crate::window::show_discover_window;
use crate::PauseState;
use crate::{open_folder, rpc, window};
use shared::config::Config;
Expand Down Expand Up @@ -346,12 +347,14 @@ pub async fn wizard_finished(
toggle_file_indexer: bool,
) -> Result<(), String> {
let plugin_name = "local-file-importer";
let mut current_settings = config.user_settings.clone();
current_settings.run_wizard = true;

// Only do this is we're enabling the plugin.
if toggle_file_indexer {
let field = "FOLDERS_LIST";

// TODO: Make this waaaay less involved to get & update a single field.
let mut current_settings = config.user_settings.clone();
let plugin_configs = config.load_plugin_config();
// Load the plugin configuration, grab the default paths & add to the plugin config.
let to_update = current_settings
Expand Down Expand Up @@ -381,19 +384,21 @@ pub async fn wizard_finished(
if let Ok(val) = field_opts.form_type.validate(&paths) {
log::debug!("Updating {}.{} w/ {}", plugin_name, field, val);
to_update.insert(field.into(), val);
let _ = config.save_user_settings(&current_settings);
}
}
}
}
}

// Save any updated settings based on onboarding flow.
let _ = config.save_user_settings(&current_settings);
// Turn on/off the plugin based on the user prefs.
let _ = toggle_plugin(win.clone(), plugin_name, toggle_file_indexer).await;

// close wizard window
if let Some(window) = win.get_window(crate::constants::WIZARD_WIN_NAME) {
let _ = window.close();
show_discover_window(&window.app_handle());
}

Ok(())
Expand Down
4 changes: 0 additions & 4 deletions crates/tauri/src/plugins/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,5 @@ async fn run_and_check_backend(app_handle: AppHandle) {
// Run wizard on first run
if !config.user_settings.run_wizard {
show_wizard_window(&window.app_handle());
// Only run the wizard once.
let mut updated = config.user_settings.clone();
updated.run_wizard = true;
let _ = config.save_user_settings(&updated);
}
}
5 changes: 1 addition & 4 deletions crates/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ pub async fn resize_window(window: &Window, height: f64) {

fn show_window(window: &Window) {
let _ = window.show();
// A little hack to bring window to the front if its hiding behind something.
let _ = window.set_always_on_top(true);
let _ = window.set_always_on_top(false);
let _ = window.set_focus();
let _ = window.center();
}
Expand Down Expand Up @@ -217,7 +214,7 @@ pub fn show_wizard_window(app: &AppHandle) {
constants::WIZARD_WIN_NAME,
WindowUrl::App("/wizard".into()),
)
.title("Getting Started w/ Spyglass")
.title("Getting Started")
.menu(Menu::new())
.min_inner_size(400.0, 492.0)
.max_inner_size(400.0, 492.0)
Expand Down

0 comments on commit c6184ea

Please sign in to comment.