generated from dave/wails-template
Implement fetching brightness from api
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Header from "$lib/components/Header.svelte";
|
|
||||||
import Router from "$lib/router/Router.svelte";
|
import Router from "$lib/router/Router.svelte";
|
||||||
import { Toaster } from "svelte-sonner";
|
import { Toaster } from "svelte-sonner";
|
||||||
import { Close } from '$wails/main/App'
|
import { Close } from '$wails/main/App'
|
||||||
|
@@ -1,34 +1,21 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
export let brightnessChange = (brightness) => {};
|
export let brightnessChange = (brightness: number) => {};
|
||||||
|
export let brightness: number;
|
||||||
|
|
||||||
let brightness = 50; // Default brightness level
|
function handleBrightnessChange(event) {
|
||||||
|
brightness = event.target.value;
|
||||||
function handleBrightnessChange(event) {
|
brightnessChange(brightness);
|
||||||
brightness = event.target.value;
|
}
|
||||||
brightnessChange(brightness); // Call the callback with the current brightness
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col items-center justify-center p-4">
|
<div class="flex flex-col items-center justify-center p-4">
|
||||||
<div
|
<div
|
||||||
class="w-48 h-48 rounded-full overflow-hidden mb-4"
|
class="w-48 h-48 rounded-full overflow-hidden mb-4"
|
||||||
style="background-color: #FFD700; filter: brightness({brightness}%)"
|
style="background-color: #FFD700; filter: brightness({brightness}%)"
|
||||||
>
|
>
|
||||||
<svg
|
<svg class="w-48 h-48 fill-current text-yellow-800" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
class="w-48 h-48 fill-current text-yellow-800"
|
<path d="M12 2L2 22h20Z" />
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
</svg>
|
||||||
viewBox="0 0 24 24"
|
</div>
|
||||||
>
|
<input type="range" min="0" max="100" step="1" value={brightness} on:input={handleBrightnessChange} class="w-4/5" />
|
||||||
<path d="M12 2L2 22h20Z" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
min="0"
|
|
||||||
max="100"
|
|
||||||
step="1"
|
|
||||||
value={brightness}
|
|
||||||
on:input={handleBrightnessChange}
|
|
||||||
class="w-4/5"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
@@ -1,10 +1,23 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Lamp from "../../components/Lamp.svelte";
|
import Lamp from "../../components/Lamp.svelte";
|
||||||
|
import { GetLamps } from "$wails/main/App";
|
||||||
|
|
||||||
|
let lamps: number[] = [0, 0];
|
||||||
|
GetLamps().then(apilamps => {
|
||||||
|
console.log(apilamps);
|
||||||
|
for (let i = 0; i < apilamps.length; i++) {
|
||||||
|
lamps[i] = Number(apilamps[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleBrightnessChange(brightness: number) {
|
||||||
|
console.log(brightness);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-row justify-center items-center">
|
<div class="flex flex-row justify-center items-center">
|
||||||
<Lamp />
|
<Lamp brightness={lamps[0]} brightnessChange={handleBrightnessChange} />
|
||||||
<Lamp />
|
<Lamp brightness={lamps[1]} brightnessChange={handleBrightnessChange} />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
4
frontend/wailsjs/go/main/App.d.ts
vendored
4
frontend/wailsjs/go/main/App.d.ts
vendored
@@ -2,3 +2,7 @@
|
|||||||
// This file is automatically generated. DO NOT EDIT
|
// This file is automatically generated. DO NOT EDIT
|
||||||
|
|
||||||
export function Close():Promise<void>;
|
export function Close():Promise<void>;
|
||||||
|
|
||||||
|
export function GetLamps():Promise<Array<string>>;
|
||||||
|
|
||||||
|
export function SetLampBrightness(arg1:number,arg2:number):Promise<string>;
|
||||||
|
@@ -5,3 +5,11 @@
|
|||||||
export function Close() {
|
export function Close() {
|
||||||
return window['go']['main']['App']['Close']();
|
return window['go']['main']['App']['Close']();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function GetLamps() {
|
||||||
|
return window['go']['main']['App']['GetLamps']();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SetLampBrightness(arg1, arg2) {
|
||||||
|
return window['go']['main']['App']['SetLampBrightness'](arg1, arg2);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user