-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
259 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Button, Dialog, DialogActions, DialogContent, TextField, DialogTitle, MenuItem, Select, SelectChangeEvent, InputLabel, FormControl, FormControlLabel, Checkbox } from '@mui/material'; | ||
import { useState } from 'react'; | ||
import { config, Theme } from '../config.ts'; | ||
|
||
export default function SettingsDialog(props: { open: boolean, onClose: (_apply: boolean) => void }) { | ||
const [serverurl, setServerurl] = useState(config.baseUrl); | ||
const [theme, setTheme] = useState(config.theme); | ||
const [showOffline, setShowOffline] = useState(config.showOffline); | ||
|
||
function handleClose(apply: boolean) { | ||
if (apply) { | ||
config.baseUrl = serverurl; | ||
config.theme = theme; | ||
config.showOffline = showOffline; | ||
} | ||
props.onClose(apply); | ||
} | ||
|
||
return ( | ||
<div> | ||
<Dialog open={props.open} > | ||
<DialogTitle>Settings</DialogTitle> | ||
<DialogContent dividers> | ||
<TextField | ||
autoFocus margin="dense" id="host" label="Snapserver host" type="text" fullWidth variant="standard" | ||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => { setServerurl(event.target.value as string) }} | ||
value={serverurl} | ||
/> | ||
<FormControl variant="standard" fullWidth sx={{ minWidth: 100 }}> | ||
<InputLabel id="theme-label">Theme</InputLabel> | ||
<Select | ||
labelId="theme-select-label" | ||
id="demo-theme-select" | ||
value={theme} | ||
label="Theme" | ||
onChange={(event: SelectChangeEvent<Theme>) => { console.log("Theme selected: " + event.target.value); setTheme(event.target.value as Theme) }} | ||
> | ||
<MenuItem value={Theme.System}>{Theme.System}</MenuItem> | ||
<MenuItem value={Theme.Light}>{Theme.Light}</MenuItem> | ||
<MenuItem value={Theme.Dark}>{Theme.Dark}</MenuItem> | ||
</Select> | ||
</FormControl> | ||
<FormControlLabel sx={{ minWidth: 100, mt: 1 }} control={<Checkbox checked={showOffline} onChange={(_event: React.ChangeEvent<HTMLInputElement>, checked: boolean) => setShowOffline(checked)} />} label="Show offline clients" /> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={() => { handleClose(false) }}>Cancel</Button> | ||
<Button onClick={() => { handleClose(true) }}>OK</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</div> | ||
); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,55 @@ | ||
const host = import.meta.env.VITE_APP_SNAPSERVER_HOST || window.location.host; | ||
|
||
const keys = { | ||
snapserver_host: "snapserver.host", | ||
theme: "theme", | ||
showoffline: "showoffline" | ||
} | ||
|
||
enum Theme { | ||
System = "system", | ||
Light = "light", | ||
Dark = "dark", | ||
} | ||
|
||
function setPersistentValue(key: string, value: string) { | ||
if (window.localStorage) { | ||
window.localStorage.setItem(key, value); | ||
} | ||
} | ||
|
||
function getPersistentValue(key: string, defaultValue: string = ""): string { | ||
if (window.localStorage) { | ||
const value = window.localStorage.getItem(key); | ||
if (value !== null) { | ||
return value; | ||
} | ||
window.localStorage.setItem(key, defaultValue); | ||
return defaultValue; | ||
} | ||
return defaultValue; | ||
} | ||
|
||
const config = { | ||
baseUrl: (window.location.protocol === "https:" ? "wss://" : "ws://") + host, | ||
get baseUrl() { | ||
return getPersistentValue(keys.snapserver_host, (window.location.protocol === "https:" ? "wss://" : "ws://") + host); | ||
}, | ||
set baseUrl(value) { | ||
setPersistentValue(keys.snapserver_host, value); | ||
}, | ||
get theme() { | ||
return getPersistentValue(keys.theme, Theme.System.toString()) as Theme; | ||
}, | ||
set theme(value: Theme) { | ||
setPersistentValue(keys.theme, value); | ||
}, | ||
get showOffline() { | ||
return getPersistentValue(keys.showoffline, String(false)) === String(true); | ||
}, | ||
set showOffline(value: boolean) { | ||
setPersistentValue(keys.showoffline, String(value)); | ||
} | ||
}; | ||
|
||
export { config }; | ||
|
||
export { config, getPersistentValue, setPersistentValue, Theme }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import './main.css'; | ||
import { config } from "./config"; | ||
import SnapWeb from './components/SnapWeb'; | ||
import { SnapControl } from './snapcontrol'; | ||
|
||
|
||
|
||
const root = ReactDOM.createRoot( | ||
document.getElementById('root') as HTMLElement | ||
); | ||
|
||
const snapcontrol = new SnapControl(config.baseUrl); | ||
|
||
console.log(`Welcome to ${import.meta.env.VITE_APP_NAME} ${import.meta.env.VITE_APP_VERSION}`) | ||
|
||
root.render( | ||
<React.StrictMode> | ||
<SnapWeb snapcontrol={snapcontrol} /> | ||
<SnapWeb /> | ||
</React.StrictMode> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters