Skip to content

Commit

Permalink
Save/restore app settings
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Mar 3, 2024
1 parent 4a7b6df commit 95544e3
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 19 deletions.
23 changes: 23 additions & 0 deletions main/src/infrastructure/plugin/backbone_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,29 @@ impl BackboneShell {
BackboneShell::helgoboss_resource_dir_path().join("App")
}

pub fn app_config_dir_path() -> PathBuf {
BackboneShell::helgoboss_resource_dir_path().join("AppConfig")
}

pub fn app_settings_file_path() -> PathBuf {
BackboneShell::app_config_dir_path().join("settings.json")
}

pub fn read_app_settings() -> Option<String> {
fs::read_to_string(Self::app_settings_file_path()).ok()
}

pub fn write_app_settings(settings: String) -> anyhow::Result<()> {
let file_path = Self::app_settings_file_path();
fs::create_dir_all(
file_path
.parent()
.context("app settings file should have parent")?,
)?;
fs::write(file_path, settings)?;
Ok(())
}

fn realearn_resource_dir_path() -> PathBuf {
BackboneShell::helgoboss_resource_dir_path().join("ReaLearn")
}
Expand Down
134 changes: 131 additions & 3 deletions main/src/infrastructure/proto/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub mod reply {
pub struct CommandRequest {
#[prost(
oneof = "command_request::Value",
tags = "1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 37, 40, 25, 26, 27, 34, 28, 29, 31, 32, 33, 35, 36, 38, 39, 41, 42"
tags = "1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 37, 40, 25, 26, 27, 34, 28, 29, 31, 32, 33, 35, 36, 38, 39, 41, 42, 43"
)]
pub value: ::core::option::Option<command_request::Value>,
}
Expand Down Expand Up @@ -139,6 +139,8 @@ pub mod command_request {
SetInstanceSettings(super::SetInstanceSettingsRequest),
#[prost(message, tag = "42")]
AddLicense(super::AddLicenseRequest),
#[prost(message, tag = "43")]
SetAppSettings(super::SetAppSettingsRequest),
}
}
/// Envelope for queries.
Expand All @@ -161,7 +163,7 @@ pub struct QueryRequest {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Query {
#[prost(oneof = "query::Value", tags = "1, 2, 3, 4, 5")]
#[prost(oneof = "query::Value", tags = "1, 2, 3, 4, 5, 6")]
pub value: ::core::option::Option<query::Value>,
}
/// Nested message and enum types in `Query`.
Expand All @@ -179,6 +181,8 @@ pub mod query {
GetHostInfo(super::GetHostInfoRequest),
#[prost(message, tag = "5")]
GetArrangementInfo(super::GetArrangementInfoRequest),
#[prost(message, tag = "6")]
GetAppSettings(super::GetAppSettingsRequest),
}
}
/// Envelope for query results.
Expand All @@ -199,7 +203,7 @@ pub struct QueryReply {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct QueryResult {
#[prost(oneof = "query_result::Value", tags = "1, 2, 3, 4, 5, 6")]
#[prost(oneof = "query_result::Value", tags = "1, 2, 3, 4, 5, 6, 7")]
pub value: ::core::option::Option<query_result::Value>,
}
/// Nested message and enum types in `QueryResult`.
Expand All @@ -219,6 +223,8 @@ pub mod query_result {
GetHostInfoReply(super::GetHostInfoReply),
#[prost(message, tag = "6")]
GetArrangementInfoReply(super::GetArrangementInfoReply),
#[prost(message, tag = "7")]
GetAppSettingsReply(super::GetAppSettingsReply),
}
}
/// Should contain all possible *event* replies from above service.
Expand Down Expand Up @@ -483,6 +489,23 @@ pub struct GetHostInfoReply {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetAppSettingsRequest {}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetAppSettingsReply {
/// App settings as JSON
#[prost(string, optional, tag = "1")]
pub app_settings: ::core::option::Option<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SetAppSettingsRequest {
/// App settings as JSON
#[prost(string, tag = "1")]
pub app_settings: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ProveAuthenticityRequest {
#[prost(bytes = "vec", tag = "1")]
pub challenge: ::prost::alloc::vec::Vec<u8>,
Expand Down Expand Up @@ -2115,6 +2138,13 @@ pub mod helgobox_service_server {
tonic::Response<super::ProveAuthenticityReply>,
tonic::Status,
>;
async fn get_app_settings(
&self,
request: tonic::Request<super::GetAppSettingsRequest>,
) -> std::result::Result<
tonic::Response<super::GetAppSettingsReply>,
tonic::Status,
>;
/// Matrix queries
async fn get_project_dir(
&self,
Expand All @@ -2139,6 +2169,10 @@ pub mod helgobox_service_server {
tonic::Status,
>;
/// Global commands
async fn set_app_settings(
&self,
request: tonic::Request<super::SetAppSettingsRequest>,
) -> std::result::Result<tonic::Response<super::Empty>, tonic::Status>;
async fn add_license(
&self,
request: tonic::Request<super::AddLicenseRequest>,
Expand Down Expand Up @@ -2637,6 +2671,53 @@ pub mod helgobox_service_server {
};
Box::pin(fut)
}
"/generated.HelgoboxService/GetAppSettings" => {
#[allow(non_camel_case_types)]
struct GetAppSettingsSvc<T: HelgoboxService>(pub Arc<T>);
impl<
T: HelgoboxService,
> tonic::server::UnaryService<super::GetAppSettingsRequest>
for GetAppSettingsSvc<T> {
type Response = super::GetAppSettingsReply;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::GetAppSettingsRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as HelgoboxService>::get_app_settings(&inner, request)
.await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = GetAppSettingsSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/generated.HelgoboxService/GetProjectDir" => {
#[allow(non_camel_case_types)]
struct GetProjectDirSvc<T: HelgoboxService>(pub Arc<T>);
Expand Down Expand Up @@ -2781,6 +2862,53 @@ pub mod helgobox_service_server {
};
Box::pin(fut)
}
"/generated.HelgoboxService/SetAppSettings" => {
#[allow(non_camel_case_types)]
struct SetAppSettingsSvc<T: HelgoboxService>(pub Arc<T>);
impl<
T: HelgoboxService,
> tonic::server::UnaryService<super::SetAppSettingsRequest>
for SetAppSettingsSvc<T> {
type Response = super::Empty;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::SetAppSettingsRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as HelgoboxService>::set_app_settings(&inner, request)
.await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = SetAppSettingsSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/generated.HelgoboxService/AddLicense" => {
#[allow(non_camel_case_types)]
struct AddLicenseSvc<T: HelgoboxService>(pub Arc<T>);
Expand Down
30 changes: 23 additions & 7 deletions main/src/infrastructure/proto/request_handler.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::infrastructure::plugin::{BackboneShell, InstanceShell};
use crate::infrastructure::proto::{
AddLicenseRequest, DeleteControllerRequest, DragClipRequest, DragColumnRequest, DragRowRequest,
DragSlotRequest, Empty, GetArrangementInfoReply, GetArrangementInfoRequest, GetClipDetailReply,
GetClipDetailRequest, GetHostInfoReply, GetHostInfoRequest, GetProjectDirReply,
GetProjectDirRequest, ImportFilesRequest, ProveAuthenticityReply, ProveAuthenticityRequest,
SaveControllerRequest, SetClipDataRequest, SetClipNameRequest, SetColumnSettingsRequest,
SetColumnTrackRequest, SetInstanceSettingsRequest, SetMatrixPanRequest,
SetMatrixSettingsRequest, SetMatrixTempoRequest, SetMatrixTimeSignatureRequest,
SetMatrixVolumeRequest, SetRowDataRequest, SetSequenceInfoRequest, SetTrackColorRequest,
DragSlotRequest, Empty, GetAppSettingsReply, GetAppSettingsRequest, GetArrangementInfoReply,
GetArrangementInfoRequest, GetClipDetailReply, GetClipDetailRequest, GetHostInfoReply,
GetHostInfoRequest, GetProjectDirReply, GetProjectDirRequest, ImportFilesRequest,
ProveAuthenticityReply, ProveAuthenticityRequest, SaveControllerRequest, SetAppSettingsRequest,
SetClipDataRequest, SetClipNameRequest, SetColumnSettingsRequest, SetColumnTrackRequest,
SetInstanceSettingsRequest, SetMatrixPanRequest, SetMatrixSettingsRequest,
SetMatrixTempoRequest, SetMatrixTimeSignatureRequest, SetMatrixVolumeRequest,
SetRowDataRequest, SetSequenceInfoRequest, SetTrackColorRequest,
SetTrackInputMonitoringRequest, SetTrackInputRequest, SetTrackNameRequest, SetTrackPanRequest,
SetTrackVolumeRequest, TriggerClipRequest, TriggerColumnRequest, TriggerMatrixRequest,
TriggerRowRequest, TriggerSequenceRequest, TriggerSlotRequest, TriggerTrackRequest,
Expand Down Expand Up @@ -468,6 +469,21 @@ impl ProtoRequestHandler {
}
}

pub async fn get_app_settings(
&self,
_req: GetAppSettingsRequest,
) -> Result<Response<GetAppSettingsReply>, Status> {
Ok(Response::new(GetAppSettingsReply {
app_settings: BackboneShell::read_app_settings(),
}))
}

pub fn set_app_settings(&self, req: SetAppSettingsRequest) -> Result<Response<Empty>, Status> {
BackboneShell::write_app_settings(req.app_settings)
.map_err(|e| Status::unknown(e.to_string()))?;
Ok(Response::new(Empty {}))
}

pub async fn get_host_info(
&self,
_req: GetHostInfoRequest,
Expand Down
36 changes: 27 additions & 9 deletions main/src/infrastructure/proto/service_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use crate::infrastructure::proto::senders::{ProtoSenders, WithSessionId};
use crate::infrastructure::proto::{
create_initial_global_updates, create_initial_instance_updates, helgobox_service_server,
AddLicenseRequest, DeleteControllerRequest, DragClipRequest, DragColumnRequest, DragRowRequest,
DragSlotRequest, Empty, GetArrangementInfoReply, GetArrangementInfoRequest, GetClipDetailReply,
GetClipDetailRequest, GetContinuousColumnUpdatesReply, GetContinuousColumnUpdatesRequest,
DragSlotRequest, Empty, GetAppSettingsReply, GetAppSettingsRequest, GetArrangementInfoReply,
GetArrangementInfoRequest, GetClipDetailReply, GetClipDetailRequest,
GetContinuousColumnUpdatesReply, GetContinuousColumnUpdatesRequest,
GetContinuousMatrixUpdatesReply, GetContinuousMatrixUpdatesRequest,
GetContinuousSlotUpdatesReply, GetContinuousSlotUpdatesRequest, GetOccasionalClipUpdatesReply,
GetOccasionalClipUpdatesRequest, GetOccasionalColumnUpdatesReply,
Expand All @@ -17,13 +18,14 @@ use crate::infrastructure::proto::{
GetOccasionalRowUpdatesRequest, GetOccasionalSlotUpdatesReply, GetOccasionalSlotUpdatesRequest,
GetOccasionalTrackUpdatesReply, GetOccasionalTrackUpdatesRequest, GetProjectDirReply,
GetProjectDirRequest, ImportFilesRequest, ProtoRequestHandler, ProveAuthenticityReply,
ProveAuthenticityRequest, SaveControllerRequest, SetClipDataRequest, SetClipNameRequest,
SetColumnSettingsRequest, SetColumnTrackRequest, SetInstanceSettingsRequest,
SetMatrixPanRequest, SetMatrixSettingsRequest, SetMatrixTempoRequest,
SetMatrixTimeSignatureRequest, SetMatrixVolumeRequest, SetRowDataRequest, SetTrackColorRequest,
SetTrackInputMonitoringRequest, SetTrackInputRequest, SetTrackNameRequest, SetTrackPanRequest,
SetTrackVolumeRequest, TriggerClipRequest, TriggerColumnRequest, TriggerMatrixRequest,
TriggerRowRequest, TriggerSlotRequest, TriggerTrackRequest,
ProveAuthenticityRequest, SaveControllerRequest, SetAppSettingsRequest, SetClipDataRequest,
SetClipNameRequest, SetColumnSettingsRequest, SetColumnTrackRequest,
SetInstanceSettingsRequest, SetMatrixPanRequest, SetMatrixSettingsRequest,
SetMatrixTempoRequest, SetMatrixTimeSignatureRequest, SetMatrixVolumeRequest,
SetRowDataRequest, SetTrackColorRequest, SetTrackInputMonitoringRequest, SetTrackInputRequest,
SetTrackNameRequest, SetTrackPanRequest, SetTrackVolumeRequest, TriggerClipRequest,
TriggerColumnRequest, TriggerMatrixRequest, TriggerRowRequest, TriggerSlotRequest,
TriggerTrackRequest,
};
use base::future_util;
use futures::{FutureExt, Stream, StreamExt};
Expand Down Expand Up @@ -629,6 +631,22 @@ impl helgobox_service_server::HelgoboxService for HelgoboxServiceImpl {
self.command_handler
.set_instance_settings(request.into_inner())
}

async fn get_app_settings(
&self,
request: Request<GetAppSettingsRequest>,
) -> Result<Response<GetAppSettingsReply>, Status> {
self.command_handler
.get_app_settings(request.into_inner())
.await
}

async fn set_app_settings(
&self,
request: Request<SetAppSettingsRequest>,
) -> Result<Response<Empty>, Status> {
self.command_handler.set_app_settings(request.into_inner())
}
}

type SyncBoxStream<'a, T> = Pin<Box<dyn Stream<Item = T> + Send + Sync + 'a>>;
Expand Down
10 changes: 10 additions & 0 deletions main/src/infrastructure/ui/app/app_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use anyhow::{anyhow, bail, Context, Result};
use base::Global;
use libloading::{Library, Symbol};

use crate::infrastructure::proto::query::Value;
#[cfg(feature = "playtime")]
use playtime_clip_engine::base::Matrix;
use prost::Message;
Expand Down Expand Up @@ -407,6 +408,12 @@ fn process_query_request(instance_id: String, id: u32, query: proto::query::Valu
Ok(query_result::Value::GetArrangementInfoReply(value))
});
}
GetAppSettings(req) => {
send_query_reply_to_app(instance_id, id, async move {
let value = handler.get_app_settings(req).await?.into_inner();
Ok(query_result::Value::GetAppSettingsReply(value))
});
}
}
Ok(())
}
Expand Down Expand Up @@ -609,6 +616,9 @@ fn process_command(
SetInstanceSettings(req) => {
handler.set_instance_settings(req)?;
}
SetAppSettings(req) => {
handler.set_app_settings(req)?;
}
}
Ok(())
}
Expand Down

0 comments on commit 95544e3

Please sign in to comment.