Skip to content

Commit

Permalink
Settings page now displays version. Necassary changes to accomadate t…
Browse files Browse the repository at this point in the history
…his added across the stack.
  • Loading branch information
HenryMBaldwin committed Sep 24, 2024
1 parent ce23f96 commit bd150a5
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stargazer"
version = "0.1.0"
version = "0.1.2"
description = "A Tauri App"
authors = ["you"]
license = ""
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/gui/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
.plugin(tauri_plugin_shell::init())
//.manage(client)
.setup(|app| {
//check for updates on startup and then every hour
//check for updates on startup and then every 10 minutes
let handle = app.handle().clone();
tauri::async_runtime::spawn(async move {
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(3600));
Expand Down Expand Up @@ -101,6 +101,7 @@ fn main() {
pipe_client::get_databases,
pipe_client::switch_database,
pipe_client::logout,
pipe_client::get_server_version,
])
.build(tauri::generate_context!())
.expect("error while running tauri application")
Expand Down
13 changes: 11 additions & 2 deletions src-tauri/src/gui/pipe_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// Important: Any functions in the orion_api in the server must be reflected here for the gui to have access to them.
// Important: Any functions that communicate with the server must ensure to call check_alive() before attempting to communicate with the server.
use std::env;
use stargazer::libpipe::reqres::{GetDatabasesRequest, GetQueryLogRequest, SwitchDatabaseRequest};
use stargazer::libpipe::reqres::{GetDatabasesRequest, GetQueryLogRequest, GetServerVersionRequest, SwitchDatabaseRequest};
use tokio::process::Command;
use std::io::{Read, Write};
use named_pipe::PipeClient;
use stargazer::libpipe::{reqres::{ RequestType, LoginRequest, ResponseType, CheckAuthRequest, CheckAliveRequest}, consts};
use reqwest::StatusCode;
use reqwest::{Response, StatusCode};
use serde_json;
use anyhow::{Result,Error};

Expand Down Expand Up @@ -132,6 +132,15 @@ pub async fn switch_database(id: String) -> Vec<(String, String, bool)> {
}
}

#[tauri::command]
pub async fn get_server_version() -> String {
let request = serde_json::to_string(&RequestType::GetServerVersion(GetServerVersionRequest{})).expect("Error: error serializing json.");
let response = serde_json::from_str::<ResponseType>(&send_wait(&request).await.expect("Error connecting to pipe")).expect("Error deserializing json");
match response {
ResponseType::GetServerVersion(get_server_version) => get_server_version.version,
_ => "Error: could not get server version".to_string()
}
}
// writes request to named pipe and waits for reponse, for check_alive()
async fn start_wait(request: &str) -> Result<String> {
let mut client = match PipeClient::connect(consts::PIPE_NAME) {
Expand Down
12 changes: 12 additions & 0 deletions src-tauri/src/libpipe/reqres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub enum RequestType {
SwitchDatabase(SwitchDatabaseRequest),
Logout(LogoutRequest),
ShutdownServer(ShutdownServerRequest),
GetServerVersion(GetServerVersionRequest),
}

#[derive(Serialize, Deserialize)]
Expand All @@ -55,6 +56,7 @@ pub enum ResponseType {
SwitchDatabase(SwitchDatabaseResponse),
Logout(LogoutResponse),
ShutdownServer(ShutdownServerResponse),
GetServerVersion(GetServerVersionResponse)
}


Expand Down Expand Up @@ -196,4 +198,14 @@ pub struct ShutdownServerRequest{}
#[derive(Serialize, Deserialize)]
pub struct ShutdownServerResponse{
pub status: u16,
}

//get_server_version
#[derive(Serialize, Deserialize)]
pub struct GetServerVersionRequest{}

#[derive(Serialize, Deserialize)]
pub struct GetServerVersionResponse {
pub version: String,
pub status: u16,
}
5 changes: 5 additions & 0 deletions src-tauri/src/server/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ impl InstanceManager {
self.ready_to_die = true;
}

//gets server version as string
pub fn get_server_version(&self) -> String {
let version_string = self.server.version.to_string();
format!("0.{}.{}", &version_string[0..1], &version_string[1..])
}
//register a client instance
//returns true if the client was registered
//returns false if the client cannot be registered
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@ async fn handle_request(request: &str, orion_api: Arc<OrionAPI>, cache_controlle

serde_json::to_string(&resp).unwrap()
},
Ok(RequestType::GetServerVersion(_)) => {
let version = instance_manager.lock().await.get_server_version();
let resp = ResponseType::GetServerVersion(GetServerVersionResponse {
version,
status: StatusCode::OK.as_u16()
});
serde_json::to_string(&resp).unwrap()
}
//Error
Err(e) => {
//TODO Handle Error
Expand Down
2 changes: 1 addition & 1 deletion src/routes/dashboard/home/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<li><code class="code">=Stargazer.QUERY(id, cache, [args])</code> - This formula takes in a query id, a boolean, then all args as strings. Some things to note:
<ul class="list-disc list-inside text-sm pl-4">
<li><strong>cache</strong> - If true, the formula will attempt to retrieve a cached query. Queries are cached base on their ID and arguments. This is extremely useful if
you need to use the same query multiple times in the same day, and it's not sensitive to changes in that time. If you need to ensure query data is
you need to use the same query multiple times in the same day, and don't need moment to moment changes. If you need to ensure query data is
always up to date to the moment the formula calculates, then set this to false. </li>
<li><strong>args</strong> - These are the arguments for the query. They must be in the same order as the prompts, and must be strings. Any dates in excel should be converted
to formated strings. This formula can accept an arbitrary amount of arguments.</li>
Expand Down
29 changes: 25 additions & 4 deletions src/routes/dashboard/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
selected: false,
});
const version = writable<string>("loading...");
onMount(async () => {
get_version();
databasesStore.set(await get_databases());
});
async function get_databases(): Promise<Database[]> {
Expand Down Expand Up @@ -81,6 +84,13 @@
});
}
async function get_version(){
await invoke("get_server_version").then((res) => {
const result = res as string;
version.set(result);
});
}
let selectedDatabase: Database = {
id: "0",
name: "None",
Expand Down Expand Up @@ -108,8 +118,19 @@

<div class="w-full flex flex-col items-start py-8 px-20 gap-8 max-w-prose gap-8 font-aleo">
<h1 class="h2 font-aleo">Settings</h1>
<!-- Info -->
<div class="flex flex-col items-start gap-4 w-full card bg-surface-50 p-4">
<div class="flex flex-col items-start w-full">
<h3 class="h3 font-aleo">Info</h3>
<hr class="!border-t-1 !border-secondary-500 w-full">
</div>
<div class="flex flex-row items-center justify-between w-full">
Version
<span>{$version}</span>
</div>
</div>
<!-- Orion Settings -->
<div class="flex flex-col items-start gap-4 w-full card bg-surface-50 p-4 ">
<!-- Orion Settings -->
<div class="flex flex-col items-start w-full">
<h3 class="h3 font-aleo">Orion</h3>
<hr class="!border-t-1 !border-secondary-500 w-full"/>
Expand All @@ -121,10 +142,10 @@
<span>↓</span>
</button>
</div>
<!-- /Orion Settings -->
</div>
<!-- /Orion Settings -->
<!-- General Settings -->
<div class="flex flex-col items-start gap-4 w-full card bg-surface-50 p-4 ">
<!-- General Settings -->
<div class="flex flex-col items-start w-full">
<h3 class="h3 font-aleo">General</h3>
<hr class="!border-t-1 !border-secondary-500 w-full"/>
Expand All @@ -135,5 +156,5 @@
</button>
</div>
</div>

<!-- /General Settings -->
</div>

0 comments on commit bd150a5

Please sign in to comment.