Skip to content

Commit

Permalink
fix: handle exceptions in update_node command
Browse files Browse the repository at this point in the history
  • Loading branch information
necipsagiro committed Jan 4, 2024
1 parent 1df9ea5 commit 11da942
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"private": true,
"type": "module",
"scripts": {
"tauri": "tauri"
"tauri": "tauri",
"dev": "tauri dev"
},
"devDependencies": {
"@tauri-apps/cli": "^1.4.0"
Expand Down
31 changes: 21 additions & 10 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,22 +604,33 @@ fn validator_list() -> Result<String, String> {
}

#[tauri::command(async)]
fn update_node(latest_version: String) -> Result<(), String> {
fn update_node(latest_version: String, exception: String) -> Result<(), String> {
let my_boxed_session =
unsafe { GLOBAL_STRUCT.as_ref() }.ok_or("There is no active session. Timed out.")?;
let mut channel = my_boxed_session
.open_session
.channel_session()
.map_err(|e| e.to_string())?;
let command = format!(
"bash -c -l 'systemctl stop $EXECUTE;
cd celestia-node;
git fetch --tags;
git checkout {latest_version};
make build;
sudo make install;
systemctl restart $EXECUTE;'"
);
let command = match exception.as_str() {
"celestia-full" => format!(
"bash -c -l 'systemctl stop $EXECUTE;
cd celestia-node;
git fetch --tags;
git checkout {latest_version};
make build;
sudo make install;
systemctl restart $EXECUTE;'"
),
_ => format!(
"bash -c -l 'systemctl stop $EXECUTE;
cd $PROJECT_FOLDER;
git fetch --tags;
git checkout {latest_version};
make build;
sudo make install;
systemctl restart $EXECUTE;'"
),
};
channel.exec(&command).map_err(|e| e.to_string())?;
let mut s = String::new();
channel.read_to_string(&mut s).map_err(|e| e.to_string())?;
Expand Down
1 change: 0 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
GOOGLE_API;
API_TOKEN;
2 changes: 1 addition & 1 deletion src/node-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ const nodeOperationsSetup = async () => {
updateNodeButton.addEventListener("click", async () => {
node_action = "update";
document.body.classList.add("waiting");
await tauri.invoke("update_node", { latestVersion: latest_tag }).catch(async (err) => { await handleTimeOut(err); });
await tauri.invoke("update_node", { latestVersion: latest_tag, exception: exception }).catch(async (err) => { await handleTimeOut(err); });
});
deleteNodeButton.addEventListener("click", async () => {
if (await dialog.ask("This action cannot be reverted. Are you sure?", { title: "Delete Node", type: "warning" })) {
Expand Down

0 comments on commit 11da942

Please sign in to comment.