Skip to content

Commit

Permalink
Enhance type generate to output docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zephraph committed Sep 24, 2024
1 parent 6999db7 commit 7e8fc68
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
21 changes: 19 additions & 2 deletions scripts/generate-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ type NodeIR =
| { type: "union"; members: NodeIR[] }
| {
type: "object";
properties: { key: string; required: boolean; value: NodeIR }[];
properties: {
key: string;
required: boolean;
description?: string;
value: NodeIR;
}[];
}
| { type: "boolean"; optional?: boolean }
| { type: "string"; optional?: boolean }
Expand Down Expand Up @@ -85,6 +90,7 @@ function jsonSchemaToIR(schema: JSONSchema): DocIR {
) => ({
key,
required: node.required?.includes(key) ?? false,
description: (value as JSONSchema).description,
value: nodeToIR(value as JSONSchema),
})),
},
Expand Down Expand Up @@ -141,7 +147,18 @@ function generateTypes(ir: DocIR) {
.with({ type: "literal" }, (node) => w(`"${node.value}"`))
.with({ type: "object" }, (node) => {
wn("{");
for (const { key, required, value } of node.properties) {
for (const { key, required, description, value } of node.properties) {
if (description) {
if (description.includes("\n")) {
wn(`/**`);
for (const line of description.split("\n")) {
wn(` * ${line}`);
}
wn(` */`);
} else {
wn(`/** ${description} */`);
}
}
w(key, required ? ": " : "? : ");
generateNode(value);
wn(",");
Expand Down
3 changes: 3 additions & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ export class WebView implements Disposable {
return returnAck(result);
}

/**
* Returns true if the webview window is visible.
*/
async isVisible(): Promise<boolean> {
const result = await this.#send({ $type: "isVisible" });
return returnResult(result, "boolean");
Expand Down
13 changes: 8 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ struct WebViewOptions {
title: String,
#[serde(flatten)]
target: WebViewTarget,
/// Sets whether the window should be fullscreen.
/// When true, the window will be fullscreen. Default is false.
#[serde(default)]
fullscreen: bool,
/// Sets whether the window should have a border, a title bar, etc.
/// When true, the window will have a border, a title bar, etc. Default is true.
#[serde(default = "default_true")]
decorations: bool,
/// Sets whether the window should be transparent.
#[serde(default)]
transparent: bool,
/// Sets whether all media can be played without user interaction.
/// When true, all media can be played without user interaction. Default is false.
#[serde(default)]
autoplay: bool,
/// Enable or disable web inspector which is usually called devtools.
/// Enable or disable webview devtools.
///
/// Note this only enables devtools to the webview. To open it, you can call WebView::open_devtools, or right click the page and open it from the context menu.
/// Note this only enables devtools to the webview. To open it, you can call `webview.open_devtools()`, or right click the page and open it from the context menu.
#[serde(default)]
devtools: bool,
/// Run the WebView with incognito mode. Note that WebContext will be ingored if incognito is enabled.
Expand Down Expand Up @@ -60,7 +61,9 @@ fn default_true() -> bool {
#[derive(JsonSchema, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
enum WebViewTarget {
/// Url to load in the webview.
Url(String),
/// Html to load in the webview.
Html(String),
}

Expand Down
22 changes: 22 additions & 0 deletions src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,37 @@ import { z } from "npm:zod";

export type WebViewOptions =
& {
/** Sets whether clicking an inactive window also clicks through to the webview. Default is false. */
accept_first_mouse?: boolean;
/** Sets whether all media can be played without user interaction. */
autoplay?: boolean;
/**
* Enables clipboard access for the page rendered on Linux and Windows.
*
* macOS doesn’t provide such method and is always enabled by default. But your app will still need to add menu item accelerators to use the clipboard shortcuts.
*/
clipboard?: boolean;
/** Sets whether the window should have a border, a title bar, etc. */
decorations?: boolean;
/**
* Enable or disable web inspector which is usually called devtools.
*
* Note this only enables devtools to the webview. To open it, you can call WebView::open_devtools, or right click the page and open it from the context menu.
*/
devtools?: boolean;
/** Sets whether the webview should be focused when created. Default is false. */
focused?: boolean;
/** Sets whether the window should be fullscreen. */
fullscreen?: boolean;
/**
* Run the WebView with incognito mode. Note that WebContext will be ingored if incognito is enabled.
*
* Platform-specific: - Windows: Requires WebView2 Runtime version 101.0.1210.39 or higher, does nothing on older versions, see https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes/archive?tabs=dotnetcsharp#10121039
*/
incognito?: boolean;
/** Sets whether host should be able to receive messages from the webview via `window.ipc.postMessage`. */
ipc?: boolean;
/** Sets the title of the window. */
title: string;
transparent?: boolean;
}
Expand Down

0 comments on commit 7e8fc68

Please sign in to comment.