Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement configuring network settings #1

Merged
merged 2 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions firmwareflasher.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"eyetrack",
"eyetrackvrfft",
"flashtool",
"hljs",
"improv",
"Iprops",
"kobalte",
Expand All @@ -56,6 +57,7 @@
"ratelimit",
"solidjs",
"specta",
"stackoverflow",
"Swatinem",
"typecheck",
"Unlisten",
Expand Down
171 changes: 86 additions & 85 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,86 +1,87 @@
{
"name": "etvr-firmware-flasher-tool",
"version": "1.1.2",
"private": true,
"description": "A SolidJS project for EyeTrackVR",
"author": "EyeTrackVR",
"license": "MIT",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"start": "vite start",
"serve": "vite preview",
"tauri": "tauri",
"tauri:dev": "tauri dev",
"tauri:dev:release": "tauri dev --release",
"tauri:build": "tauri build",
"tauri:build:dev": "tauri build --debug",
"tauri:update": "cd src-tauri && cargo update && cargo upgrade",
"tauri:clean": "cd src-tauri && cargo clean",
"specta:post-install": "pnpm run specta:codegen && pnpm run specta:build",
"specta:build": "pnpm --stream -r specta:build",
"specta:gen": "pnpm --stream -r specta:gen",
"docs": "jsdoc -c jsdoc.conf.json",
"lint": "eslint --ext .js,.ts,.jsx,.tsx src",
"format": "pnpm run lint --fix & pnpm prettier --write \"src/**/*.{js,jsx,ts,tsx}\"",
"update-deps": "pnpm up -Li",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@babel/core": "^7.23.0",
"@babel/preset-env": "^7.22.20",
"@tailwindcss/forms": "^0.5.6",
"@tauri-apps/api": "^1.5.0",
"@tauri-apps/cli": "^1.5.1",
"@types/node": "^20.8.2",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"autoprefixer": "^10.4.16",
"babel-loader": "^9.1.3",
"better-docs": "^2.7.2",
"eslint": "^8.50.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-autofix": "^1.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-solid": "^0.13.0",
"https-localhost": "^4.7.1",
"jsdoc": "^4.0.2",
"postcss": "^8.4.31",
"postcss-import": "^15.1.0",
"prettier": "^3.0.3",
"tailwindcss": "^3.3.3",
"typescript": "^5.2.2",
"vite": "^4.4.11",
"vite-plugin-solid": "^2.7.0"
},
"dependencies": {
"@kobalte/core": "^0.11.0",
"@kobalte/tailwindcss": "^0.8.0",
"@optimize-lodash/rollup-plugin": "^4.0.4",
"@solid-primitives/i18n": "^1.4.1",
"@solid-primitives/map": "^0.4.8",
"@solid-primitives/refs": "^1.0.5",
"@solidjs/meta": "^0.28.6",
"@solidjs/router": "^0.8.3",
"@stitches/core": "^1.2.8",
"@tailwindcss/typography": "^0.5.10",
"babel-preset-solid": "^1.7.12",
"fp-ts": "^2.16.1",
"lodash": "^4.17.21",
"solid-form-handler": "^1.2.0",
"solid-headless": "^0.13.1",
"solid-i18n": "^1.1.0",
"solid-icons": "^1.0.12",
"solid-js": "^1.7.12",
"solid-spinner": "^0.1.9",
"solid-transition-group": "^0.2.3",
"solidjs-icons": "^1.0.12",
"solidjs-use": "^2.3.0",
"tauri-plugin-log-api": "github:tauri-apps/tauri-plugin-log",
"tauri-plugin-request-client": "workspace:*",
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store",
"tauri-plugin-upload-api": "github:tauri-apps/tauri-plugin-upload"
}
}
"name": "etvr-firmware-flasher-tool",
"version": "1.1.1",
"private": true,
"description": "A SolidJS project for EyeTrackVR",
"author": "EyeTrackVR",
"license": "MIT",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"start": "vite start",
"serve": "vite preview",
"tauri": "tauri",
"tauri:dev": "tauri dev",
"tauri:dev:release": "tauri dev --release",
"tauri:build": "tauri build",
"tauri:build:dev": "tauri build --debug",
"tauri:update": "cd src-tauri && cargo update && cargo upgrade",
"tauri:clean": "cd src-tauri && cargo clean",
"specta:post-install": "pnpm run specta:codegen && pnpm run specta:build",
"specta:build": "pnpm --stream -r specta:build",
"specta:gen": "pnpm --stream -r specta:gen",
"docs": "jsdoc -c jsdoc.conf.json",
"lint": "eslint --ext .js,.ts,.jsx,.tsx src",
"format": "pnpm run lint --fix & pnpm prettier --write \"src/**/*.{js,jsx,ts,tsx}\"",
"update-deps": "pnpm up -Li",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@babel/core": "^7.23.0",
"@babel/preset-env": "^7.22.20",
"@tailwindcss/forms": "^0.5.6",
"@tauri-apps/api": "^1.5.0",
"@tauri-apps/cli": "^1.5.1",
"@types/node": "^20.8.2",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"autoprefixer": "^10.4.16",
"babel-loader": "^9.1.3",
"better-docs": "^2.7.2",
"eslint": "^8.50.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-autofix": "^1.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-solid": "^0.13.0",
"https-localhost": "^4.7.1",
"jsdoc": "^4.0.2",
"postcss": "^8.4.31",
"postcss-import": "^15.1.0",
"prettier": "^3.0.3",
"tailwindcss": "^3.3.3",
"typescript": "^5.2.2",
"vite": "^4.4.11",
"vite-plugin-solid": "^2.7.0"
},
"dependencies": {
"@kobalte/core": "^0.11.0",
"@kobalte/tailwindcss": "^0.8.0",
"@optimize-lodash/rollup-plugin": "^4.0.4",
"@solid-primitives/i18n": "^1.4.1",
"@solid-primitives/map": "^0.4.8",
"@solid-primitives/refs": "^1.0.5",
"@solidjs/meta": "^0.28.6",
"@solidjs/router": "^0.8.3",
"@stitches/core": "^1.2.8",
"@tailwindcss/typography": "^0.5.10",
"babel-preset-solid": "^1.7.12",
"fp-ts": "^2.16.1",
"lodash": "^4.17.21",
"solid-form-handler": "^1.2.0",
"solid-headless": "^0.13.1",
"highlight.js": "11.9.0",
"solid-i18n": "^1.1.0",
"solid-icons": "^1.0.12",
"solid-js": "^1.7.12",
"solid-spinner": "^0.1.9",
"solid-transition-group": "^0.2.3",
"solidjs-icons": "^1.0.12",
"solidjs-use": "^2.3.0",
"tauri-plugin-log-api": "github:tauri-apps/tauri-plugin-log",
"tauri-plugin-request-client": "workspace:*",
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store",
"tauri-plugin-upload-api": "github:tauri-apps/tauri-plugin-upload"
}
}
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions src-tauri/src/lib/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ impl RESTClient {
pub fn new(base_url: Option<String>, method: Option<String>) -> Self {
Self {
http_client: Arc::new(tauri::async_runtime::Mutex::new(Client::new())),
base_url: Arc::new(Mutex::new(base_url.unwrap_or(String::new()))),
method: Arc::new(Mutex::new(method.unwrap_or(String::new()))),
base_url: Arc::new(Mutex::new(base_url.unwrap_or_default())),
method: Arc::new(Mutex::new(method.unwrap_or_default())),
}
}
}
Expand Down Expand Up @@ -63,7 +63,7 @@ impl<R: Runtime> APIPlugin<R> {
self.rest_client.method.lock().unwrap().clone()
}

async fn request(&self) -> ETVResult<()> {
async fn request(&self) -> ETVResult<String> {
info!("Making REST request");

let base_url = self.get_base_url();
Expand Down Expand Up @@ -112,8 +112,8 @@ impl<R: Runtime> APIPlugin<R> {
};
self
.app_handle
.trigger_global("request-response", Some(response));
Ok(())
.trigger_global("request-response", Some(response.clone()));
Ok(response)
// send a global event when the API is closed
}

Expand All @@ -135,8 +135,12 @@ impl<R: Runtime> APIPlugin<R> {

let request_result = self.request().await;
match request_result {
Ok(()) => {
println!("[APIPlugin]: Request response: Ok");
Ok(response) => {
self
.app_handle
.emit_all("request-response", Some(response.clone()))
.expect("Failed to emit event");
println!("[APIPlugin]: Request response: {}", response);
}
Err(e) => println!("[APIPlugin]: Request failed: {}", e),
}
Expand Down Expand Up @@ -175,8 +179,7 @@ macro_rules! specta_builder {
ts::builder()
.commands(collect_commands![make_request::<$e>])
.path(generate_plugin_path(PLUGIN_NAME))
.config(specta::ts::ExportConfig::default()
.formatter(specta::ts::prettier))
.config(specta::ts::ExportConfig::default().formatter(specta::ts::prettier))
//.events(collect_events![RandomNumber])
};
}
Expand Down
73 changes: 73 additions & 0 deletions src/components/AppSettings/DeviceConfig.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { listen } from '@tauri-apps/api/event'
import { createSignal, onCleanup, onMount } from 'solid-js'
import { debug } from 'tauri-plugin-log-api'
import Highlight from '@components/Highlight'
import { ENotificationType } from '@static/types/enums'
import { useAppAPIContext } from '@store/context/api'
import { useAppNotificationsContext } from '@store/context/notifications'
import '@static/highlight.js/styles/atom-one-dark.css'

// TODO: Implement a device config viewer

const DeviceConfig = () => {
const [response, setResponse] = createSignal<object>()
const [config, setConfig] = createSignal<string>()

const { useRequestHook } = useAppAPIContext()
const { addNotification } = useAppNotificationsContext()

const _listen = async () => {
const unlisten = await listen<string>('request-response', (event) => {
const parsedResponse = JSON.parse(event.payload)
setResponse(parsedResponse)
debug(`[NetworkSettings]: ${JSON.stringify(parsedResponse)}`)
})
return unlisten
}

onMount(async () => {
const unlisten = await _listen()
onCleanup(unlisten)
})

const handleGetConfig = async (e: Event) => {
e.preventDefault()

debug(`Response: ${response()}`)

//* Check if there is a response from the device
await useRequestHook('ping', '192.168.4.1')

if (response()!['msg'] !== 'ok') {
addNotification({
title: 'Error',
message:
'Could not connect to device, please connect your PC to the EyeTrackVR Access Point and try again.',
type: ENotificationType.ERROR,
})
return
}

//* Make Request to set network settings
await useRequestHook('getStoredConfig', '192.168.4.1')

if (response()!['msg'] !== 'ok') {
addNotification({
title: 'Error',
message: 'Could not get device config, please try again.',
type: ENotificationType.ERROR,
})
return
}
setConfig(JSON.stringify(response()!['data']))
}

return (
<div class="flex grow rounded-xl flex-col pl-4 pr-4 pb-4 pt-4 bg-[#333742]">
<h1 class="flex justify-start pb-3 text-[#f8f8f2] text-xl font-bold">Device Config</h1>
<Highlight>{config()}</Highlight>
</div>
)
}

export default DeviceConfig
Loading