feat: add discord rich presence editor window and interactive embed preview
This commit is contained in:
1 parent
e3abea8d83
commit
386c829455
30 files changed
+4102
-263
No files matched your search
@@ -1087,6 +1087,35 @@ pub struct PresenceButton {
|
||||
url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PresenceActivityPayload {
|
||||
pub state: Option<String>,
|
||||
pub details: Option<String>,
|
||||
pub large_image_key: Option<String>,
|
||||
pub large_image_text: Option<String>,
|
||||
pub small_image_key: Option<Option<String>>,
|
||||
pub small_image_text: Option<Option<String>>,
|
||||
pub button1: Option<Option<presence::PresenceButton>>,
|
||||
pub button2: Option<Option<presence::PresenceButton>>,
|
||||
pub show_timestamp: Option<bool>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn presence_update_activity(activity: PresenceActivityPayload) {
|
||||
presence::update_activity(
|
||||
activity.state.as_deref(),
|
||||
activity.details.as_deref(),
|
||||
activity.large_image_key.as_deref(),
|
||||
activity.large_image_text.as_deref(),
|
||||
activity.small_image_key,
|
||||
activity.small_image_text,
|
||||
activity.button1,
|
||||
activity.button2,
|
||||
activity.show_timestamp,
|
||||
);
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn presence_update_button(button: PresenceButton) {
|
||||
match (button.text.as_deref(), button.url.as_deref()) {
|
||||
@@ -2168,6 +2197,9 @@ pub async fn open_theme_editor(app: AppHandle, theme_folder: Option<String>) ->
|
||||
let _ = window.unminimize();
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
if let Some(main) = app.get_webview_window("main") {
|
||||
let _ = main.hide();
|
||||
}
|
||||
app.emit_to("theme-editor", "theme-editor-context", ())
|
||||
.map_err(|error| error.to_string())?;
|
||||
let _ = app.emit_to("main", "theme-editor-state", true);
|
||||
@@ -2194,14 +2226,125 @@ pub async fn open_theme_editor(app: AppHandle, theme_folder: Option<String>) ->
|
||||
let main_window = app.clone();
|
||||
window.on_window_event(move |event| {
|
||||
if matches!(event, WindowEvent::Destroyed) {
|
||||
if let Some(main) = main_window.get_webview_window("main") {
|
||||
let _ = main.show();
|
||||
let _ = main.unminimize();
|
||||
let _ = main.set_focus();
|
||||
}
|
||||
let _ = main_window.emit_to("main", "theme-editor-state", false);
|
||||
}
|
||||
});
|
||||
|
||||
if let Some(main) = app.get_webview_window("main") {
|
||||
let _ = main.hide();
|
||||
}
|
||||
let _ = app.emit_to("main", "theme-editor-state", true);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Focus the theme editor window and keep the main launcher window hidden.
|
||||
#[tauri::command]
|
||||
pub async fn focus_theme_editor(app: AppHandle) -> Result<(), String> {
|
||||
if let Some(window) = app.get_webview_window("theme-editor") {
|
||||
let _ = window.unminimize();
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
if let Some(main) = app.get_webview_window("main") {
|
||||
let _ = main.hide();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Close the theme editor window and restore the main launcher window.
|
||||
#[tauri::command]
|
||||
pub async fn close_theme_editor(app: AppHandle) -> Result<(), String> {
|
||||
if let Some(window) = app.get_webview_window("theme-editor") {
|
||||
let _ = window.close();
|
||||
}
|
||||
if let Some(main) = app.get_webview_window("main") {
|
||||
let _ = main.show();
|
||||
let _ = main.unminimize();
|
||||
let _ = main.set_focus();
|
||||
}
|
||||
let _ = app.emit_to("main", "theme-editor-state", false);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Open (or focus) the discord presence embed editor in its own native window.
|
||||
#[tauri::command]
|
||||
pub async fn open_presence_editor(app: AppHandle) -> Result<(), String> {
|
||||
if let Some(window) = app.get_webview_window("presence-editor") {
|
||||
let _ = window.unminimize();
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
if let Some(main) = app.get_webview_window("main") {
|
||||
let _ = main.hide();
|
||||
}
|
||||
let _ = app.emit_to("main", "presence-editor-state", true);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let window =
|
||||
WebviewWindowBuilder::new(&app, "presence-editor", WebviewUrl::App("index.html".into()))
|
||||
.title("EZPPLauncher — Discord Rich Presence Editor")
|
||||
.inner_size(1200.0, 800.0)
|
||||
.min_inner_size(980.0, 650.0)
|
||||
.resizable(true)
|
||||
.center()
|
||||
.build()
|
||||
.map_err(|error| format!("Could not open the presence editor: {error}"))?;
|
||||
|
||||
let main_window = app.clone();
|
||||
window.on_window_event(move |event| {
|
||||
if matches!(event, WindowEvent::Destroyed) {
|
||||
if let Some(main) = main_window.get_webview_window("main") {
|
||||
let _ = main.show();
|
||||
let _ = main.unminimize();
|
||||
let _ = main.set_focus();
|
||||
}
|
||||
let _ = main_window.emit_to("main", "presence-editor-state", false);
|
||||
}
|
||||
});
|
||||
|
||||
if let Some(main) = app.get_webview_window("main") {
|
||||
let _ = main.hide();
|
||||
}
|
||||
let _ = app.emit_to("main", "presence-editor-state", true);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Focus the presence editor window and keep the main launcher window hidden.
|
||||
#[tauri::command]
|
||||
pub async fn focus_presence_editor(app: AppHandle) -> Result<(), String> {
|
||||
if let Some(window) = app.get_webview_window("presence-editor") {
|
||||
let _ = window.unminimize();
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
if let Some(main) = app.get_webview_window("main") {
|
||||
let _ = main.hide();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Close the presence editor window and restore the main launcher window.
|
||||
#[tauri::command]
|
||||
pub async fn close_presence_editor(app: AppHandle) -> Result<(), String> {
|
||||
if let Some(window) = app.get_webview_window("presence-editor") {
|
||||
let _ = window.close();
|
||||
}
|
||||
if let Some(main) = app.get_webview_window("main") {
|
||||
let _ = main.show();
|
||||
let _ = main.unminimize();
|
||||
let _ = main.set_focus();
|
||||
}
|
||||
let _ = app.emit_to("main", "presence-editor-state", false);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Theme data requested by the advanced editor window when it starts or switches themes.
|
||||
#[tauri::command]
|
||||
pub fn theme_editor_context(app: AppHandle) -> Result<ThemeEditorContext, String> {
|
||||
|
||||
+11
-5
@@ -18,18 +18,18 @@ pub mod theme_server;
|
||||
pub mod utils;
|
||||
use crate::{
|
||||
commands::{
|
||||
backup_theme_folder, check_for_corruption, config_all, config_clear, config_delete,
|
||||
backup_theme_folder, check_for_corruption, close_presence_editor, close_theme_editor, config_all, config_clear, config_delete,
|
||||
config_exists, config_get, config_set, download_and_extract_theme,
|
||||
download_ezpp_launcher_update, download_ezpp_launcher_update_files, encrypt_string, exit,
|
||||
export_theme, extract_theme, file_size, find_osu_installation, get_beatmapsets_count,
|
||||
export_theme, extract_theme, file_size, find_osu_installation, focus_presence_editor, focus_theme_editor, get_beatmapsets_count,
|
||||
get_ezpp_launcher_update_files, get_hwid, get_launcher_version, get_osu_release_stream,
|
||||
get_osu_skin, get_osu_version, get_platform, get_skins_count, has_net8, has_osuwinello,
|
||||
has_wmctrl, install_ezpp_launcher_update, installation_diagnostics,
|
||||
is_open_tablet_driver_path_valid, is_open_tablet_driver_running, is_osu_running,
|
||||
list_theme_backups, log_frontend, open_logs_folder, open_theme_editor, open_theme_folder,
|
||||
list_theme_backups, log_frontend, open_logs_folder, open_presence_editor, open_theme_editor, open_theme_folder,
|
||||
open_url_in_browser, opened_urls, optimize_theme_media, pick_osu_installation,
|
||||
presence_connect, presence_disconnect, presence_is_connected, presence_update_button,
|
||||
presence_update_status, presence_update_user, read_theme_info, replace_ui_files,
|
||||
presence_connect, presence_disconnect, presence_is_connected, presence_update_activity,
|
||||
presence_update_button, presence_update_status, presence_update_user, read_theme_info, replace_ui_files,
|
||||
resolve_osu_folder, restore_theme_backup, run_open_tablet_driver, run_osu, run_osu_updater,
|
||||
save_theme_project, set_logging_enabled, set_osu_config_values, set_osu_user_config_values,
|
||||
stop_open_tablet_driver, theme_asset_base, theme_editor_context, theme_preview_url,
|
||||
@@ -172,6 +172,7 @@ pub fn run() {
|
||||
presence_update_status,
|
||||
presence_update_user,
|
||||
presence_update_button,
|
||||
presence_update_activity,
|
||||
presence_is_connected,
|
||||
has_osuwinello,
|
||||
has_wmctrl,
|
||||
@@ -189,6 +190,11 @@ pub fn run() {
|
||||
export_theme,
|
||||
open_theme_folder,
|
||||
open_theme_editor,
|
||||
focus_theme_editor,
|
||||
close_theme_editor,
|
||||
open_presence_editor,
|
||||
focus_presence_editor,
|
||||
close_presence_editor,
|
||||
theme_editor_context,
|
||||
theme_asset_base,
|
||||
theme_preview_url,
|
||||
|
||||
+76
-11
@@ -6,13 +6,15 @@ use tauri::{AppHandle, RunEvent};
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
use tokio::time::{Duration, interval};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PresenceButton {
|
||||
pub label: String,
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PresenceData {
|
||||
pub state: String,
|
||||
pub details: String,
|
||||
@@ -21,6 +23,8 @@ pub struct PresenceData {
|
||||
pub small_image_key: Option<String>,
|
||||
pub small_image_text: Option<String>,
|
||||
pub dynamic_button: Option<PresenceButton>,
|
||||
pub secondary_button: Option<PresenceButton>,
|
||||
pub show_timestamp: bool,
|
||||
}
|
||||
|
||||
impl Default for PresenceData {
|
||||
@@ -32,7 +36,15 @@ impl Default for PresenceData {
|
||||
large_image_text: "EZPPFarm".to_string(),
|
||||
small_image_key: None,
|
||||
small_image_text: None,
|
||||
dynamic_button: None,
|
||||
dynamic_button: Some(PresenceButton {
|
||||
label: "Download the Launcher".to_string(),
|
||||
url: "https://git.ez-pp.farm/EZPPFarm/EZPPLauncher/releases/latest".to_string(),
|
||||
}),
|
||||
secondary_button: Some(PresenceButton {
|
||||
label: "Join EZPPFarm".to_string(),
|
||||
url: "https://ez-pp.farm/discord".to_string(),
|
||||
}),
|
||||
show_timestamp: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,10 +174,13 @@ impl PresenceActor {
|
||||
let mut builder = ActivityBuilder::new()
|
||||
.state(&self.data.state)
|
||||
.details(&self.data.details)
|
||||
.start_timestamp(self.start_timestamp as u64)
|
||||
.large_image(&self.data.large_image_key)
|
||||
.large_text(&self.data.large_image_text);
|
||||
|
||||
if self.data.show_timestamp {
|
||||
builder = builder.start_timestamp(self.start_timestamp as u64);
|
||||
}
|
||||
|
||||
if let Some(key) = &self.data.small_image_key {
|
||||
builder = builder.small_image(key);
|
||||
}
|
||||
@@ -174,14 +189,15 @@ impl PresenceActor {
|
||||
}
|
||||
|
||||
if let Some(btn) = &self.data.dynamic_button {
|
||||
builder = builder.button(&btn.label, &btn.url);
|
||||
} else {
|
||||
builder = builder.button(
|
||||
"Download the Launcher",
|
||||
"https://git.ez-pp.farm/EZPPFarm/EZPPLauncher/releases/latest",
|
||||
);
|
||||
if !btn.label.trim().is_empty() && !btn.url.trim().is_empty() {
|
||||
builder = builder.button(&btn.label, &btn.url);
|
||||
}
|
||||
}
|
||||
if let Some(btn2) = &self.data.secondary_button {
|
||||
if !btn2.label.trim().is_empty() && !btn2.url.trim().is_empty() {
|
||||
builder = builder.button(&btn2.label, &btn2.url);
|
||||
}
|
||||
}
|
||||
builder = builder.button("Join EZPPFarm", "https://ez-pp.farm/discord");
|
||||
|
||||
let activity = builder.build();
|
||||
|
||||
@@ -286,6 +302,55 @@ pub async fn has_presence() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn update_activity(
|
||||
state: Option<&str>,
|
||||
details: Option<&str>,
|
||||
large_image_key: Option<&str>,
|
||||
large_image_text: Option<&str>,
|
||||
small_image_key: Option<Option<String>>,
|
||||
small_image_text: Option<Option<String>>,
|
||||
button1: Option<Option<PresenceButton>>,
|
||||
button2: Option<Option<PresenceButton>>,
|
||||
show_timestamp: Option<bool>,
|
||||
) {
|
||||
let data = {
|
||||
let mut guard = PRESENCE_DATA.lock().unwrap();
|
||||
if let Some(s) = state {
|
||||
guard.state = s.to_string();
|
||||
}
|
||||
if let Some(d) = details {
|
||||
guard.details = d.to_string();
|
||||
}
|
||||
if let Some(img) = large_image_key {
|
||||
guard.large_image_key = img.to_string();
|
||||
}
|
||||
if let Some(txt) = large_image_text {
|
||||
guard.large_image_text = txt.to_string();
|
||||
}
|
||||
if let Some(key) = small_image_key {
|
||||
guard.small_image_key = key;
|
||||
}
|
||||
if let Some(text) = small_image_text {
|
||||
guard.small_image_text = text;
|
||||
}
|
||||
if let Some(b1) = button1 {
|
||||
guard.dynamic_button = b1;
|
||||
}
|
||||
if let Some(b2) = button2 {
|
||||
guard.secondary_button = b2;
|
||||
}
|
||||
if let Some(ts) = show_timestamp {
|
||||
guard.show_timestamp = ts;
|
||||
}
|
||||
guard.clone()
|
||||
};
|
||||
|
||||
let tx = PRESENCE_TX.clone();
|
||||
tokio::spawn(async move {
|
||||
let _ = tx.send(PresenceCommand::UpdateData(data)).await;
|
||||
});
|
||||
}
|
||||
|
||||
pub fn update_status(state: Option<&str>, details: Option<&str>, large_image_key: Option<&str>) {
|
||||
let data = {
|
||||
let mut guard = PRESENCE_DATA.lock().unwrap();
|
||||
|
||||
Reference in new issue
Block a user