Skip to content

Commit

Permalink
since we have types now we don't need to call them out in the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jpatters committed Dec 14, 2023
1 parent c6f3d89 commit ab82b8c
Showing 1 changed file with 16 additions and 148 deletions.
164 changes: 16 additions & 148 deletions v3/internal/runtime/desktop/api/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Wails API

This package provides a typed Javascript API for Wails applications.
This package provides a typed Javascript API for Wails applications.

It provides methods for the following components:

Expand Down Expand Up @@ -63,7 +63,7 @@ function example() {

#### Message Dialogs

Message dialogs are used to display a message to the user.
Message dialogs are used to display a message to the user.
They can be used to display information, errors, warnings and questions.
Each method returns the button that was pressed by the user.

Expand All @@ -88,9 +88,9 @@ The Save Dialog is used to save a file. It returns the path of the selected file

### Events

The Events API provides access to the Wails event system. This is a global event system
The Events API provides access to the Wails event system. This is a global event system
that can be used to send events between the Go and Javascript.
Events are available to every window in a multi-window application.
Events are available to every window in a multi-window application.
These API methods are specific to the window in which they are called in.

```javascript
Expand All @@ -99,12 +99,12 @@ import { Events } from "@wailsapp/api";
function example() {
// Emit an event
Events.Emit("myevent", { message: "Hello" });

// Subscribe to an event
let unsub = Events.On("otherEvent", (data) => {
console.log("Received event: " + data);
});

// Unsubscribe from the event
unsub();
}
Expand All @@ -118,8 +118,8 @@ Emit an event with optional data.

#### Subscribe

Three methods are provided to subscribe to an event:
- `On(eventName: string, callback: (data: any) => void): () => void` - Subscribe to all events of the given name
Three methods are provided to subscribe to an event:
- `On(eventName: string, callback: (data: any) => void): () => void` - Subscribe to all events of the given name
- `Once(eventName: string, callback: (data: any) => void): () => void` - Subscribe to one event of the given name
- `OnMultiple(eventName: string, callback: (data: any) => void, count: number): () => void` - Subscribe to multiple events of the given name

Expand Down Expand Up @@ -161,7 +161,7 @@ The Window API provides a number of methods that interact with the window in whi

### Plugin

The Plugin API provides access to the Wails plugin system.
The Plugin API provides access to the Wails plugin system.
This method provides the ability to call a plugin method from the frontend.

```javascript
Expand All @@ -179,7 +179,7 @@ function example() {
### Screens

The Screens API provides access to the Wails screen system.

```javascript
import { Screens } from "@wailsapp/api";

Expand All @@ -188,12 +188,12 @@ function example() {
Screens.GetAll().then((screens) => {
console.log("Screens: " + screens);
});

// Get the primary screen
Screens.GetPrimary().then((screen) => {
console.log("Primary screen: " + screen);
});

// Get the screen the window is on
Screens.GetCurrent().then((screen) => {
console.log("Window screen: " + screen);
Expand All @@ -213,151 +213,19 @@ The Application API provides access to the Wails application system.
import { Application } from "@wailsapp/api";

function example() {

// Hide the application
Application.Hide();

// Shopw the application
Application.Show();

// Quit the application
Application.Quit();

}
```

- `Hide: () => void` - Hide the application
- `Show: () => void` - Show the application
- `Quit: () => void` - Quit the application

## Types

This is a comprehensive list of types used by the Wails API.

```typescript

export interface Button {
// The label of the button
Label?: string;
// True if this button is the cancel button (selected when pressing escape)
IsCancel?: boolean;
// True if this button is the default button (selected when pressing enter)
IsDefault?: boolean;
}

interface MessageDialogOptions {
// The title for the dialog
Title?: string;
// The message to display
Message?: string;
// The buttons to use on the dialog
Buttons?: Button[];
}

export interface OpenFileDialogOptions {
// Allows the user to be able to select directories
CanChooseDirectories?: boolean;
// Allows the user to be able to select files
CanChooseFiles?: boolean;
// Provide an option to create directories in the dialog
CanCreateDirectories?: boolean;
// Makes the dialog show hidden files
ShowHiddenFiles?: boolean;
// Whether the dialog should follow filesystem aliases
ResolvesAliases?: boolean;
// Allow the user to select multiple files or directories
AllowsMultipleSelection?: boolean;
// Hide the extension when showing the filename
HideExtension?: boolean;
// Allow the user to select files where the system hides their extensions
CanSelectHiddenExtension?: boolean;
// Treats file packages as directories, e.g. .app on macOS
TreatsFilePackagesAsDirectories?: boolean;
// Allows selection of filetypes not specified in the filters
AllowsOtherFiletypes?: boolean;
// The file filters to use in the dialog
Filters?: FileFilter[];
// The title of the dialog
Title?: string;
// The message to display
Message?: string;
// The label for the select button
ButtonText?: string;
// The default directory to open the dialog in
Directory?: string;
}
export interface FileFilter {
// The display name for the filter, e.g. "Text Files"
DisplayName?: string;
// The pattern to use for the filter, e.g. "*.txt;*.md"
Pattern?: string;
}
export interface SaveFileDialogOptions {
// Provide an option to create directories in the dialog
CanCreateDirectories?: boolean;
// Makes the dialog show hidden files
ShowHiddenFiles?: boolean;
// Allow the user to select files where the system hides their extensions
CanSelectHiddenExtension?: boolean;
// Allows selection of filetypes not specified in the filters
AllowOtherFiletypes?: boolean;
// Hide the extension when showing the filename
HideExtension?: boolean;
// Treats file packages as directories, e.g. .app on macOS
TreatsFilePackagesAsDirectories?: boolean;
// The message to show in the dialog
Message?: string;
// The default directory to open the dialog in
Directory?: string;
// The default filename to use in the dialog
Filename?: string;
// The label for the select button
ButtonText?: string;
}

export interface Screen {
// The screen ID
Id: string;
// The screen name
Name: string;
// The screen scale. 1 = standard resolution, 2: 2x retina, etc.
Scale: number;
// The X position of the screen
X: number;
// The Y position of the screen
Y: number;
// The width and height of the screen
Size: Size;
// The bounds of the screen
Bounds: Rect;
// The work area of the screen
WorkArea: Rect;
// True if this is the primary screen
IsPrimary: boolean;
// The rotation of the screen
Rotation: number;
}
export interface Rect {
X: number;
Y: number;
Width: number;
Height: number;
}

export interface WailsEvent {
// The name of the event
Name: string;
// The data associated with the event
Data?: any;
}

export interface Size {
Width: number;
Height: number;
}
export interface Position {
X: number;
Y: number;
}

```

0 comments on commit ab82b8c

Please sign in to comment.