5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 21:43:19 +08:00

[v2] [broken - WIP] Major refactor of runtime in progress

This commit is contained in:
Lea Anthony 2021-07-19 23:04:36 +10:00
parent f02c140709
commit 06ebe5f51f
21 changed files with 10 additions and 1165 deletions

View File

@ -1,24 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
import { SendMessage } from 'ipc';
/**
* Opens the given URL / filename in the system browser
*
* @export
* @param {string} target
* @returns
*/
export function Open(target) {
return SendMessage('RBO' + target);
}

View File

@ -1,92 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
import { SystemCall } from './calls';
/**
* @type {Object} OpenDialogOptions
* @param {string} [DefaultDirectory=""]
* @param {string} [DefaultFilename=""]
* @param {string} [Title=""]
* @param {string} [Filters=""]
* @param {boolean} [AllowFiles=false]
* @param {boolean} [AllowDirectories=false]
* @param {boolean} [AllowMultiple=false]
* @param {boolean} [ShowHiddenFiles=false]
* @param {boolean} [CanCreateDirectories=false]
* @param {boolean} [ResolvesAliases=false] - Mac Only: Resolves aliases (symlinks)
* @param {boolean} [TreatPackagesAsDirectories=false] - Mac Only: Show packages (EG Applications) as folders
*/
/**
* Opens a dialog using the given parameters, prompting the user to
* select files/folders.
*
* @export
* @param {OpenDialogOptions} options
* @returns {Promise<Array<string>>} - List of files/folders selected
*/
export function Open(options) {
return SystemCall('Dialog.Open', options);
}
/**
*
* @type {Object} SaveDialogOptions
* @param {string} [DefaultDirectory=""]
* @param {string} [DefaultFilename=""]
* @param {string} [Title=""]
* @param {string} [Filters=""]
* @param {boolean} [ShowHiddenFiles=false]
* @param {boolean} [CanCreateDirectories=false]
* @param {boolean} [TreatPackagesAsDirectories=false]
*/
/**
* Opens a dialog using the given parameters, prompting the user to
* select a single file/folder.
*
* @export
* @param {SaveDialogOptions} options
* @returns {Promise<string>}
*/
export function Save(options) {
return SystemCall('Dialog.Save', options);
}
/**
*
* @type {Object} MessageDialogOptions
* @param {DialogType} [Type=InfoDialog] - The type of the dialog
* @param {string} [Title=""] - The dialog title
* @param {string} [Message=""] - The dialog message
* @param {string[]} [Buttons=[]] - The button titles
* @param {string} [DefaultButton=""] - The button that should be used as the default button
* @param {string} [CancelButton=""] - The button that should be used as the cancel button
* @param {string} [Icon=""] - The name of the icon to use in the dialog
*/
/**
* Opens a dialog using the given parameters, to display a message
* or prompt the user to select an option
*
* @export
* @name Message
* @param {MessageDialogOptions} options
* @returns {Promise<string>} - The button text that was selected
*/
export function Message(options) {
return SystemCall('Dialog.Message', options);
}

View File

@ -9,16 +9,11 @@ The lightweight framework for web-like apps
*/
/* jshint esversion: 6 */
import * as Log from './log';
import * as Browser from './browser';
import * as Window from './window';
import * as Dialog from './dialog';
import { On, Once, OnMultiple, Emit, Notify } from './events';
import { Callback, SystemCall } from './calls';
import { AddScript, InjectCSS, DisableDefaultContextMenu } from './utils';
import { AddIPCListener, SendMessage } from 'ipc';
import {Emit, Notify, On, Once, OnMultiple} from './events';
import {Callback, SystemCall} from './calls';
import {AddScript, DisableDefaultContextMenu, InjectCSS} from './utils';
import {AddIPCListener, SendMessage} from 'ipc';
import * as Platform from 'platform';
import * as Store from './store';
import * as Tray from './tray';
export function Init() {
// Backend is where the Go struct wrappers get bound to
@ -26,12 +21,7 @@ export function Init() {
// Initialise global if not already
window.wails = {
System: Platform.System,
Log,
Browser,
Window,
Tray,
Dialog,
Events: {
On,
Once,
@ -49,18 +39,8 @@ export function Init() {
SystemCall,
SendMessage,
},
Store,
};
// Setup system. Store uses window.wails so needs to be setup after that
window.wails.System = {
IsDarkMode: Store.New('wails:isdarkmode'),
LogLevel: Store.New('wails:loglevel'),
AppConfig: Store.New('wails:appconfig'),
};
// Copy platform specific information into it
Object.assign(window.wails.System, Platform.System);
// Do platform specific Init
Platform.Init();
}

View File

@ -1,182 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
import { Init } from './main';
import { SetBindings } from './bindings';
function init() {
// Bridge object
window.wailsbridge = {
reconnectOverlay: null,
reconnectTimer: 300,
wsURL: 'ws://' + window.location.hostname + ':8080/ws',
connectionState: null,
config: {},
websocket: null,
callback: null,
overlayHTML:
'<div class="wails-reconnect-overlay"><div class="wails-reconnect-overlay-content"><div class="wails-reconnect-overlay-title">Wails Bridge</div><br><div class="wails-reconnect-overlay-loadingspinner"></div><br><div id="wails-reconnect-overlay-message">Waiting for backend</div></div></div>',
overlayCSS:
'.wails-reconnect-overlay{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.6);font-family:sans-serif;display:none;z-index:999999}.wails-reconnect-overlay-content{padding:20px 30px;text-align:center;width:20em;position:relative;height:14em;border-radius:1em;margin:5% auto 0;background-color:#fff;box-shadow:1px 1px 20px 3px;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC8AAAAuCAMAAACPpbA7AAAAqFBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAAAAAAAAEBAQAAAAAAAAAAAAEBAQEBAQDAwMBAQEAAAABAQEAAAAAAAAAAAABAQEAAAAAAAACAgICAgIBAQEAAAAAAAAAAAAAAAAAAAAAAAABAQEAAAACAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFBQWKCj6oAAAAN3RSTlMALiIqDhkGBAswJjP0GxP6NR4W9/ztjRDMhWU50G9g5eHXvbZ9XEI9xZTcqZl2aldKo55QwoCvZUgzhAAAAs9JREFUSMeNleeWqjAUhU0BCaH3Itiw9zKT93+zG02QK1hm/5HF+jzZJ6fQe6cyXE+jg9X7o9wxuylIIf4Tv2V3+bOrEXnf8dwQ/KQIGDN2/S+4OmVCVXL/ScBnfibxURqIByP/hONE8r8T+bDMlQ98KSl7Y8hzjpS8v1qtDh8u5f8KQpGpfnPPhqG8JeogN37Hq9eaN2xRhIwAaGnvws8F1ShxqK5ob2twYi1FAMD4rXsYtnC/JEiRbl4cUrCWhnMCLRFemXezXbb59QK4WASOsm6n2W1+4CBT2JmtzQ6fsrbGubR/NFbd2g5Y179+5w/GEHaKsHjYCet7CgrXU3txarNC7YxOVJtIj4/ERzMdZfzc31hp+8cD6eGILgarZY9uZ12hAs03vfBD9C171gS5Omz7OcvxALQIn4u8RRBBBcsi9WW2woO9ipLgfzpYlggg3ZRdROUC8KT7QLqq3W9KB5BbdFVg4929kdwp6+qaZnMCCNBdj+NyN1W885Ry/AL3D4AQbsVV4noCiM/C83kyYq80XlDAYQtralOiDzoRAHlotWl8q2tjvYlOgcg1A8jEApZa+C06TBdAz2Qv0wu11I/zZOyJQ6EwGez2P2b8PIQr1hwwnAZsAxwA4UAYOyXUxM/xp6tHAn4GUmPGM9R28oVxgC0e/zQJJI6DyhyZ1r7uzRQhpcW7x7vTaWSzKSG6aep77kroTEl3U81uSVaUTtgEINfC8epx+Q4F9SpplHG84Ek6m4RAq9/TLkOBrxyeuddZhHvGIp1XXfFy3Z3vtwNblKGiDn+J+92vwwABHghj7HnzlS1H5kB49AZvdGCFgiBPq69qfXPr3y++yilF0ON4R8eR7spAsLpZ95NqAW5tab1c4vkZm6aleajchMwYTdILQQTwE2OV411ZM9WztDjPql12caBi6gDpUKmDd4U1XNdQxZ4LIXQ5/Tr4P7I9tYcFrDK3AAAAAElFTkSuQmCC);background-repeat:no-repeat;background-position:center}.wails-reconnect-overlay-title{font-size:2em}.wails-reconnect-overlay-message{font-size:1.3em}.wails-reconnect-overlay-loadingspinner{pointer-events:none;width:2.5em;height:2.5em;border:.4em solid transparent;border-color:#3E67EC #eee #eee;border-radius:50%;animation:loadingspin 1s linear infinite;margin:auto;padding:2.5em}@keyframes loadingspin{100%{transform:rotate(360deg)}}',
log: function (message) {
// eslint-disable-next-line
console.log(
'%c wails bridge %c ' + message + ' ',
'background: #aa0000; color: #fff; border-radius: 3px 0px 0px 3px; padding: 1px; font-size: 0.7rem',
'background: #009900; color: #fff; border-radius: 0px 3px 3px 0px; padding: 1px; font-size: 0.7rem'
);
}
};
}
// Adapted from webview - thanks zserge!
function injectCSS(css) {
var elem = document.createElement('style');
elem.setAttribute('type', 'text/css');
if (elem.styleSheet) {
elem.styleSheet.cssText = css;
} else {
elem.appendChild(document.createTextNode(css));
}
var head = document.head || document.getElementsByTagName('head')[0];
head.appendChild(elem);
}
// Creates a node in the Dom
function createNode(parent, elementType, id, className, content) {
var d = document.createElement(elementType);
if (id) {
d.id = id;
}
if (className) {
d.className = className;
}
if (content) {
d.innerHTML = content;
}
parent.appendChild(d);
return d;
}
// Sets up the overlay
function setupOverlay() {
var body = document.body;
var wailsBridgeNode = createNode(body, 'div', 'wails-bridge');
wailsBridgeNode.innerHTML = window.wailsbridge.overlayHTML;
// Inject the overlay CSS
injectCSS(window.wailsbridge.overlayCSS);
}
// Start the Wails Bridge
function startBridge() {
// Setup the overlay
setupOverlay();
window.wailsbridge.websocket = null;
window.wailsbridge.connectTimer = null;
window.wailsbridge.reconnectOverlay = document.querySelector(
'.wails-reconnect-overlay'
);
window.wailsbridge.connectionState = 'disconnected';
// Shows the overlay
function showReconnectOverlay() {
window.wailsbridge.reconnectOverlay.style.display = 'block';
}
// Hides the overlay
function hideReconnectOverlay() {
window.wailsbridge.reconnectOverlay.style.display = 'none';
}
// Handles incoming websocket connections
function handleConnect() {
window.wailsbridge.log('Connected to backend');
hideReconnectOverlay();
clearInterval(window.wailsbridge.connectTimer);
window.wailsbridge.websocket.onclose = handleDisconnect;
window.wailsbridge.websocket.onmessage = handleMessage;
window.wailsbridge.connectionState = 'connected';
}
// Handles websocket disconnects
function handleDisconnect() {
window.wailsbridge.log('Disconnected from backend');
window.wailsbridge.websocket = null;
window.wailsbridge.connectionState = 'disconnected';
showReconnectOverlay();
connect();
}
// Try to connect to the backend every 300ms (default value).
// Change this value in the main wailsbridge object.
function connect() {
window.wailsbridge.connectTimer = setInterval(function () {
if (window.wailsbridge.websocket == null) {
window.wailsbridge.websocket = new WebSocket(window.wailsbridge.wsURL);
window.wailsbridge.websocket.onopen = handleConnect;
window.wailsbridge.websocket.onerror = function (e) {
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
window.wailsbridge.websocket = null;
return false;
};
}
}, window.wailsbridge.reconnectTimer);
}
function handleMessage(message) {
switch (message.data[0]) {
case 'e':
case 'E':
window.wails._.Notify(message.data.slice(1));
break;
case 'R':
window.wails._.Callback(message.data.slice(1));
break;
default:
window.wails.Log.Error('Unknown message type received: ' + message.data[0]);
}
}
// Start by showing the overlay...
showReconnectOverlay();
// ...and attempt to connect
connect();
}
function start() {
// Set up the bridge
init();
// Start Bridge
startBridge();
// Load bindings
window.wailspreinit = function () {
if (window.wailsbindings) {
SetBindings(window.wailsbindings);
}
};
Init();
// Save the binding script
window.SetBindings = SetBindings;
}
// Start your engines!
start();

View File

@ -1,96 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
/**
* Creates a new sync store with the given name and optional default value
*
* @export
* @param {string} name
* @param {*} optionalDefault
*/
export function New(name, optionalDefault) {
// This is the store state
var state;
// Check we are initialised
if( !window.wails) {
throw Error('Wails is not initialised');
}
// Store for the callbacks
let callbacks = [];
// Subscribe to updates by providing a callback
let subscribe = function(callback) {
callbacks.push(callback);
};
// sets the store state to the provided `newstate` value
let set = function(newstate) {
state = newstate;
// Emit a notification to back end
window.wails.Events.Emit('wails:sync:store:updatedbyfrontend:'+name, JSON.stringify(state));
// Notify callbacks
callbacks.forEach( function(callback) {
callback(state);
});
};
// update mutates the value in the store by calling the
// provided method with the current value. The value returned
// by the updater function will be set as the new store value
let update = function(updater) {
var newValue = updater(state);
this.set(newValue);
};
// get returns the current value of the store
let get = function() {
return state;
};
// Setup event callback
window.wails.Events.On('wails:sync:store:updatedbybackend:'+name, function(jsonEncodedState) {
// Parse state
let newState = JSON.parse(jsonEncodedState);
// Todo: Potential preprocessing?
// Save state
state = newState;
// Notify callbacks
callbacks.forEach( function(callback) {
callback(state);
});
});
// Set to the optional default if set
if( optionalDefault ) {
this.set(optionalDefault);
}
// Trigger an update to the store
window.wails.Events.Emit('wails:sync:store:resync:'+name);
return {
subscribe,
get,
set,
update,
};
}

View File

@ -1,26 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
import * as Events from './events';
import * as Store from './store';
// Set up stores
export const LogLevel = Store.New('wails:loglevel');
export const AppConfig = Store.New('wails:appconfig');
// Set up dark mode
export let isDarkMode;
// Register system event listener to keep isDarkMode up to date
Events.On('wails:system:themechange', (darkMode) => {
isDarkMode = darkMode;
});

View File

@ -1,28 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
import { SendMessage } from 'ipc';
/**
* Sets the tray icon to the icon referenced by the given ID.
* Tray icons must follow this convention:
* - They must be PNG files
* - They must reside in a "trayicons" directory in the project root
* - They must have a ".png" extension
*
* The icon ID is the name of the file, without the ".png"
*
* @param {string} trayIconID - The tray icon ID
*/
export function SetIcon(trayIconID) {
SendMessage('TI' + trayIconID);
}

View File

@ -1,135 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
import { SendMessage } from 'ipc';
/**
* Place the window in the center of the screen
*
* @export
*/
export function Center() {
SendMessage('Wc');
}
/**
* Sets the window title
*
* @param {string} title
* @export
*/
export function SetTitle(title) {
SendMessage('WT' + title);
}
/**
* Makes the window go fullscreen
*
* @export
*/
export function Fullscreen() {
SendMessage('WF');
}
/**
* Reverts the window from fullscreen
*
* @export
*/
export function UnFullscreen() {
SendMessage('Wf');
}
/**
* Set the Size of the window
*
* @export
* @param {number} width
* @param {number} height
*/
export function SetSize(width, height) {
SendMessage('Ws:' + width + ':' + height);
}
/**
* Set the Position of the window
*
* @export
* @param {number} x
* @param {number} y
*/
export function SetPosition(x, y) {
SendMessage('Wp:' + x + ':' + y);
}
/**
* Hide the Window
*
* @export
*/
export function Hide() {
SendMessage('WH');
}
/**
* Show the Window
*
* @export
*/
export function Show() {
SendMessage('WS');
}
/**
* Maximise the Window
*
* @export
*/
export function Maximise() {
SendMessage('WM');
}
/**
* Unmaximise the Window
*
* @export
*/
export function Unmaximise() {
SendMessage('WU');
}
/**
* Minimise the Window
*
* @export
*/
export function Minimise() {
SendMessage('Wm');
}
/**
* Unminimise the Window
*
* @export
*/
export function Unminimise() {
SendMessage('Wu');
}
/**
* Close the Window
*
* @export
*/
export function Close() {
SendMessage('WC');
}

View File

@ -13,11 +13,6 @@ The lightweight framework for web-like apps
* Initialises platform specific code
*/
export const System = {
AppType: 'desktop',
Platform: () => 'darwin',
};
export function SendMessage(message) {
window.wailsInvoke(message);
}

View File

@ -13,11 +13,6 @@ The lightweight framework for web-like apps
* Initialises platform specific code
*/
export const System = {
AppType: 'desktop',
Platform: () => 'linux',
};
export function SendMessage(message) {
window.wailsInvoke(message);
}

View File

@ -13,11 +13,6 @@ The lightweight framework for web-like apps
* Initialises platform specific code
*/
export const System = {
AppType: 'desktop',
Platform: () => 'windows',
};
export function SendMessage(message) {
window.wailsInvoke(message);
}

View File

@ -1,21 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
/**
* Opens the given URL or Filename in the system browser
*
* @export
* @param {string} target
* @returns
*/
export function Open(target) {
return window.wails.Browser.Open(target);
}

View File

@ -1,86 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
/**
* @type {Object} OpenDialog
* @param {string} [DefaultDirectory=""]
* @param {string} [DefaultFilename=""]
* @param {string} [Title=""]
* @param {string} [Filters=""]
* @param {boolean} [AllowFiles=false]
* @param {boolean} [AllowDirectories=false]
* @param {boolean} [AllowMultiple=false]
* @param {boolean} [ShowHiddenFiles=false]
* @param {boolean} [CanCreateDirectories=false]
* @param {boolean} [ResolvesAliases=false] - Mac Only: Resolves aliases (symlinks)
* @param {boolean} [TreatPackagesAsDirectories=false] - Mac Only: Show packages (EG Applications) as folders
*/
/**
* Opens a dialog using the given parameters, prompting the user to
* select files/folders.
*
* @export
* @param {OpenDialogOptions} options
* @returns {Promise<Array<string>>} - List of files/folders selected
*/
export function Open(options) {
return window.wails.Dialog.Open(options);
}
/**
*
* @type {Object} SaveDialogOptions
* @param {string} [DefaultDirectory=""]
* @param {string} [DefaultFilename=""]
* @param {string} [Title=""]
* @param {string} [Filters=""]
* @param {boolean} [ShowHiddenFiles=false]
* @param {boolean} [CanCreateDirectories=false]
* @param {boolean} [TreatPackagesAsDirectories=false]
*/
/**
* Opens a dialog using the given parameters, prompting the user to
* select a single file/folder.
*
* @export
* @param {SaveDialogOptions} options
* @returns {Promise<string>}
*/
export function Save(options) {
return window.wails.Dialog.Save(options);
}
/**
*
* @type {Object} MessageDialogOptions
* @param {DialogType} [Type=InfoDialog] - The type of the dialog
* @param {string} [Title=""] - The dialog title
* @param {string} [Message=""] - The dialog message
* @param {string[]} [Buttons=[]] - The button titles
* @param {string} [DefaultButton=""] - The button that should be used as the default button
* @param {string} [CancelButton=""] - The button that should be used as the cancel button
* @param {string} [Icon=""] - The name of the icon to use in the dialog
*/
/**
* Opens a dialog using the given parameters, to display a message
* or prompt the user to select an option
*
* @export
* @param {MessageDialogOptions} options
* @returns {Promise<string>} - The button text that was selected
*/
export function Message(options) {
return window.wails.Dialog.Message(options);
}

View File

@ -10,23 +10,11 @@ The lightweight framework for web-like apps
/* jshint esversion: 6 */
const Log = require('./log');
const Browser = require('./browser');
const Dialog = require('./dialog');
const Events = require('./events');
const Init = require('./init');
const System = require('./system');
const Store = require('./store');
const Window = require('./window');
const Tray = require('./tray');
module.exports = {
Browser: Browser,
Dialog: Dialog,
Events: Events,
ready: Init.ready,
Log: Log,
System: System,
Store: Store,
Window: Window,
Tray: Tray,
};

View File

@ -1,103 +1,14 @@
export = wailsapp__runtime;
interface Store {
get(): any;
set(value: any): void;
subscribe(callback: (newvalue: any) => void): void;
update(callback: (currentvalue: any) => any): void;
}
interface MacTitleBar {
TitleBarAppearsTransparent: boolean; // NSWindow.titleBarAppearsTransparent
HideTitle: boolean; // NSWindow.hideTitle
HideTitleBar: boolean; // NSWindow.hideTitleBar
FullSizeContent: boolean; // Makes the webview portion of the window the full size of the window, even over the titlebar
UseToolbar: boolean; // Set true to add a blank toolbar to the window (makes the title bar larger)
HideToolbarSeparator: boolean; // Set true to remove the separator between the toolbar and the main content area
}
interface MacAppConfig {
TitleBar: MacTitleBar;
}
interface LinuxAppConfig {
}
interface WindowsAppConfig {
}
interface AppConfig {
Title: string; // Application Title
Width: number; // Window Width
Height: number; // Window Height
DisableResize: boolean; // True if resize is disabled
Fullscreen: boolean; // App started in fullscreen
MinWidth: number; // Window Minimum Width
MinHeight: number; // Window Minimum Height
MaxWidth: number; // Window Maximum Width
MaxHeight: number; // Window Maximum Height
StartHidden: boolean; // Start with window hidden
DevTools: boolean; // Enables the window devtools
RBGA: number; // The initial window colour. Convert to hex then it'll mean 0xRRGGBBAA
Mac?: MacAppConfig; // - Configuration when running on Mac
Linux?: LinuxAppConfig; // - Configuration when running on Linux
Windows?: WindowsAppConfig; // - Configuration when running on Windows
Appearance: string; // The default application appearance. Use the values listed here: https://developer.apple.com/documentation/appkit/nsappearance?language=objc
WebviewIsTransparent: number; // Makes the background of the webview content transparent. Use this with the Alpha part of the window colour to make parts of your application transparent.
WindowBackgroundIsTranslucent: number; // Makes the transparent parts of the application window translucent. Example: https://en.wikipedia.org/wiki/MacOS_Big_Sur#/media/File:MacOS_Big_Sur_-_Safari_Extensions_category_in_App_Store.jpg
LogLevel: number; // The initial log level (lower is more verbose)
}
interface Level {
TRACE: 1,
DEBUG: 2,
INFO: 3,
WARNING: 4,
ERROR: 5,
}
interface OpenDialogOptions {
DefaultDirectory: string;
DefaultFilename: string;
Title: string;
Filters: string;
AllowFiles: boolean;
AllowDirectories: boolean;
AllowMultiple: boolean;
ShowHiddenFiles: boolean;
CanCreateDirectories: boolean;
ResolvesAliases: boolean;
TreatPackagesAsDirectories: boolean;
}
interface SaveDialogOptions {
DefaultDirectory: string;
DefaultFilename: string;
Title: string;
Filters: string;
ShowHiddenFiles: boolean;
CanCreateDirectories: boolean;
TreatPackagesAsDirectories: boolean;
}
interface DialogType {
InfoDialog: 'info',
WarningDialog: 'warning',
ErrorDialog: 'error',
QuestionDialog: 'question',
}
interface MessageDialogOptions {
Type: DialogType;
Title: string;
Message: string;
Buttons: string[];
DefaultButton: string;
CancelButton: string;
Icon: string;
interface Level {
TRACE: 1,
DEBUG: 2,
INFO: 3,
WARNING: 4,
ERROR: 5,
}
declare const wailsapp__runtime: {
Browser: {
Open(target: string): Promise<any>;
};
Events: {
Emit(eventName: string, data?: any): void;
On(eventName: string, callback: (data?: any) => void): void;
@ -113,25 +24,6 @@ declare const wailsapp__runtime: {
Warning(message: string): void;
Level: Level;
};
System: {
DarkModeEnabled(): Promise<boolean>;
OnThemeChange(callback: (darkModeEnabled: boolean) => void): void;
LogLevel(): Store;
Platform(): string;
AppType(): string;
AppConfig(): AppConfig;
};
Store: {
New(name: string, defaultValue?: any): Store;
};
Dialog: {
Open(options: OpenDialogOptions): Promise<Array<string>>;
Save(options: SaveDialogOptions): Promise<string>;
Message(options: MessageDialogOptions): Promise<string>;
};
Tray: {
SetIcon(trayIconID: string): void;
}
};

View File

@ -1,27 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
/**
* Create a new Store with the given name and optional default value
*
* @export
* @param {string} name
* @param {*} optionalDefault
*/
function New(name, optionalDefault) {
return window.wails.Store.New(name, optionalDefault);
}
module.exports = {
New: New,
};

View File

@ -1,110 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
const Events = require('./events');
/**
* Registers an event listener that will be invoked when the user changes the
* desktop theme (light mode / dark mode). The callback receives a booleanean which
* indicates if dark mode is enabled.
*
* @export
* @param {function} callback The callback to invoke on theme change
*/
function OnThemeChange(callback) {
Events.On("wails:system:themechange", callback);
}
/**
* Checks if dark mode is curently enabled.
*
* @export
* @returns {Promise}
*/
function DarkModeEnabled() {
return window.wails.System.IsDarkMode.get();
}
/**
* Mac Application Config
* @typedef {Object} MacAppConfig
* @param {MacTitleBar} TitleBar - The window's titlebar configuration
*/
/**
* Mac Title Bar Config
* Check out https://github.com/lukakerr/NSWindowStyles for some examples of these settings
* @typedef {Object} MacTitleBar
* @param {boolean} TitleBarAppearsTransparent - NSWindow.titleBarAppearsTransparent
* @param {boolean} HideTitle - NSWindow.hideTitle
* @param {boolean} HideTitleBar - NSWindow.hideTitleBar
* @param {boolean} FullSizeContent - Makes the webview portion of the window the full size of the window, even over the titlebar
* @param {boolean} UseToolbar - Set true to add a blank toolbar to the window (makes the title bar larger)
* @param {boolean} HideToolbarSeparator - Set true to remove the separator between the toolbar and the main content area
*
*/
/**
* The application configuration
*
* @typedef {Object} AppConfig
* @param {string} Title - Application Title
* @param {number} Width - Window Width
* @param {number} Height - Window Height
* @param {boolean} DisableResize - True if resize is disabled
* @param {boolean} Fullscreen - App started in fullscreen
* @param {number} MinWidth - Window Minimum Width
* @param {number} MinHeight - Window Minimum Height
* @param {number} MaxWidth - Window Maximum Width
* @param {number} MaxHeight - Window Maximum Height
* @param {boolean} StartHidden - Start with window hidden
* @param {boolean} DevTools - Enables the window devtools
* @param {number} RBGA - The initial window colour. Convert to hex then it'll mean 0xRRGGBBAA
* @param {MacAppConfig} [Mac] - Configuration when running on Mac
* @param {LinuxAppConfig} [Linux] - Configuration when running on Linux
* @param {WindowsAppConfig} [Windows] - Configuration when running on Windows
* @param {string} Appearance - The default application appearance. Use the values listed here: https://developer.apple.com/documentation/appkit/nsappearance?language=objc
* @param {number} WebviewIsTransparent - Makes the background of the webview content transparent. Use this with the Alpha part of the window colour to make parts of your application transparent.
* @param {number} WindowBackgroundIsTranslucent - Makes the transparent parts of the application window translucent. Example: https://en.wikipedia.org/wiki/MacOS_Big_Sur#/media/File:MacOS_Big_Sur_-_Safari_Extensions_category_in_App_Store.jpg
* @param {number} LogLevel - The initial log level (lower is more verbose)
*
*/
/**
* Returns the application configuration.
*
* @export
* @returns {Promise<AppConfig>}
*/
function AppConfig() {
return window.wails.System.AppConfig.get();
}
function LogLevel() {
return window.wails.System.LogLevel();
}
function Platform() {
return window.wails.System.Platform();
}
function AppType() {
return window.wails.System.AppType();
}
module.exports = {
OnThemeChange: OnThemeChange,
DarkModeEnabled: DarkModeEnabled,
LogLevel: LogLevel,
Platform: Platform,
AppType: AppType,
AppConfig: AppConfig,
};

View File

@ -1,32 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
/**
* Sets the tray icon to the icon referenced by the given ID.
* Tray icons must follow this convention:
* - They must be PNG files
* - They must reside in a "trayicons" directory in the project root
* - They must have a ".png" extension
*
* The icon ID is the name of the file, without the ".png"
*
* @export
* @param {string} trayIconID
*/
function SetIcon(trayIconID) {
window.wails.Tray.SetIcon(trayIconID);
}
module.exports = {
SetIcon: SetIcon,
};

View File

@ -1,131 +0,0 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
/**
* Place the window in the center of the screen
*
* @export
*/
export function Center() {
window.wails.Window.Center();
}
/**
* Set the Size of the window
*
* @export
* @param {number} width
* @param {number} height
*/
export function SetSize(width, height) {
window.wails.Window.SetSize(width, height);
}
/**
* Set the Position of the window
*
* @export
* @param {number} x
* @param {number} y
*/
export function SetPosition(x, y) {
window.wails.Window.SetPosition(x, y);
}
/**
* Hide the Window
*
* @export
*/
export function Hide() {
window.wails.Window.Hide();
}
/**
* Show the Window
*
* @export
*/
export function Show() {
window.wails.Window.Show();
}
/**
* Maximise the Window
*
* @export
*/
export function Maximise() {
window.wails.Window.Maximise()
}
/**
* Unmaximise the Window
*
* @export
*/
export function Unmaximise() {
window.wails.Window.Unmaximise()
}
/**
* Minimise the Window
*
* @export
*/
export function Minimise() {
window.wails.Window.Minimise();
}
/**
* Unminimise the Window
*
* @export
*/
export function Unminimise() {
window.wails.Window.Unminimise();
}
/**
* Close the Window
*
* @export
*/
export function Close() {
window.wails.Window.Close();
}
/**
* Sets the window title
*
* @export
*/
export function SetTitle(title) {
window.wails.Window.SetTitle(title);
}
/**
* Makes the window go fullscreen
*
* @export
*/
export function Fullscreen() {
window.wails.Window.Fullscreen();
}
/**
* Reverts the window from fullscreen
*
* @export
*/
export function UnFullscreen() {
window.wails.Window.UnFullscreen();
}

View File

@ -13,9 +13,4 @@ The lightweight framework for web-like apps
* Initialises platform specific code
*/
export const System = {
Platform: "darwin",
AppType: "server"
}
export function Init() { }

View File

@ -13,9 +13,4 @@ The lightweight framework for web-like apps
* Initialises platform specific code
*/
export const System = {
Platform: "linux",
AppType: "server"
}
export function Init() { }