Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Remove the bleep plugin, use setup hook instead (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdy authored Aug 21, 2023
1 parent 80f10ab commit 3311f59
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 48 deletions.
56 changes: 10 additions & 46 deletions apps/desktop/src-tauri/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn get_device_id() -> String {
static SENTRY: OnceCell<ClientInitGuard> = OnceCell::new();

#[tauri::command]
fn get_last_log_file(config: tauri::State<Configuration>) -> Option<String> {
pub fn get_last_log_file(config: tauri::State<Configuration>) -> Option<String> {
let log_dir = config.log_dir();

let mut entries = std::fs::read_dir(log_dir)
Expand Down Expand Up @@ -52,57 +52,21 @@ fn get_last_log_file(config: tauri::State<Configuration>) -> Option<String> {
std::fs::read_to_string(filename).ok()
}

pub(super) struct BloopBackend<R>
where
R: Runtime,
{
invoke_handler: Box<dyn Fn(Invoke<R>) + Send + Sync>,
}

impl<R: Runtime> BloopBackend<R> {
pub fn new() -> Self {
Self {
invoke_handler: Box::new(tauri::generate_handler![get_last_log_file]),
}
}
}

impl<R: Runtime> Default for BloopBackend<R> {
fn default() -> Self {
Self::new()
}
}
pub fn initialize<R: Runtime>(app: &mut tauri::App<R>) -> tauri::plugin::Result<()> {
let handle = app.handle();
let configuration = setup_configuration(&handle);

impl<R: Runtime> Plugin<R> for BloopBackend<R> {
fn name(&self) -> &'static str {
"bleep"
}
Application::install_logging(&configuration);

/// Extend the invoke handler.
fn extend_api(&mut self, message: Invoke<R>) {
(self.invoke_handler)(message)
if let Some(dsn) = &configuration.sentry_dsn {
initialize_sentry(dsn);
}

fn initialize(
&mut self,
app: &tauri::AppHandle<R>,
_config: serde_json::Value,
) -> tauri::plugin::Result<()> {
let configuration = setup_configuration(app);
app.manage(configuration.clone());

Application::install_logging(&configuration);

if let Some(dsn) = &configuration.sentry_dsn {
initialize_sentry(dsn);
}
tokio::spawn(start_backend(configuration, handle));

app.manage(configuration.clone());

let app = app.clone();
tokio::spawn(start_backend(configuration, app));

Ok(())
}
Ok(())
}

async fn wait_for_qdrant() {
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ fn relative_command_path(command: impl AsRef<str>) -> Option<PathBuf> {
async fn main() {
tauri::Builder::default()
.plugin(qdrant::QdrantSupervisor::default())
.plugin(backend::BloopBackend::default())
.setup(backend::initialize)
.invoke_handler(tauri::generate_handler![
show_folder_in_finder,
enable_telemetry,
disable_telemetry,
backend::get_last_log_file,
])
.run(tauri::generate_context!())
.expect("error running tauri application");
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ReportBugModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const ReportBugModal = ({

useEffect(() => {
if (isBugReportModalOpen) {
invokeTauriCommand('plugin:bleep|get_last_log_file').then((log) => {
invokeTauriCommand('get_last_log_file').then((log) => {
setServerLog(log);
});
}
Expand Down

0 comments on commit 3311f59

Please sign in to comment.