Skip to content

Commit 72527fa

Browse files
committed
Fix: Dynamically reload apps.json for Moonlight API if modified on disk
This adds a timestamp check in proc::refresh() and calls it from the /applist endpoint to ensure changes made to apps.json outside the Web UI are immediately reflected in Moonlight.
1 parent cf52f4b commit 72527fa

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/nvhttp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ namespace nvhttp {
955955
*/
956956
void applist(resp_https_t response, req_https_t request) {
957957
print_req<SunshineHTTPS>(request);
958+
proc::refresh(config::stream.file_apps);
958959

959960
pt::ptree tree;
960961

src/process.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ namespace proc {
4545

4646
proc_t proc; ///< Global process registry used to track and terminate child processes.
4747

48+
std::filesystem::file_time_type last_apps_file_update; ///< Timestamp of the last time apps.json was parsed.
49+
4850
/**
4951
* @brief RAII helper that runs shutdown cleanup when destroyed.
5052
*/
@@ -794,12 +796,25 @@ namespace proc {
794796

795797
/**
796798
* @brief Refresh cached platform state from the operating system.
799+
*
800+
* This function compares the current last modified time of the file to the time it was last parsed.
801+
* If the file has been modified since it was last parsed (or if it has never been parsed),
802+
* it will be re-parsed to update the app list.
797803
*/
798804
void refresh(const std::string &file_name) {
805+
std::error_code ec;
806+
auto current_time = std::filesystem::last_write_time(file_name, ec);
807+
808+
// Only parse the file if there were no errors reading the timestamp and it has been updated
809+
if (!ec && current_time <= last_apps_file_update) {
810+
return;
811+
}
812+
799813
auto proc_opt = proc::parse(file_name);
800814

801815
if (proc_opt) {
802816
proc = std::move(*proc_opt);
817+
last_apps_file_update = current_time;
803818
}
804819
}
805820
} // namespace proc

0 commit comments

Comments
 (0)