Skip to content

Commit

Permalink
Add Restarting status to be set from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Radiokot committed Dec 1, 2023
1 parent 5b0ca7d commit 5e89a9a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/components/AppHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
? "Unreacahable"
: $tunnelStatus?.isOk()
? "Running"
: $tunnelStatus?.status;
: $tunnelStatus?.isRestarting()
? "Restarting"
: $tunnelStatus?.status;
$: isTunnelHealthy = $tunnelStatus?.isOk() == true;
$: connecorVersion = $tunnelStatus?.version;
</script>
Expand Down
15 changes: 15 additions & 0 deletions src/model/TunnelStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export default class TunnelStatus {
return this.status == 'UNREACHABLE'
}

/**
* @returns {boolean} if the tunnel is restarting
*/
isRestarting() {
return this.status == 'RESTARTING'
}

/**
*
* @returns {boolean} if the tunnel is fine
Expand All @@ -44,4 +51,12 @@ export default class TunnelStatus {
static from(json) {
return new TunnelStatus(json.status, json.version, json.routes);
}

/**
* Creates status of a restartung tunnel
* @returns {TunnelStatus}
*/
static restarting() {
return new TunnelStatus('RESTARTING')
}
}
11 changes: 9 additions & 2 deletions src/routes/settings/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import { PUBLIC_GUIDE_URL } from "$env/static/public";
import TunnelSettings from "../../model/TunnelSettings";
import { setTunnelStatusRestarting } from "../../stores/tunnel-status";
const tokenRegex = /[A-Za-z0-9+/]+={0,2}$/g;
Expand All @@ -18,11 +19,17 @@
saveResult = null;
try {
await saveTunnelSettings();
try {
if (setTunnelStatusRestarting) {
setTunnelStatusRestarting()
}
} catch {}
saveResult = "The connector will restart in a moment.";
} catch (err) {
console.error("onSaveClicked(): save_failed:", err)
console.error("onSaveClicked(): save_failed:", err);
saveResult = "Failed to save the settings. Check the dev console for errors.";
saveResult =
"Failed to save the settings. Check the dev console for errors.";
} finally {
isSavingSettings = false;
}
Expand Down
9 changes: 9 additions & 0 deletions src/stores/tunnel-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ import { browser } from '$app/environment';

import TunnelStatus from "../model/TunnelStatus";

/**
* @type{(() => void)?}
*/
export let setTunnelStatusRestarting = null

/**
* Auto-updating tunnel status store.
*
* @type {import("svelte/store").Readable<TunnelStatus?>}
*/
export default readable(null, (set) => {
setTunnelStatusRestarting = () => {
set(TunnelStatus.restarting())
}

const updateValue = async () => {
let response = await fetch("/api/status");
if (!response.ok) {
Expand Down

0 comments on commit 5e89a9a

Please sign in to comment.