Skip to content

Commit

Permalink
Merge pull request #1709 from h3poteto/feat/update-icon
Browse files Browse the repository at this point in the history
Update favicon when launching app
  • Loading branch information
h3poteto authored Dec 24, 2024
2 parents 5585ade + f823891 commit 2f9656a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src-tauri/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ pub(crate) async fn remove_server(pool: &SqlitePool, id: i64) -> DBResult<()> {
Ok(())
}

pub(crate) async fn update_server(pool: &SqlitePool, server: entities::Server) -> DBResult<()> {
let mut tx = pool.begin().await?;

sqlx::query("UPDATE servers SET domain = ?, base_url = ?, sns = ?, favicon = ? WHERE id = ?")
.bind(server.domain)
.bind(server.base_url)
.bind(server.sns)
.bind(server.favicon)
.bind(server.id)
.execute(&mut *tx)
.await?;

tx.commit().await?;

Ok(())
}

pub(crate) async fn add_account(
pool: &SqlitePool,
server: &entities::Server,
Expand Down
24 changes: 24 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,23 @@ async fn list_fonts() -> Result<Vec<String>, String> {
Ok(fonts)
}

async fn update_favicon(sqlite_pool: &sqlx::SqlitePool) -> Result<(), String> {
let servers = database::list_servers(sqlite_pool)
.await
.map_err(|e| e.to_string())?;
for (mut server, _) in servers {
let url = server.base_url.clone();
let icon = favicon::get_favicon_url(&url).await;
tracing::info!("The favicon for {} is {:#?}", &url, icon);
server.favicon = icon;
let _ = database::update_server(sqlite_pool, server)
.await
.map_err(|e| e.to_string())?;
}

Ok(())
}

async fn start_timeline_streaming(
app_handle: &AppHandle,
sqlite_pool: &sqlx::SqlitePool,
Expand Down Expand Up @@ -726,6 +743,13 @@ pub fn run() -> Result<(), Box<dyn std::error::Error>> {
});
}

{
let sqlite_pool = sqlite_pool.clone();
tauri::async_runtime::spawn(async move {
let _ = update_favicon(&sqlite_pool).await;
});
}

app.manage(sqlite_pool);
app.manage(Mutex::new(app_handle));

Expand Down

0 comments on commit 2f9656a

Please sign in to comment.