Event Ballons and Tray Icon improvements (#1561)
Co-authored-by: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com>
This commit is contained in:
14
src/main.cpp
14
src/main.cpp
@@ -390,6 +390,20 @@ launch_ui() {
|
||||
platf::open_url(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Launch the Web UI at a specific endpoint.
|
||||
*
|
||||
* EXAMPLES:
|
||||
* ```cpp
|
||||
* launch_ui_with_path("/pin");
|
||||
* ```
|
||||
*/
|
||||
void
|
||||
launch_ui_with_path(std::string path) {
|
||||
std::string url = "https://localhost:" + std::to_string(map_port(confighttp::PORT_HTTPS)) + path;
|
||||
platf::open_url(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Flush the log.
|
||||
*
|
||||
|
||||
@@ -48,6 +48,8 @@ std::uint16_t
|
||||
map_port(int port);
|
||||
void
|
||||
launch_ui();
|
||||
void
|
||||
launch_ui_with_path(std::string path);
|
||||
|
||||
// namespaces
|
||||
namespace mail {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "platform/common.h"
|
||||
#include "process.h"
|
||||
#include "rtsp.h"
|
||||
#include "system_tray.h"
|
||||
#include "utility.h"
|
||||
#include "uuid.h"
|
||||
#include "video.h"
|
||||
@@ -507,7 +508,6 @@ namespace nvhttp {
|
||||
auto ptr = map_id_sess.emplace(sess.client.uniqueID, std::move(sess)).first;
|
||||
|
||||
ptr->second.async_insert_pin.salt = std::move(get_arg(args, "salt"));
|
||||
|
||||
if (config::sunshine.flags[config::flag::PIN_STDIN]) {
|
||||
std::string pin;
|
||||
|
||||
@@ -517,6 +517,9 @@ namespace nvhttp {
|
||||
getservercert(ptr->second, tree, pin);
|
||||
}
|
||||
else {
|
||||
#if defined SUNSHINE_TRAY && SUNSHINE_TRAY >= 1
|
||||
system_tray::update_tray_require_pin();
|
||||
#endif
|
||||
ptr->second.async_insert_pin.response = std::move(response);
|
||||
|
||||
fg.disable();
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "crypto.h"
|
||||
#include "main.h"
|
||||
#include "platform/common.h"
|
||||
#include "system_tray.h"
|
||||
#include "utility.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -116,7 +117,6 @@ namespace proc {
|
||||
|
||||
_app_id = app_id;
|
||||
_app = *iter;
|
||||
|
||||
_app_prep_begin = std::begin(_app.prep_cmds);
|
||||
_app_prep_it = _app_prep_begin;
|
||||
|
||||
@@ -244,9 +244,8 @@ namespace proc {
|
||||
|
||||
void
|
||||
proc_t::terminate() {
|
||||
bool has_run = _app_id > 0;
|
||||
std::error_code ec;
|
||||
|
||||
// Ensure child process is terminated
|
||||
placebo = false;
|
||||
process_end(_process, _process_handle);
|
||||
_process = bp::child();
|
||||
@@ -279,6 +278,13 @@ namespace proc {
|
||||
}
|
||||
|
||||
_pipe.reset();
|
||||
#if defined SUNSHINE_TRAY && SUNSHINE_TRAY >= 1
|
||||
// Only show the Stopped notification if we actually have an app to stop
|
||||
// Since terminate() is always run when a new app has started
|
||||
if (proc::proc.get_last_run_app_name().length() > 0 && has_run) {
|
||||
system_tray::update_tray_stopped(proc::proc.get_last_run_app_name());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
const std::vector<ctx_t> &
|
||||
@@ -304,6 +310,11 @@ namespace proc {
|
||||
return validate_app_image_path(app_image_path);
|
||||
}
|
||||
|
||||
std::string
|
||||
proc_t::get_last_run_app_name() {
|
||||
return _app.name;
|
||||
}
|
||||
|
||||
proc_t::~proc_t() {
|
||||
// It's not safe to call terminate() here because our proc_t is a static variable
|
||||
// that may be destroyed after the Boost loggers have been destroyed. Instead,
|
||||
|
||||
@@ -82,7 +82,8 @@ namespace proc {
|
||||
get_apps();
|
||||
std::string
|
||||
get_app_image(int app_id);
|
||||
|
||||
std::string
|
||||
get_last_run_app_name();
|
||||
void
|
||||
terminate();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ extern "C" {
|
||||
#include "stat_trackers.h"
|
||||
#include "stream.h"
|
||||
#include "sync.h"
|
||||
#include "system_tray.h"
|
||||
#include "thread_safe.h"
|
||||
#include "utility.h"
|
||||
|
||||
@@ -1732,6 +1733,11 @@ namespace stream {
|
||||
|
||||
// If this is the last session, invoke the platform callbacks
|
||||
if (--running_sessions == 0) {
|
||||
#if defined SUNSHINE_TRAY && SUNSHINE_TRAY >= 1
|
||||
if (proc::proc.running()) {
|
||||
system_tray::update_tray_pausing(proc::proc.get_last_run_app_name());
|
||||
}
|
||||
#endif
|
||||
platf::streaming_will_stop();
|
||||
}
|
||||
|
||||
@@ -1776,6 +1782,9 @@ namespace stream {
|
||||
// If this is the first session, invoke the platform callbacks
|
||||
if (++running_sessions == 1) {
|
||||
platf::streaming_will_start();
|
||||
#if defined SUNSHINE_TRAY && SUNSHINE_TRAY >= 1
|
||||
system_tray::update_tray_playing(proc::proc.get_last_run_app_name());
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -10,10 +10,19 @@
|
||||
#include <accctrl.h>
|
||||
#include <aclapi.h>
|
||||
#define TRAY_ICON WEB_DIR "images/favicon.ico"
|
||||
#define TRAY_ICON_PLAYING WEB_DIR "images/sunshine-playing.ico"
|
||||
#define TRAY_ICON_PAUSING WEB_DIR "images/sunshine-pausing.ico"
|
||||
#define TRAY_ICON_LOCKED WEB_DIR "images/sunshine-locked.ico"
|
||||
#elif defined(__linux__) || defined(linux) || defined(__linux)
|
||||
#define TRAY_ICON "sunshine"
|
||||
#define TRAY_ICON_PLAYING "sunshine-playing"
|
||||
#define TRAY_ICON_PAUSING "sunshine-pausing"
|
||||
#define TRAY_ICON_LOCKED "sunshine-locked"
|
||||
#elif defined(__APPLE__) || defined(__MACH__)
|
||||
#define TRAY_ICON WEB_DIR "images/logo-sunshine-16.png"
|
||||
#define TRAY_ICON_PLAYING WEB_DIR "images/sunshine-playing-16.png"
|
||||
#define TRAY_ICON_PAUSING WEB_DIR "images/sunshine-pausing-16.png"
|
||||
#define TRAY_ICON_LOCKED WEB_DIR "images/sunshine-locked-16.png"
|
||||
#include <dispatch/dispatch.h>
|
||||
#endif
|
||||
|
||||
@@ -268,5 +277,93 @@ namespace system_tray {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the tray icon in playing mode and spawns the appropriate notification
|
||||
* @param app_name The started application name
|
||||
*/
|
||||
void
|
||||
update_tray_playing(std::string app_name) {
|
||||
tray.notification_title = NULL;
|
||||
tray.notification_text = NULL;
|
||||
tray.notification_cb = NULL;
|
||||
tray.notification_icon = NULL;
|
||||
tray.icon = TRAY_ICON_PLAYING;
|
||||
tray_update(&tray);
|
||||
tray.icon = TRAY_ICON_PLAYING;
|
||||
tray.notification_title = "Stream Started";
|
||||
char msg[256];
|
||||
sprintf(msg, "Streaming started for %s", app_name.c_str());
|
||||
tray.notification_text = msg;
|
||||
tray.tooltip = msg;
|
||||
tray.notification_icon = TRAY_ICON_PLAYING;
|
||||
tray_update(&tray);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the tray icon in pausing mode (stream stopped but app running) and spawns the appropriate notification
|
||||
* @param app_name The paused application name
|
||||
*/
|
||||
void
|
||||
update_tray_pausing(std::string app_name) {
|
||||
tray.notification_title = NULL;
|
||||
tray.notification_text = NULL;
|
||||
tray.notification_cb = NULL;
|
||||
tray.notification_icon = NULL;
|
||||
tray.icon = TRAY_ICON_PAUSING;
|
||||
tray_update(&tray);
|
||||
char msg[256];
|
||||
sprintf(msg, "Streaming paused for %s", app_name.c_str());
|
||||
tray.icon = TRAY_ICON_PAUSING;
|
||||
tray.notification_title = "Stream Paused";
|
||||
tray.notification_text = msg;
|
||||
tray.tooltip = msg;
|
||||
tray.notification_icon = TRAY_ICON_PAUSING;
|
||||
tray_update(&tray);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the tray icon in stopped mode (app and stream stopped) and spawns the appropriate notification
|
||||
* @param app_name The started application name
|
||||
*/
|
||||
void
|
||||
update_tray_stopped(std::string app_name) {
|
||||
tray.notification_title = NULL;
|
||||
tray.notification_text = NULL;
|
||||
tray.notification_cb = NULL;
|
||||
tray.notification_icon = NULL;
|
||||
tray.icon = TRAY_ICON;
|
||||
tray_update(&tray);
|
||||
char msg[256];
|
||||
sprintf(msg, "Application %s successfully stopped", app_name.c_str());
|
||||
tray.icon = TRAY_ICON;
|
||||
tray.notification_icon = TRAY_ICON;
|
||||
tray.notification_title = "Application Stopped";
|
||||
tray.notification_text = msg;
|
||||
tray.tooltip = "Sunshine";
|
||||
tray_update(&tray);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Spawns a notification for PIN Pairing. Clicking it opens the PIN Web UI Page
|
||||
*/
|
||||
void
|
||||
update_tray_require_pin() {
|
||||
tray.notification_title = NULL;
|
||||
tray.notification_text = NULL;
|
||||
tray.notification_cb = NULL;
|
||||
tray.notification_icon = NULL;
|
||||
tray.icon = TRAY_ICON;
|
||||
tray_update(&tray);
|
||||
tray.icon = TRAY_ICON;
|
||||
tray.notification_title = "Incoming Pairing Request";
|
||||
tray.notification_text = "Click here to complete the pairing process";
|
||||
tray.notification_icon = TRAY_ICON_LOCKED;
|
||||
tray.tooltip = "Sunshine";
|
||||
tray.notification_cb = []() {
|
||||
launch_ui_with_path("/pin");
|
||||
};
|
||||
tray_update(&tray);
|
||||
}
|
||||
|
||||
} // namespace system_tray
|
||||
#endif
|
||||
|
||||
@@ -27,5 +27,13 @@ namespace system_tray {
|
||||
run_tray();
|
||||
int
|
||||
end_tray();
|
||||
void
|
||||
update_tray_playing(std::string app_name);
|
||||
void
|
||||
update_tray_pausing(std::string app_name);
|
||||
void
|
||||
update_tray_stopped(std::string app_name);
|
||||
void
|
||||
update_tray_require_pin();
|
||||
|
||||
} // namespace system_tray
|
||||
|
||||
Reference in New Issue
Block a user