diff --git a/mise.toml b/mise.toml index 7632be1..721f2b4 100644 --- a/mise.toml +++ b/mise.toml @@ -31,6 +31,7 @@ run = "deno run -A scripts/sync-versions.ts" [tasks."gen:rust"] description = "Generate JSON schemas from the rust code" run = "cargo run --bin generate_schemas" +depends_post = ["format:rust"] sources = ["src/**/*.rs", "Cargo.toml", "Cargo.lock"] outputs = ["schemas/*.json"] @@ -38,6 +39,7 @@ outputs = ["schemas/*.json"] description = "Generate the deno client" run = "deno run -A scripts/generate-schema/index.ts --language typescript" depends = ["gen:rust"] +depends_post = ["format:deno"] sources = ["schemas/*", "scripts/generate-schema.ts"] outputs = ["src/clients/deno/schemas/*.ts"] @@ -45,6 +47,7 @@ outputs = ["src/clients/deno/schemas/*.ts"] description = "Generate the python client" run = "deno run -A scripts/generate-schema/index.ts --language python" depends = ["gen:rust"] +depends_post = ["format:python"] sources = ["schemas/*", "scripts/generate-schema.ts"] outputs = ["src/clients/python/src/justbe_webview/schemas/*.py"] diff --git a/src/clients/python/src/justbe_webview/schemas.py b/src/clients/python/src/justbe_webview/schemas.py index 51455df..e4f24a6 100644 --- a/src/clients/python/src/justbe_webview/schemas.py +++ b/src/clients/python/src/justbe_webview/schemas.py @@ -42,229 +42,281 @@ "StartedNotification", "StringResultType", "WindowSize", - "WindowSizeStates" + "WindowSizeStates", ] -class StartedNotification(msgspec.Struct, tag_field="$type", tag="started"): + +class StartedNotification(msgspec.Struct, tag_field="$type", tag="started"): version: str - """The version of the webview binary""" + """The version of the webview binary""" + -class IpcNotification(msgspec.Struct, tag_field="$type", tag="ipc"): +class IpcNotification(msgspec.Struct, tag_field="$type", tag="ipc"): message: str - """The message sent from the webview UI to the client.""" + """The message sent from the webview UI to the client.""" + + +class ClosedNotification(msgspec.Struct, tag_field="$type", tag="closed"): + pass -class ClosedNotification(msgspec.Struct, tag_field="$type", tag="closed"): - pass -Notification = Union[StartedNotification, IpcNotification, ClosedNotification] +Notification = Union[StartedNotification, IpcNotification, ClosedNotification] """ Messages that are sent unbidden from the webview to the client. -""" -class SizeWithScale(msgspec.Struct, omit_defaults=True): +""" + + +class SizeWithScale(msgspec.Struct, omit_defaults=True): height: float - """The height of the window in logical pixels.""" + """The height of the window in logical pixels.""" scaleFactor: float - """The ratio between physical and logical sizes.""" + """The ratio between physical and logical sizes.""" width: float - """The width of the window in logical pixels.""" + """The width of the window in logical pixels.""" -class StringResultType(msgspec.Struct, tag_field="$type", tag="string"): + +class StringResultType(msgspec.Struct, tag_field="$type", tag="string"): value: str -class BooleanResultType(msgspec.Struct, tag_field="$type", tag="boolean"): + +class BooleanResultType(msgspec.Struct, tag_field="$type", tag="boolean"): value: bool -class FloatResultType(msgspec.Struct, tag_field="$type", tag="float"): + +class FloatResultType(msgspec.Struct, tag_field="$type", tag="float"): value: float -class SizeResultType(msgspec.Struct, tag_field="$type", tag="size"): + +class SizeResultType(msgspec.Struct, tag_field="$type", tag="size"): value: SizeWithScale -ResultType = Union[StringResultType, BooleanResultType, FloatResultType, SizeResultType] + +ResultType = Union[StringResultType, BooleanResultType, FloatResultType, SizeResultType] """ Types that can be returned from webview results. -""" -class AckResponse(msgspec.Struct, tag_field="$type", tag="ack"): +""" + + +class AckResponse(msgspec.Struct, tag_field="$type", tag="ack"): id: int -class ResultResponse(msgspec.Struct, tag_field="$type", tag="result"): + +class ResultResponse(msgspec.Struct, tag_field="$type", tag="result"): id: int result: ResultType -class ErrResponse(msgspec.Struct, tag_field="$type", tag="err"): + +class ErrResponse(msgspec.Struct, tag_field="$type", tag="err"): id: int message: str -Response = Union[AckResponse, ResultResponse, ErrResponse] + +Response = Union[AckResponse, ResultResponse, ErrResponse] """ Responses from the webview to the client. -""" -class NotificationMessage(msgspec.Struct, tag_field="$type", tag="notification"): +""" + + +class NotificationMessage(msgspec.Struct, tag_field="$type", tag="notification"): data: Notification -class ResponseMessage(msgspec.Struct, tag_field="$type", tag="response"): + +class ResponseMessage(msgspec.Struct, tag_field="$type", tag="response"): data: Response -Message = Union[NotificationMessage, ResponseMessage] + +Message = Union[NotificationMessage, ResponseMessage] """ Complete definition of all outbound messages from the webview to the client. -""" - +""" -class ContentUrl(msgspec.Struct, kw_only=True, omit_defaults=True): +class ContentUrl(msgspec.Struct, kw_only=True, omit_defaults=True): url: str - """Url to load in the webview. Note: Don't use data URLs here, as they are not supported. Use the `html` field instead.""" + """Url to load in the webview. Note: Don't use data URLs here, as they are not supported. Use the `html` field instead.""" headers: Union[dict[str, str], None] = None - """Optional headers to send with the request.""" + """Optional headers to send with the request.""" -class ContentHtml(msgspec.Struct, kw_only=True, omit_defaults=True): + +class ContentHtml(msgspec.Struct, kw_only=True, omit_defaults=True): html: str - """Html to load in the webview.""" + """Html to load in the webview.""" origin: Union[str, None] = None - """What to set as the origin of the webview when loading html.""" + """What to set as the origin of the webview when loading html.""" + -Content = Union[ContentUrl, ContentHtml] +Content = Union[ContentUrl, ContentHtml] """ The content to load into the webview. -""" -class Size(msgspec.Struct, omit_defaults=True): +""" + + +class Size(msgspec.Struct, omit_defaults=True): height: float - """The height of the window in logical pixels.""" + """The height of the window in logical pixels.""" width: float - """The width of the window in logical pixels.""" + """The width of the window in logical pixels.""" + + +class WindowSizeStates(str, Enum): + maximized = "maximized" + fullscreen = "fullscreen" + + +WindowSize = Union[WindowSizeStates, Size] + -class WindowSizeStates(str, Enum): - maximized = "maximized" - fullscreen = "fullscreen" +class Options(msgspec.Struct, omit_defaults=True): + """ + Options for creating a webview. + """ -WindowSize = Union[WindowSizeStates, Size] -class Options(msgspec.Struct, omit_defaults=True): - """ - Options for creating a webview. - """ title: str - """Sets the title of the window.""" + """Sets the title of the window.""" acceptFirstMouse: Union[bool, None] = None - """Sets whether clicking an inactive window also clicks through to the webview. Default is false.""" + """Sets whether clicking an inactive window also clicks through to the webview. Default is false.""" autoplay: Union[bool, None] = None - """When true, all media can be played without user interaction. Default is false.""" + """When true, all media can be played without user interaction. Default is false.""" clipboard: Union[bool, None] = None """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.""" +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.""" decorations: Union[bool, None] = None - """When true, the window will have a border, a title bar, etc. Default is true.""" + """When true, the window will have a border, a title bar, etc. Default is true.""" devtools: Union[bool, None] = None """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.""" focused: Union[bool, None] = None - """Sets whether the webview should be focused when created. Default is false.""" + """Sets whether the webview should be focused when created. Default is false.""" incognito: Union[bool, None] = None """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""" +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""" initializationScript: Union[str, None] = None - """Run JavaScript code when loading new pages. When the webview loads a new page, this code will be executed. It is guaranteed that the code is executed before window.onload.""" + """Run JavaScript code when loading new pages. When the webview loads a new page, this code will be executed. It is guaranteed that the code is executed before window.onload.""" ipc: Union[bool, None] = None - """Sets whether host should be able to receive messages from the webview via `window.ipc.postMessage`.""" + """Sets whether host should be able to receive messages from the webview via `window.ipc.postMessage`.""" load: Union[Content, None] = None - """The content to load into the webview.""" + """The content to load into the webview.""" size: Union[WindowSize, None] = None - """The size of the window.""" + """The size of the window.""" transparent: Union[bool, None] = None - """Sets whether the window should be transparent.""" + """Sets whether the window should be transparent.""" userAgent: Union[str, None] = None - """Sets the user agent to use when loading pages.""" + """Sets the user agent to use when loading pages.""" - - -class GetVersionRequest(msgspec.Struct, tag_field="$type", tag="getVersion"): +class GetVersionRequest(msgspec.Struct, tag_field="$type", tag="getVersion"): id: int - """The id of the request.""" + """The id of the request.""" -class EvalRequest(msgspec.Struct, tag_field="$type", tag="eval"): + +class EvalRequest(msgspec.Struct, tag_field="$type", tag="eval"): id: int - """The id of the request.""" + """The id of the request.""" js: str - """The javascript to evaluate.""" + """The javascript to evaluate.""" + -class SetTitleRequest(msgspec.Struct, tag_field="$type", tag="setTitle"): +class SetTitleRequest(msgspec.Struct, tag_field="$type", tag="setTitle"): id: int - """The id of the request.""" + """The id of the request.""" title: str - """The title to set.""" + """The title to set.""" -class GetTitleRequest(msgspec.Struct, tag_field="$type", tag="getTitle"): + +class GetTitleRequest(msgspec.Struct, tag_field="$type", tag="getTitle"): id: int - """The id of the request.""" + """The id of the request.""" + -class SetVisibilityRequest(msgspec.Struct, tag_field="$type", tag="setVisibility"): +class SetVisibilityRequest(msgspec.Struct, tag_field="$type", tag="setVisibility"): id: int - """The id of the request.""" + """The id of the request.""" visible: bool - """Whether the window should be visible or hidden.""" + """Whether the window should be visible or hidden.""" + -class IsVisibleRequest(msgspec.Struct, tag_field="$type", tag="isVisible"): +class IsVisibleRequest(msgspec.Struct, tag_field="$type", tag="isVisible"): id: int - """The id of the request.""" + """The id of the request.""" -class OpenDevToolsRequest(msgspec.Struct, tag_field="$type", tag="openDevTools"): + +class OpenDevToolsRequest(msgspec.Struct, tag_field="$type", tag="openDevTools"): id: int - """The id of the request.""" + """The id of the request.""" + -class GetSizeRequest(msgspec.Struct, tag_field="$type", tag="getSize"): +class GetSizeRequest(msgspec.Struct, tag_field="$type", tag="getSize"): id: int - """The id of the request.""" + """The id of the request.""" include_decorations: Union[bool, None] = None - """Whether to include the title bar and borders in the size measurement.""" + """Whether to include the title bar and borders in the size measurement.""" -class SetSizeRequest(msgspec.Struct, tag_field="$type", tag="setSize"): + +class SetSizeRequest(msgspec.Struct, tag_field="$type", tag="setSize"): id: int - """The id of the request.""" + """The id of the request.""" size: Size - """The size to set.""" + """The size to set.""" + -class FullscreenRequest(msgspec.Struct, tag_field="$type", tag="fullscreen"): +class FullscreenRequest(msgspec.Struct, tag_field="$type", tag="fullscreen"): id: int - """The id of the request.""" + """The id of the request.""" fullscreen: Union[bool, None] = None - """Whether to enter fullscreen mode. If left unspecified, the window will enter fullscreen mode if it is not already in fullscreen mode or exit fullscreen mode if it is currently in fullscreen mode.""" + """Whether to enter fullscreen mode. If left unspecified, the window will enter fullscreen mode if it is not already in fullscreen mode or exit fullscreen mode if it is currently in fullscreen mode.""" -class MaximizeRequest(msgspec.Struct, tag_field="$type", tag="maximize"): + +class MaximizeRequest(msgspec.Struct, tag_field="$type", tag="maximize"): id: int - """The id of the request.""" + """The id of the request.""" maximized: Union[bool, None] = None - """Whether to maximize the window. If left unspecified, the window will be maximized if it is not already maximized or restored if it was previously maximized.""" + """Whether to maximize the window. If left unspecified, the window will be maximized if it is not already maximized or restored if it was previously maximized.""" + -class MinimizeRequest(msgspec.Struct, tag_field="$type", tag="minimize"): +class MinimizeRequest(msgspec.Struct, tag_field="$type", tag="minimize"): id: int - """The id of the request.""" + """The id of the request.""" minimized: Union[bool, None] = None - """Whether to minimize the window. If left unspecified, the window will be minimized if it is not already minimized or restored if it was previously minimized.""" + """Whether to minimize the window. If left unspecified, the window will be minimized if it is not already minimized or restored if it was previously minimized.""" + -class LoadHtmlRequest(msgspec.Struct, tag_field="$type", tag="loadHtml"): +class LoadHtmlRequest(msgspec.Struct, tag_field="$type", tag="loadHtml"): html: str - """HTML to set as the content of the webview.""" + """HTML to set as the content of the webview.""" id: int - """The id of the request.""" + """The id of the request.""" origin: Union[str, None] = None - """What to set as the origin of the webview when loading html. If not specified, the origin will be set to the value of the `origin` field when the webview was created.""" + """What to set as the origin of the webview when loading html. If not specified, the origin will be set to the value of the `origin` field when the webview was created.""" -class LoadUrlRequest(msgspec.Struct, tag_field="$type", tag="loadUrl"): + +class LoadUrlRequest(msgspec.Struct, tag_field="$type", tag="loadUrl"): id: int - """The id of the request.""" + """The id of the request.""" url: str - """URL to load in the webview.""" + """URL to load in the webview.""" headers: Union[dict[str, str], None] = None - """Optional headers to send with the request.""" - -Request = Union[GetVersionRequest, EvalRequest, SetTitleRequest, GetTitleRequest, SetVisibilityRequest, IsVisibleRequest, OpenDevToolsRequest, GetSizeRequest, SetSizeRequest, FullscreenRequest, MaximizeRequest, MinimizeRequest, LoadHtmlRequest, LoadUrlRequest] + """Optional headers to send with the request.""" + + +Request = Union[ + GetVersionRequest, + EvalRequest, + SetTitleRequest, + GetTitleRequest, + SetVisibilityRequest, + IsVisibleRequest, + OpenDevToolsRequest, + GetSizeRequest, + SetSizeRequest, + FullscreenRequest, + MaximizeRequest, + MinimizeRequest, + LoadHtmlRequest, + LoadUrlRequest, +] """ Explicit requests from the client to the webview. -""" - - - +"""