Notification Panel (#200)

* feat: add tauri nspanel

* feat: add notification panel

* feat: move notification service to backend

* feat: add sync notification job

* feat: enable panel to join all spaces including fullscreen (#203)

* feat: fetch notification

* feat: listen for new notification

* feat: finish panel

---------

Co-authored-by: Victor Aremu <me@victorare.mu>
This commit is contained in:
雨宮蓮
2024-06-06 14:32:30 +07:00
committed by GitHub
parent 4e7da4108b
commit 799835a629
25 changed files with 1006 additions and 977 deletions

View File

@@ -4,8 +4,8 @@
)]
pub mod commands;
pub mod fns;
pub mod nostr;
pub mod tray;
#[cfg(target_os = "macos")]
extern crate cocoa;
@@ -17,8 +17,18 @@ extern crate objc;
use nostr_sdk::prelude::*;
use std::fs;
use tauri::Manager;
use tauri_nspanel::ManagerExt;
use tauri_plugin_decorum::WebviewWindowExt;
#[cfg(target_os = "macos")]
use crate::fns::{
position_menubar_panel, setup_menubar_panel_listeners, swizzle_to_menubar_panel,
update_menubar_appearance,
};
#[cfg(target_os = "macos")]
use tauri::tray::{MouseButtonState, TrayIconEvent};
pub struct Nostr {
client: Client,
}
@@ -39,7 +49,6 @@ fn main() {
nostr::keys::event_to_bech32,
nostr::keys::user_to_bech32,
nostr::keys::verify_nip05,
nostr::metadata::get_activities,
nostr::metadata::get_current_user_profile,
nostr::metadata::get_profile,
nostr::metadata::get_contact_list,
@@ -55,6 +64,7 @@ fn main() {
nostr::metadata::zap_profile,
nostr::metadata::zap_event,
nostr::metadata::friend_to_friend,
nostr::metadata::get_notifications,
nostr::event::get_event,
nostr::event::get_replies,
nostr::event::get_events_by,
@@ -90,25 +100,45 @@ fn main() {
#[cfg(target_os = "macos")]
main_window.set_traffic_lights_inset(8.0, 16.0).unwrap();
// Setup app tray
let handle = app.handle().clone();
tray::create_tray(app.handle()).unwrap();
// Create panel
#[cfg(target_os = "macos")]
swizzle_to_menubar_panel(&app.handle());
#[cfg(target_os = "macos")]
update_menubar_appearance(&app.handle());
#[cfg(target_os = "macos")]
setup_menubar_panel_listeners(&app.handle());
// Setup tray icon
#[cfg(target_os = "macos")]
let tray = app.tray_by_id("tray_panel").unwrap();
// Handle tray icon event
#[cfg(target_os = "macos")]
tray.on_tray_icon_event(|tray, event| match event {
TrayIconEvent::Click { button_state, .. } => {
if button_state == MouseButtonState::Up {
let app = tray.app_handle();
let panel = app.get_webview_panel("panel").unwrap();
match panel.is_visible() {
true => panel.order_out(None),
false => {
position_menubar_panel(&app, 0.0);
panel.show();
}
}
}
}
_ => {}
});
// Create data folder if not exist
let home_dir = app.path().home_dir().unwrap();
let _ = fs::create_dir_all(home_dir.join("Lume/"));
tauri::async_runtime::block_on(async move {
// Create nostr database connection
let db_path = home_dir.join(&"Lume/database");
#[cfg(target_family = "unix")]
let database = NdbDatabase::open(db_path.to_str().unwrap());
#[cfg(target_os = "windows")]
let database = RocksDatabase::open(db_path.to_str().unwrap()).await;
// Create nostr connection
let database = SQLiteDatabase::open(home_dir.join("Lume/lume.db")).await;
let client = match database {
Ok(db) => ClientBuilder::default().database(db).build(),
Err(_) => ClientBuilder::default().build(),
@@ -135,11 +165,12 @@ fn main() {
client.connect().await;
// Update global state
handle.manage(Nostr { client })
app.handle().manage(Nostr { client })
});
Ok(())
})
.plugin(tauri_nspanel::init())
.plugin(tauri_plugin_theme::init(ctx.config_mut()))
.plugin(tauri_plugin_decorum::init())
.plugin(tauri_plugin_clipboard_manager::init())