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: log plugin v2 #1509

Open
wants to merge 4 commits into
base: v2
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions examples/api/src-tauri/src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::sync::atomic::{AtomicBool, Ordering};
use tauri::{
menu::{Menu, MenuItem},
tray::{ClickType, TrayIconBuilder},
tray::{MouseButton, TrayIconBuilder, TrayIconEvent},
Manager, Runtime, WebviewUrl, WebviewWindowBuilder,
};

Expand Down Expand Up @@ -106,14 +106,21 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {

_ => {}
})
.on_tray_icon_event(|tray, event| {
if event.click_type == ClickType::Left {
.on_tray_icon_event(|tray, event| match event {
TrayIconEvent::Click {
id,
position,
rect,
button,
button_state,
} if button == MouseButton::Left => {
let app = tray.app_handle();
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
}
_ => {}
})
.build(app);

Expand Down
6 changes: 6 additions & 0 deletions examples/api/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import WebRTC from "./views/WebRTC.svelte";
import Scanner from "./views/Scanner.svelte";
import Biometric from "./views/Biometric.svelte";
import Log from "./views/Log.svelte";

import { onMount, tick } from "svelte";
import { ask } from "@tauri-apps/plugin-dialog";
Expand Down Expand Up @@ -120,6 +121,11 @@
component: Biometric,
icon: "i-ph-scan",
},
{
label: "Log",
component: Log,
icon: "i-ph-scan",
},
];

let selected = views[0];
Expand Down
297 changes: 297 additions & 0 deletions examples/api/src/views/Log.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,297 @@
<script>
function test() {
// This file is used to check the output of exposed console methods.
// All top-level exposed functions of the official console API are included.
// https://console.spec.whatwg.org/#console-namespace

// Includes all tests in https://github.com/ioannad/console/blob/main/NOTES.md

// This test should be run first because it contains a `console.clear` which may
// influence subsequent tests.
function test_console_methods_basic() {
console.log(
"------- Testing console methods for basic functionality -------",
);

// assert
console.log(' --- console.assert(true, "should not be logged");');
console.assert(true, "should not be logged");

console.log(
' --- console.assert(false, "Failed assertion logged.", "one", "two", 3);',
);
console.assert(false, "Failed assertion logged.", "one", "two", 3);

console.log(
" --- console.assert(console.assert(true) == undefined);",
);
console.assert(console.assert(true) == undefined);

console.log(' --- console.log("does this appear?");');
console.log("does this appear?"); // it does when streams are being redirected to files.

console.log(' --- console.group("foo");');
console.group("foo");

console.log(' --- console.log("should not appear");');
console.log("should not appear"); // still does when streams are being redirected to files.

console.log(" --- console.clear();");
console.clear();

console.log(' --- console.debug("debug");');
console.debug("debug");

console.log(' --- console.error("error");');
console.error("error");

console.log(' --- console.info("info");');
console.info("info");

console.log(' --- console.log("log");');
console.log("log");

console.log(' --- console.warn("warn");');
console.warn("warn");

// Due to some weird formatting difference between native node.js and deno run
// outputs, suspecting that console.clear somehow left open the group that was
// created before the clearing of the console.

console.log(" --- console.groupEnd();");
console.groupEnd();

function tracedfoo() {
function tracedbar() {
console.trace();
}
tracedbar();
}

console.log(" --- tracedfoo();");
tracedfoo();

console.log(' --- console.dir(["dir", 2]);');
console.dir(["dir", 2]);

// ~data~ is any object or DOM element - Nodejs documentation says that it treats ~dirxml~ as ~log~.
console.log(' --- console.dirxml([1,2], "default", null);');
console.dirxml([1, 2], "default", null);

// Grouping
console.log(' --- console.group("bar");');
console.group("bar");

console.log(' --- console.groupCollapsed("baz");');
console.groupCollapsed("baz");

console.log(" --- console.groupEnd();");
console.groupEnd();

console.log(" --- console.groupEnd();");
console.groupEnd();

console.log(function () {});
console.log(async function anAsyncFunction(a, b, c) {});
console.log(function* aGeneratorFunction() {});
console.log(async function* anAsyncGeneratorFunction() {});

console.log(new Int8Array([1, 2, 3, 4]));
console.log(new Uint8Array([1, 2, 3, 4]));
console.log(new Uint8ClampedArray([1, 2, 3, 4]));
console.log(new Int16Array([1, 2, 3, 4]));
console.log(new Uint16Array([1, 2, 3, 4]));
console.log(new Int32Array([1, 2, 3, 4]));
console.log(new Uint32Array([1, 2, 3, 4]));
console.log(new Float32Array([1, 2, 3, 4]));
console.log(new Float64Array([1, 2, 3, 4]));
console.log(new BigInt64Array([1n, 2n, 3n, 4n]));
console.log(new BigUint64Array([1n, 2n, 3n, 4n]));

console.log(
new Map([
["a", 1],
["b", 2],
]),
);
console.log(new Set([1, 2, 3, 4]));
}

function test_formatter() {
// Initially taken from https://github.com/ioannad/console/blob/main/NOTES.md

console.log("------- Testing formatter -------");

// Float formatting of integers
console.log(' --- console.log("%f", 23);');
console.log("%f", 23);

console.log(
" --- console.log('bjoern and robert are born on the %fst dec', 1.234);",
);
console.log("bjoern and robert are born on the %fst dec", 1.234);

console.log(' --- console.log("%f", null);');
console.log("%f", null);

// Integer formatting of null
console.log(' --- console.log("%d", null);');
console.log("%d", null);

// Integer formatting of a string
console.log(
" --- console.log('bjoern and robert are born on the %dst dec', \"foo\");",
);
console.log("bjoern and robert are born on the %dst dec", "foo");

// not enough arguments to interpolate all placeholders
console.log(' --- console.log("%s %snewword", "duck");');
console.log("%s %snewword", "duck");

// console.assert - string formatter in assert
console.log(
' --- console.assert(false, "robert keeps %s on his balcony", "plaices");',
);
console.assert(false, "robert keeps %s on his balcony", "plaices");

// console.assert - string formatter of an object
console.log(
' --- console.assert(false, "robert keeps %s on his balcony", {foo: "bar"});',
);
console.assert(false, "robert keeps %s on his balcony", {
foo: "bar",
});
}

function test_console_table() {
console.log("------- Testing console.table -------");

// console.table - printing of strings
console.log(
' --- console.table("the plaice living on the balcony");',
);
console.table("the plaice living on the balcony");

// console.table - Sets
console.log(
' --- console.table(new Set([{name: "terin", owner: false}, {name: "robert", owner: false}, {name: "domenic", owner: true}]));',
);
console.table(
new Set([
{ name: "terin", owner: false },
{ name: "robert", owner: false },
{ name: "domenic", owner: true },
]),
);

// console.table - Multiple Arguments
console.log(
" --- console.table([[1, 2, 3, 4], [5, 6, 7, 8]], 2, 3);",
);
// console.log('Fails in Deno repl 1.34.2'); // ------------------------------ FAIL
console.table(
[
[1, 2, 3, 4],
[5, 6, 7, 8],
],
2,
3,
);
}

function test_console_count() {
console.log("------- Testing console.count -------");

// Basic functionality

console.log(" --- console.count();");
console.count();

console.log(' --- console.countReset("default");');
console.countReset("default");

console.log(' --- console.count("default");');
console.count("default");

// console.count - counters and label repetition

console.log(" --- console.count('foo');");
console.count("foo");
console.log(" --- console.count('foo');");
console.count("foo");

// console.count - objects / arrays

console.log(" --- console.count({});");
console.count({});

console.log(" --- console.count([]);");
console.count([]);

// console.count - no arguments / empty strings / null / undefined

console.log(" --- console.count();");
console.count();

console.log(' --- console.count("");');
console.count("");

console.log(" --- console.count(null);");
console.count(null);

console.log(" --- console.count(undefined);");
console.count(undefined);
}

function test_console_timing() {
console.log("------- Testing console.time -------");

console.log(" --- console.time();");
console.time();

console.log(" --- console.time(undefined);");
console.time(undefined);

console.log(" --- console.time(null);");
console.time(null);

console.log("------- Testing console.timeLog -------");

console.log(" --- console.timeLog();");
console.timeLog();

console.log(" --- console.timeLog(undefined);");
console.timeLog(undefined);

console.log(" --- console.timeLog(null);");
console.timeLog(null);

console.log("------- Testing console.timeEnd -------");

console.log(" --- console.timeEnd();");
console.timeEnd();

console.log(" --- console.timeEnd(null);");
console.timeEnd(null);

console.log(" --- console.timeEnd(undefined);");
console.timeEnd(undefined);

console.log(" --- Finish testing console.time");
}

// This should go first because it contains a "clear" that may mees up the output in some environments.
test_console_methods_basic();

test_formatter();
test_console_count();
test_console_timing();

// This should go last because its last command fails in Deno 1.34.2 which stops execution.
test_console_table(); // **TODO** consider moving this elsewhere and/or running it separately from the other tests

console.log("---------------------------TEST END.");
}
</script>

<button class="btn" on:click={test}> Test </button>
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"CVE-2023-46115"
]
}
}
},
"packageManager": "pnpm@9.4.0+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a"
}
1 change: 1 addition & 0 deletions plugins/log/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
/.tauri
!/dist-js
2 changes: 1 addition & 1 deletion plugins/log/api-iife.js

Large diffs are not rendered by default.

Loading
Loading