From f1cd84d0c889ff948834bfee9593fa4103d4dbfc Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 10 Oct 2020 15:06:27 +1100 Subject: [PATCH] Support dynamic loglevel --- v2/internal/runtime/js/runtime/package.json | 2 +- v2/internal/runtime/js/runtime/runtime.d.ts | 11 +++++++++++ v2/internal/runtime/js/runtime/system.js | 1 + v2/test/kitchensink/frontend/package-lock.json | 12 ++++++------ v2/test/kitchensink/frontend/package.json | 4 ++-- v2/test/kitchensink/frontend/src/Store.js | 11 +++++++++++ .../frontend/src/pages/logging/Logging.svelte | 18 ++++++++++++++---- 7 files changed, 46 insertions(+), 13 deletions(-) diff --git a/v2/internal/runtime/js/runtime/package.json b/v2/internal/runtime/js/runtime/package.json index db9e044f6..ec4b5f374 100644 --- a/v2/internal/runtime/js/runtime/package.json +++ b/v2/internal/runtime/js/runtime/package.json @@ -1,6 +1,6 @@ { "name": "@wails/runtime", - "version": "1.0.1", + "version": "1.0.2", "description": "Wails V2 Javascript runtime library", "main": "main.js", "types": "runtime.d.ts", diff --git a/v2/internal/runtime/js/runtime/runtime.d.ts b/v2/internal/runtime/js/runtime/runtime.d.ts index 239cf0445..82d86e065 100644 --- a/v2/internal/runtime/js/runtime/runtime.d.ts +++ b/v2/internal/runtime/js/runtime/runtime.d.ts @@ -1,5 +1,12 @@ export = wailsapp__runtime; +interface Store { + get(): any; + set(value: any): void; + subscribe(callback: (newvalue: any) => void): void; + update(callback: (currentvalue: any) => any): void; +} + declare const wailsapp__runtime: { Browser: { OpenFile(filename: string): Promise; @@ -24,6 +31,10 @@ declare const wailsapp__runtime: { System: { DarkModeEnabled(): Promise; OnThemeChange(callback: (darkModeEnabled: boolean) => void): void; + LogLevel(): Store; + }; + Store: { + New(name: string, defaultValue?: any): Store; } }; diff --git a/v2/internal/runtime/js/runtime/system.js b/v2/internal/runtime/js/runtime/system.js index 68ef94b69..5a28ab30c 100644 --- a/v2/internal/runtime/js/runtime/system.js +++ b/v2/internal/runtime/js/runtime/system.js @@ -36,4 +36,5 @@ function DarkModeEnabled() { module.exports = { OnThemeChange: OnThemeChange, DarkModeEnabled: DarkModeEnabled, + LogLevel: window.wails.System.LogLevel, }; \ No newline at end of file diff --git a/v2/test/kitchensink/frontend/package-lock.json b/v2/test/kitchensink/frontend/package-lock.json index a2c0e2ce3..c1e84c694 100644 --- a/v2/test/kitchensink/frontend/package-lock.json +++ b/v2/test/kitchensink/frontend/package-lock.json @@ -124,9 +124,9 @@ } }, "@wails/runtime": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@wails/runtime/-/runtime-1.0.1.tgz", - "integrity": "sha512-zAhPm1eTZ7f7IsE2II0HoDvCtnttj7ah3gzCTpoAd9zltuoao6aU7m1RMsuqLvd/zvdsA4bKywmVjsa2O4zJpQ==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@wails/runtime/-/runtime-1.0.2.tgz", + "integrity": "sha512-Af/VqrJz7so3t7tJT83ZxlL7AqgfHIfrIC+ZH80MQsNmcNmYiyB3rwxMxSWCqwmf2iDWUZx7hZ+XfytAPhH8PA==", "dev": true }, "alphanum-sort": { @@ -902,9 +902,9 @@ } }, "focus-visible": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/focus-visible/-/focus-visible-5.1.0.tgz", - "integrity": "sha512-nPer0rjtzdZ7csVIu233P2cUm/ks/4aVSI+5KUkYrYpgA7ujgC3p6J7FtFU+AIMWwnwYQOB/yeiOITxFeYIXiw==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/focus-visible/-/focus-visible-5.2.0.tgz", + "integrity": "sha512-Rwix9pBtC1Nuy5wysTmKy+UjbDJpIfg8eHjw0rjZ1mX4GNLz1Bmd16uDpI3Gk1i70Fgcs8Csg2lPm8HULFg9DQ==", "dev": true }, "fs.realpath": { diff --git a/v2/test/kitchensink/frontend/package.json b/v2/test/kitchensink/frontend/package.json index cdce03914..af9851fb9 100644 --- a/v2/test/kitchensink/frontend/package.json +++ b/v2/test/kitchensink/frontend/package.json @@ -10,8 +10,8 @@ "devDependencies": { "@rollup/plugin-commonjs": "^11.0.0", "@rollup/plugin-node-resolve": "^7.0.0", - "@wails/runtime": "^1.0.1", - "focus-visible": "^5.0.2", + "@wails/runtime": "^1.0.2", + "focus-visible": "^5.2.0", "halfmoon": "^1.1.1", "postcss": "^8.1.1", "postcss-import": "^12.0.1", diff --git a/v2/test/kitchensink/frontend/src/Store.js b/v2/test/kitchensink/frontend/src/Store.js index 9dba559ae..b5e2d8475 100644 --- a/v2/test/kitchensink/frontend/src/Store.js +++ b/v2/test/kitchensink/frontend/src/Store.js @@ -9,3 +9,14 @@ export let darkMode = writable(runtime.System.DarkModeEnabled()); runtime.System.OnThemeChange( (isDarkMode) => { darkMode.set(isDarkMode); }); + +// LogLevel +// Create a svelte store for the logLevel and initialise with +// the loglevel stored in the Wails runtime +export let logLevel = writable(runtime.System.LogLevel.get()); + +// Bind updates to the Wails store to the Svelte Store +runtime.System.LogLevel.subscribe( (newValue) => { + logLevel.set(newValue); +}) + diff --git a/v2/test/kitchensink/frontend/src/pages/logging/Logging.svelte b/v2/test/kitchensink/frontend/src/pages/logging/Logging.svelte index f73737368..7241a11aa 100644 --- a/v2/test/kitchensink/frontend/src/pages/logging/Logging.svelte +++ b/v2/test/kitchensink/frontend/src/pages/logging/Logging.svelte @@ -5,12 +5,18 @@ import jsCode from './code.jsx'; import goCode from './code.go'; + import { logLevel } from '../../Store'; + var message = ''; var isJs = false; - var options = ["Print", "Trace", "Debug", "Info", "Warning", "Error", "Fatal"]; + var options = ["Trace", "Debug", "Info", "Warning", "Error", "Fatal", "Print"]; var loglevel = options[0]; + + // This is the current log level in text form + $: currentLoglevelText = options[$logLevel]; + $: lang = isJs ? 'Javascript' : 'Go'; function sendLogMessage() { @@ -42,11 +48,14 @@
-
+
- - {#each options as option} + + {#each options as option, index} + {#if index === $logLevel} +
Current Log Level
+ {/if}
@@ -64,4 +73,5 @@
+