diff --git a/v3/internal/runtime/desktop/api/application.js b/v3/internal/runtime/desktop/api/application.js new file mode 100644 index 000000000..9ae7ba915 --- /dev/null +++ b/v3/internal/runtime/desktop/api/application.js @@ -0,0 +1,35 @@ +/* + _ __ _ __ +| | / /___ _(_) /____ +| | /| / / __ `/ / / ___/ +| |/ |/ / /_/ / / (__ ) +|__/|__/\__,_/_/_/____/ +The electron alternative for Go +(c) Lea Anthony 2019-present +*/ + +/* jshint esversion: 9 */ + +/** + * The Application API provides methods to interact with the application. + */ +export const Application = { + /** + * Hides the application + */ + Hide: () => { + return wails.Application.Hide(); + }, + /** + * Shows the application + */ + Show: () => { + return wails.Application.Show(); + }, + /** + * Quits the application + */ + Quit: () => { + return wails.Application.Quit(); + }, +}; diff --git a/v3/internal/runtime/desktop/api/clipboard.js b/v3/internal/runtime/desktop/api/clipboard.js new file mode 100644 index 000000000..c18dcbe18 --- /dev/null +++ b/v3/internal/runtime/desktop/api/clipboard.js @@ -0,0 +1,31 @@ +/* + _ __ _ __ +| | / /___ _(_) /____ +| | /| / / __ `/ / / ___/ +| |/ |/ / /_/ / / (__ ) +|__/|__/\__,_/_/_/____/ +The electron alternative for Go +(c) Lea Anthony 2019-present +*/ + +/* jshint esversion: 9 */ + +/** + * The Clipboard API provides methods to interact with the system clipboard. + */ +export const Clipboard = { + /** + * Gets the text from the clipboard + * @returns {Promise} + */ + Text: () => { + return wails.Clipboard.Text(); + }, + /** + * Sets the text on the clipboard + * @param {string} text - text to set in the clipboard + */ + SetText: (text) => { + return wails.Clipboard.SetText(text); + }, +}; diff --git a/v3/internal/runtime/desktop/api/dialogs.js b/v3/internal/runtime/desktop/api/dialogs.js new file mode 100644 index 000000000..e129c31da --- /dev/null +++ b/v3/internal/runtime/desktop/api/dialogs.js @@ -0,0 +1,75 @@ +/* + _ __ _ __ +| | / /___ _(_) /____ +| | /| / / __ `/ / / ___/ +| |/ |/ / /_/ / / (__ ) +|__/|__/\__,_/_/_/____/ +The electron alternative for Go +(c) Lea Anthony 2019-present +*/ + +/* jshint esversion: 9 */ + +/** + * @typedef {import("./types").MessageDialogOptions} MessageDialogOptions + * @typedef {import("./types").OpenDialogOptions} OpenDialogOptions + * @typedef {import("./types").SaveDialogOptions} SaveDialogOptions + */ +/** + * The Dialog API provides methods to interact with system dialogs. + */ +export const Dialog = { + /** + * Shows an info dialog + * @param {MessageDialogOptions} options - options for the dialog + * @returns {Promise} + */ + Info: (options) => { + return wails.Dialog.Info(options); + }, + /** + * Shows a warning dialog + * @param {MessageDialogOptions} options - options for the dialog + * @returns {Promise} + */ + Warning: (options) => { + return wails.Dialog.Warning(options); + }, + /** + * Shows an error dialog + * @param {MessageDialogOptions} options - options for the dialog + * @returns {Promise} + */ + Error: (options) => { + return wails.Dialog.Error(options); + }, + + /** + * Shows a question dialog + * @param {MessageDialogOptions} options - options for the dialog + * @returns {Promise} + */ + Question: (options) => { + return wails.Dialog.Question(options); + }, + + /** + * Shows a file open dialog and returns the files selected by the user. + * A blank string indicates that the dialog was cancelled. + * @param {OpenDialogOptions} options - options for the dialog + * @returns {Promise|Promise} + */ + OpenFile: (options) => { + return wails.Dialog.OpenFile(options); + }, + + /** + * Shows a file save dialog and returns the filename given by the user. + * A blank string indicates that the dialog was cancelled. + * @param {SaveDialogOptions} options - options for the dialog + * @returns {Promise} + */ + SaveFile: (options) => { + return wails.Dialog.SaveFile(options); + }, +}; \ No newline at end of file diff --git a/v3/internal/runtime/desktop/api/events.js b/v3/internal/runtime/desktop/api/events.js new file mode 100644 index 000000000..b705f1da2 --- /dev/null +++ b/v3/internal/runtime/desktop/api/events.js @@ -0,0 +1,68 @@ +/* + _ __ _ __ +| | / /___ _(_) /____ +| | /| / / __ `/ / / ___/ +| |/ |/ / /_/ / / (__ ) +|__/|__/\__,_/_/_/____/ +The electron alternative for Go +(c) Lea Anthony 2019-present +*/ + +/* jshint esversion: 9 */ + + +/** + * The Events API provides methods to interact with the event system. + */ +export const Events = { + /** + * Emit an event + * @param {string} name + * @param {any=} data + */ + Emit: (name, data) => { + return wails.Events.Emit(name, data); + }, + /** + * Subscribe to an event + * @param {string} name - name of the event + * @param {(any) => void} callback - callback to call when the event is emitted + @returns {function()} unsubscribeMethod - method to unsubscribe from the event + */ + On: (name, callback) => { + return wails.Events.On(name, callback); + }, + /** + * Subscribe to an event once + * @param {string} name - name of the event + * @param {(any) => void} callback - callback to call when the event is emitted + * @returns {function()} unsubscribeMethod - method to unsubscribe from the event + */ + Once: (name, callback) => { + return wails.Events.Once(name, callback); + }, + /** + * Subscribe to an event multiple times + * @param {string} name - name of the event + * @param {(any) => void} callback - callback to call when the event is emitted + * @param {number} count - number of times to call the callback + * @returns {Promise} unsubscribeMethod - method to unsubscribe from the event + */ + OnMultiple: (name, callback, count) => { + return wails.Events.OnMultiple(name, callback, count); + }, + /** + * Unsubscribe from an event + * @param {string} name - name of the event to unsubscribe from + * @param {...string} additionalNames - additional names of events to unsubscribe from + */ + Off: (name, ...additionalNames) => { + wails.Events.Off(name, additionalNames); + }, + /** + * Unsubscribe all listeners from all events + */ + OffAll: () => { + wails.Events.OffAll(); + }, +}; diff --git a/v3/internal/runtime/desktop/api/index.js b/v3/internal/runtime/desktop/api/index.js index edc342299..46a46b4b2 100644 --- a/v3/internal/runtime/desktop/api/index.js +++ b/v3/internal/runtime/desktop/api/index.js @@ -9,86 +9,14 @@ The electron alternative for Go */ /* jshint esversion: 9 */ -/** - * @typedef {import("./types").MessageDialogOptions} MessageDialogOptions - * @typedef {import("./types").OpenDialogOptions} OpenDialogOptions - * @typedef {import("./types").SaveDialogOptions} SaveDialogOptions - * @typedef {import("./types").Screen} Screen - * @typedef {import("./types").Size} Size - * @typedef {import("./types").Position} Position - * - */ +import * as Clipboard from "./clipboard"; +import * as Application from "./application"; +import * as Screens from "./screens"; +import * as Dialogs from "./dialogs"; +import * as Events from "./events"; +import * as Window from "./window"; -/** - * The Clipboard API provides methods to interact with the system clipboard. - */ -export const Clipboard = { - /** - * Gets the text from the clipboard - * @returns {Promise} - */ - Text: () => { - return wails.Clipboard.Text(); - }, - /** - * Sets the text on the clipboard - * @param {string} text - text to set in the clipboard - */ - SetText: (text) => { - return wails.Clipboard.SetText(text); - }, -}; - -/** - * The Application API provides methods to interact with the application. - */ -export const Application = { - /** - * Hides the application - */ - Hide: () => { - return wails.Application.Hide(); - }, - /** - * Shows the application - */ - Show: () => { - return wails.Application.Show(); - }, - /** - * Quits the application - */ - Quit: () => { - return wails.Application.Quit(); - }, -}; - -/** - * The Screens API provides methods to interact with the system screens/monitors. - */ -export const Screens = { - /** - * Get the primary screen - * @returns {Promise} - */ - GetPrimary: () => { - return wails.Screens.GetPrimary(); - }, - /** - * Get all screens - * @returns {Promise} - */ - GetAll: () => { - return wails.Screens.GetAll(); - }, - /** - * Get the current screen - * @returns {Promise} - */ - GetCurrent: () => { - return wails.Screens.GetCurrent(); - }, -}; +export { Clipboard, Application, Screens, Dialogs, Events, Window }; /** * Call a plugin method @@ -101,249 +29,4 @@ export const Plugin = (pluginName, methodName, ...args) => { return wails.Plugin(pluginName, methodName, ...args); }; -/** - * The Dialog API provides methods to interact with system dialogs. - */ -export const Dialog = { - /** - * Shows an info dialog - * @param {MessageDialogOptions} options - options for the dialog - * @returns {Promise} - */ - Info: (options) => { - return wails.Dialog.Info(options); - }, - /** - * Shows a warning dialog - * @param {MessageDialogOptions} options - options for the dialog - * @returns {Promise} - */ - Warning: (options) => { - return wails.Dialog.Warning(options); - }, - /** - * Shows an error dialog - * @param {MessageDialogOptions} options - options for the dialog - * @returns {Promise} - */ - Error: (options) => { - return wails.Dialog.Error(options); - }, - /** - * Shows a question dialog - * @param {MessageDialogOptions} options - options for the dialog - * @returns {Promise} - */ - Question: (options) => { - return wails.Dialog.Question(options); - }, - - /** - * Shows a file open dialog and returns the files selected by the user. - * A blank string indicates that the dialog was cancelled. - * @param {OpenDialogOptions} options - options for the dialog - * @returns {Promise|Promise} - */ - OpenFile: (options) => { - return wails.Dialog.OpenFile(options); - }, - - /** - * Shows a file save dialog and returns the filename given by the user. - * A blank string indicates that the dialog was cancelled. - * @param {SaveDialogOptions} options - options for the dialog - * @returns {Promise} - */ - SaveFile: (options) => { - return wails.Dialog.SaveFile(options); - }, -}; - -/** - * The Events API provides methods to interact with the event system. - */ -export const Events = { - /** - * Emit an event - * @param {string} name - * @param {any=} data - */ - Emit: (name, data) => { - return wails.Events.Emit(name, data); - }, - /** - * Subscribe to an event - * @param {string} name - name of the event - * @param {(any) => void} callback - callback to call when the event is emitted - @returns {function()} unsubscribeMethod - method to unsubscribe from the event - */ - On: (name, callback) => { - return wails.Events.On(name, callback); - }, - /** - * Subscribe to an event once - * @param {string} name - name of the event - * @param {(any) => void} callback - callback to call when the event is emitted - * @returns {function()} unsubscribeMethod - method to unsubscribe from the event - */ - Once: (name, callback) => { - return wails.Events.Once(name, callback); - }, - /** - * Subscribe to an event multiple times - * @param {string} name - name of the event - * @param {(any) => void} callback - callback to call when the event is emitted - * @param {number} count - number of times to call the callback - * @returns {Promise} unsubscribeMethod - method to unsubscribe from the event - */ - OnMultiple: (name, callback, count) => { - return wails.Events.OnMultiple(name, callback, count); - }, - /** - * Unsubscribe from an event - * @param {string} name - name of the event to unsubscribe from - * @param {...string} additionalNames - additional names of events to unsubscribe from - */ - Off: (name, ...additionalNames) => { - wails.Events.Off(name, additionalNames); - }, - /** - * Unsubscribe all listeners from all events - */ - OffAll: () => { - wails.Events.OffAll(); - }, -}; - -/** - * The Window API provides methods to interact with the window. - */ -export const Window = { - /** - * Center the window. - */ - Center: () => void wails.Window.Center(), - /** - * Set the window title. - * @param title - */ - SetTitle: (title) => void wails.Window.SetTitle(title), - - /** - * Makes the window fullscreen. - */ - Fullscreen: () => void wails.Window.Fullscreen(), - - /** - * Unfullscreen the window. - */ - UnFullscreen: () => void wails.Window.UnFullscreen(), - - /** - * Set the window size. - * @param {number} width The window width - * @param {number} height The window height - */ - SetSize: (width, height) => void wails.Window.SetSize(width, height), - - /** - * Get the window size. - * @returns {Promise} The window size - */ - Size: () => { - return wails.Window.Size(); - }, - - /** - * Set the window maximum size. - * @param {number} width - * @param {number} height - */ - SetMaxSize: (width, height) => void wails.Window.SetMaxSize(width, height), - - /** - * Set the window minimum size. - * @param {number} width - * @param {number} height - */ - SetMinSize: (width, height) => void wails.Window.SetMinSize(width, height), - - /** - * Set window to be always on top. - * @param {boolean} onTop Whether the window should be always on top - */ - SetAlwaysOnTop: (onTop) => void wails.Window.SetAlwaysOnTop(onTop), - - /** - * Set the window position. - * @param {number} x - * @param {number} y - */ - SetPosition: (x, y) => void wails.Window.SetPosition(x, y), - - /** - * Get the window position. - * @returns {Promise} The window position - */ - Position: () => { - return wails.Window.Position(); - }, - - /** - * Get the screen the window is on. - * @returns {Promise} - */ - Screen: () => { - return wails.Window.Screen(); - }, - - /** - * Hide the window - */ - Hide: () => void wails.Window.Hide(), - - /** - * Maximise the window - */ - Maximise: () => void wails.Window.Maximise(), - - /** - * Show the window - */ - Show: () => void wails.Window.Show(), - - /** - * Close the window - */ - Close: () => void wails.Window.Close(), - - /** - * Toggle the window maximise state - */ - ToggleMaximise: () => void wails.Window.ToggleMaximise(), - - /** - * Unmaximise the window - */ - UnMaximise: () => void wails.Window.UnMaximise(), - - /** - * Minimise the window - */ - Minimise: () => void wails.Window.Minimise(), - - /** - * Unminimise the window - */ - UnMinimise: () => void wails.Window.UnMinimise(), - - /** - * Set the background colour of the window. - * @param {number} r - The red value between 0 and 255 - * @param {number} g - The green value between 0 and 255 - * @param {number} b - The blue value between 0 and 255 - * @param {number} a - The alpha value between 0 and 255 - */ - SetBackgroundColour: (r, g, b, a) => void wails.Window.SetBackgroundColour(r, g, b, a), -}; diff --git a/v3/internal/runtime/desktop/api/package.json b/v3/internal/runtime/desktop/api/package.json index fa19b24bb..7335f6b13 100644 --- a/v3/internal/runtime/desktop/api/package.json +++ b/v3/internal/runtime/desktop/api/package.json @@ -1,6 +1,6 @@ { "name": "@wailsapp/api", - "version": "3.0.0-alpha.3", + "version": "3.0.0-alpha.4", "description": "Wails Runtime API", "main": "index.js", "repository": { diff --git a/v3/internal/runtime/desktop/api/screens.js b/v3/internal/runtime/desktop/api/screens.js new file mode 100644 index 000000000..f1e518d15 --- /dev/null +++ b/v3/internal/runtime/desktop/api/screens.js @@ -0,0 +1,38 @@ +/* + _ __ _ __ +| | / /___ _(_) /____ +| | /| / / __ `/ / / ___/ +| |/ |/ / /_/ / / (__ ) +|__/|__/\__,_/_/_/____/ +The electron alternative for Go +(c) Lea Anthony 2019-present +*/ + +/* jshint esversion: 9 */ + +/** + * The Screens API provides methods to interact with the system screens/monitors. + */ +export const Screens = { + /** + * Get the primary screen + * @returns {Promise} + */ + GetPrimary: () => { + return wails.Screens.GetPrimary(); + }, + /** + * Get all screens + * @returns {Promise} + */ + GetAll: () => { + return wails.Screens.GetAll(); + }, + /** + * Get the current screen + * @returns {Promise} + */ + GetCurrent: () => { + return wails.Screens.GetCurrent(); + }, +}; \ No newline at end of file diff --git a/v3/internal/runtime/desktop/api/window.js b/v3/internal/runtime/desktop/api/window.js new file mode 100644 index 000000000..f6f97aee7 --- /dev/null +++ b/v3/internal/runtime/desktop/api/window.js @@ -0,0 +1,159 @@ +/* + _ __ _ __ +| | / /___ _(_) /____ +| | /| / / __ `/ / / ___/ +| |/ |/ / /_/ / / (__ ) +|__/|__/\__,_/_/_/____/ +The electron alternative for Go +(c) Lea Anthony 2019-present +*/ + +/* jshint esversion: 9 */ + + +/** + * The Window API provides methods to interact with the window. + */ +export const Window = { + /** + * Center the window. + */ + Center: () => void wails.Window.Center(), + /** + * Set the window title. + * @param title + */ + SetTitle: (title) => void wails.Window.SetTitle(title), + + /** + * Makes the window fullscreen. + */ + Fullscreen: () => void wails.Window.Fullscreen(), + + /** + * Unfullscreen the window. + */ + UnFullscreen: () => void wails.Window.UnFullscreen(), + + /** + * Set the window size. + * @param {number} width The window width + * @param {number} height The window height + */ + SetSize: (width, height) => void wails.Window.SetSize(width, height), + + /** + * Get the window size. + * @returns {Promise} The window size + */ + Size: () => { + return wails.Window.Size(); + }, + + /** + * Set the window maximum size. + * @param {number} width + * @param {number} height + */ + SetMaxSize: (width, height) => void wails.Window.SetMaxSize(width, height), + + /** + * Set the window minimum size. + * @param {number} width + * @param {number} height + */ + SetMinSize: (width, height) => void wails.Window.SetMinSize(width, height), + + /** + * Set window to be always on top. + * @param {boolean} onTop Whether the window should be always on top + */ + SetAlwaysOnTop: (onTop) => void wails.Window.SetAlwaysOnTop(onTop), + + /** + * Set the window position relative to the current monitor. + * @param {number} x + * @param {number} y + */ + SetRelativePosition: (x, y) => void wails.Window.SetRelativePosition(x, y), + + /** + * Get the window position relative to the current monitor. + * @returns {Promise} The window position + */ + RelativePosition: () => { + return wails.Window.RelativePosition(); + }, + + /** + * Set the absolute window position. + * @param {number} x + * @param {number} y + */ + SetAbsolutePosition: (x, y) => void wails.Window.SetAbsolutePosition(x, y), + + /** + * Get the absolute window position. + * @returns {Promise} The window position + */ + AbsolutePosition: () => { + return wails.Window.AbsolutePosition(); + }, + + /** + * Get the screen the window is on. + * @returns {Promise} + */ + Screen: () => { + return wails.Window.Screen(); + }, + + /** + * Hide the window + */ + Hide: () => void wails.Window.Hide(), + + /** + * Maximise the window + */ + Maximise: () => void wails.Window.Maximise(), + + /** + * Show the window + */ + Show: () => void wails.Window.Show(), + + /** + * Close the window + */ + Close: () => void wails.Window.Close(), + + /** + * Toggle the window maximise state + */ + ToggleMaximise: () => void wails.Window.ToggleMaximise(), + + /** + * Unmaximise the window + */ + UnMaximise: () => void wails.Window.UnMaximise(), + + /** + * Minimise the window + */ + Minimise: () => void wails.Window.Minimise(), + + /** + * Unminimise the window + */ + UnMinimise: () => void wails.Window.UnMinimise(), + + /** + * Set the background colour of the window. + * @param {number} r - The red value between 0 and 255 + * @param {number} g - The green value between 0 and 255 + * @param {number} b - The blue value between 0 and 255 + * @param {number} a - The alpha value between 0 and 255 + */ + SetBackgroundColour: (r, g, b, a) => void wails.Window.SetBackgroundColour(r, g, b, a), +};