mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2025-01-18 22:26:12 +01:00
Add reload config API call
This commit is contained in:
parent
1c2f639a56
commit
457f0d3d56
4 changed files with 36 additions and 2 deletions
|
@ -37,6 +37,16 @@ function pinnacle.quit()
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Reload the active config.
|
||||||
|
function pinnacle.reload_config()
|
||||||
|
client.unary_request({
|
||||||
|
service = "pinnacle.v0alpha1.PinnacleService",
|
||||||
|
method = "ReloadConfig",
|
||||||
|
request_type = "pinnacle.v0alpha1.ReloadConfigRequest",
|
||||||
|
data = {},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
---Setup a Pinnacle config.
|
---Setup a Pinnacle config.
|
||||||
---
|
---
|
||||||
---You must pass in a function that takes in the `Pinnacle` table. This table is how you'll access the other config modules.
|
---You must pass in a function that takes in the `Pinnacle` table. This table is how you'll access the other config modules.
|
||||||
|
|
|
@ -21,6 +21,8 @@ enum SetOrToggle {
|
||||||
|
|
||||||
message QuitRequest {}
|
message QuitRequest {}
|
||||||
|
|
||||||
|
message ReloadConfigRequest {}
|
||||||
|
|
||||||
// A manual ping request independent of any HTTP keepalive.
|
// A manual ping request independent of any HTTP keepalive.
|
||||||
//
|
//
|
||||||
// Tonic does not seems to give you the means to run something
|
// Tonic does not seems to give you the means to run something
|
||||||
|
@ -36,5 +38,6 @@ message PingResponse {
|
||||||
|
|
||||||
service PinnacleService {
|
service PinnacleService {
|
||||||
rpc Quit(QuitRequest) returns (google.protobuf.Empty);
|
rpc Quit(QuitRequest) returns (google.protobuf.Empty);
|
||||||
|
rpc ReloadConfig(ReloadConfigRequest) returns (google.protobuf.Empty);
|
||||||
rpc Ping(PingRequest) returns (PingResponse);
|
rpc Ping(PingRequest) returns (PingResponse);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use pinnacle_api_defs::pinnacle::v0alpha1::{
|
use pinnacle_api_defs::pinnacle::v0alpha1::{
|
||||||
pinnacle_service_client::PinnacleServiceClient, PingRequest, QuitRequest,
|
pinnacle_service_client::PinnacleServiceClient, PingRequest, QuitRequest, ReloadConfigRequest,
|
||||||
};
|
};
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use tonic::{transport::Channel, Request};
|
use tonic::{transport::Channel, Request};
|
||||||
|
@ -42,6 +42,12 @@ impl Pinnacle {
|
||||||
block_on_tokio(client.quit(QuitRequest {})).unwrap();
|
block_on_tokio(client.quit(QuitRequest {})).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reload the currently active config.
|
||||||
|
pub fn reload_config(&self) {
|
||||||
|
let mut client = self.client.clone();
|
||||||
|
block_on_tokio(client.reload_config(ReloadConfigRequest {})).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) async fn ping(&self) -> Result<(), String> {
|
pub(super) async fn ping(&self) -> Result<(), String> {
|
||||||
let mut client = self.client.clone();
|
let mut client = self.client.clone();
|
||||||
let mut payload = [0u8; 8];
|
let mut payload = [0u8; 8];
|
||||||
|
|
17
src/api.rs
17
src/api.rs
|
@ -30,7 +30,10 @@ use pinnacle_api_defs::pinnacle::{
|
||||||
SwitchToRequest,
|
SwitchToRequest,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
v0alpha1::{pinnacle_service_server, PingRequest, PingResponse, QuitRequest, SetOrToggle},
|
v0alpha1::{
|
||||||
|
pinnacle_service_server, PingRequest, PingResponse, QuitRequest, ReloadConfigRequest,
|
||||||
|
SetOrToggle,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::renderer::TextureFilter,
|
backend::renderer::TextureFilter,
|
||||||
|
@ -192,6 +195,18 @@ impl pinnacle_service_server::PinnacleService for PinnacleService {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn reload_config(
|
||||||
|
&self,
|
||||||
|
_request: Request<ReloadConfigRequest>,
|
||||||
|
) -> Result<Response<()>, Status> {
|
||||||
|
run_unary_no_response(&self.sender, |state| {
|
||||||
|
state
|
||||||
|
.start_config(state.config.dir(&state.xdg_base_dirs))
|
||||||
|
.expect("failed to restart config");
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
async fn ping(&self, request: Request<PingRequest>) -> Result<Response<PingResponse>, Status> {
|
async fn ping(&self, request: Request<PingRequest>) -> Result<Response<PingResponse>, Status> {
|
||||||
let payload = request.into_inner().payload;
|
let payload = request.into_inner().payload;
|
||||||
Ok(Response::new(PingResponse { payload }))
|
Ok(Response::new(PingResponse { payload }))
|
||||||
|
|
Loading…
Reference in a new issue