5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 20:03:01 +08:00

Support dynamic loglevel

This commit is contained in:
Lea Anthony 2020-10-10 15:06:27 +11:00
parent ba6538da7c
commit f1cd84d0c8
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
7 changed files with 46 additions and 13 deletions

View File

@ -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",

View File

@ -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<any>;
@ -24,6 +31,10 @@ declare const wailsapp__runtime: {
System: {
DarkModeEnabled(): Promise<boolean>;
OnThemeChange(callback: (darkModeEnabled: boolean) => void): void;
LogLevel(): Store;
};
Store: {
New(name: string, defaultValue?: any): Store;
}
};

View File

@ -36,4 +36,5 @@ function DarkModeEnabled() {
module.exports = {
OnThemeChange: OnThemeChange,
DarkModeEnabled: DarkModeEnabled,
LogLevel: window.wails.System.LogLevel,
};

View File

@ -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": {

View File

@ -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",

View File

@ -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);
})

View File

@ -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 @@
<CodeBlock bind:isJs={isJs} {jsCode} {goCode} title="Logging" >
<div class="logging-form">
<form data-wails-no-drag class="w-400 mw-full"> <!-- w-400 = width: 40rem (400px), mw-full = max-width: 100% -->
<form data-wails-no-drag class="w-500 mw-full"> <!-- w-400 = width: 40rem (400px), mw-full = max-width: 100% -->
<!-- Radio -->
<div class="form-group">
<label for="Debug">Log Level</label>
{#each options as option}
<label for="Debug">Select Logging Level</label>
{#each options as option, index}
{#if index === $logLevel}
<span style="margin-top: 5px; height: 20px; display: inline-block;"><hr style="width: 270px;display: inline-block; vertical-align: middle; margin-right: 10px"/> Current Log Level </span>
{/if}
<div class="custom-radio">
<input type="radio" name="logging" bind:group="{loglevel}" id="{option}" value="{option}">
<label for="{option}">{option}</label>
@ -64,4 +73,5 @@
</form>
</div>
</CodeBlock>
</div>