mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 06:20:48 +08:00
[v2] Update Menu runtime
This commit is contained in:
parent
3c0da9fd15
commit
d6cdd1df82
@ -118,8 +118,8 @@ func (b BridgeClient) DarkModeEnabled(callbackID string) {
|
|||||||
b.session.log.Info("DarkModeEnabled unsupported in Bridge mode")
|
b.session.log.Info("DarkModeEnabled unsupported in Bridge mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b BridgeClient) SetApplicationMenu(menuJSON string) {
|
func (b BridgeClient) MenuSetApplicationMenu(menuJSON string) {
|
||||||
b.session.log.Info("SetApplicationMenu unsupported in Bridge mode")
|
b.session.log.Info("MenuSetApplicationMenu unsupported in Bridge mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b BridgeClient) SetTrayMenu(trayMenuJSON string) {
|
func (b BridgeClient) SetTrayMenu(trayMenuJSON string) {
|
||||||
|
@ -120,10 +120,10 @@ func processMenuItem(parent *winc.MenuItem, menuItem *menu.MenuItem) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) SetApplicationMenu(menu *menu.Menu) {
|
func (f *Frontend) MenuSetApplicationMenu(menu *menu.Menu) {
|
||||||
f.mainWindow.SetApplicationMenu(menu)
|
f.mainWindow.SetApplicationMenu(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) UpdateApplicationMenu() {
|
func (f *Frontend) MenuUpdateApplicationMenu() {
|
||||||
processMenu(f.mainWindow, f.mainWindow.applicationMenu)
|
processMenu(f.mainWindow, f.mainWindow.applicationMenu)
|
||||||
}
|
}
|
||||||
|
@ -230,12 +230,12 @@ func (d *DevWebServer) WindowSetRGBA(col *options.RGBA) {
|
|||||||
d.desktopFrontend.WindowSetRGBA(col)
|
d.desktopFrontend.WindowSetRGBA(col)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DevWebServer) SetApplicationMenu(menu *menu.Menu) {
|
func (d *DevWebServer) MenuSetApplicationMenu(menu *menu.Menu) {
|
||||||
d.desktopFrontend.SetApplicationMenu(menu)
|
d.desktopFrontend.MenuSetApplicationMenu(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DevWebServer) UpdateApplicationMenu() {
|
func (d *DevWebServer) MenuUpdateApplicationMenu() {
|
||||||
d.desktopFrontend.UpdateApplicationMenu()
|
d.desktopFrontend.MenuUpdateApplicationMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DevWebServer) Notify(name string, data ...interface{}) {
|
func (d *DevWebServer) Notify(name string, data ...interface{}) {
|
||||||
|
@ -89,8 +89,8 @@ type Frontend interface {
|
|||||||
WindowReload()
|
WindowReload()
|
||||||
|
|
||||||
// Menus
|
// Menus
|
||||||
SetApplicationMenu(menu *menu.Menu)
|
MenuSetApplicationMenu(menu *menu.Menu)
|
||||||
UpdateApplicationMenu()
|
MenuUpdateApplicationMenu()
|
||||||
//SetTrayMenu(menu *menu.TrayMenu)
|
//SetTrayMenu(menu *menu.TrayMenu)
|
||||||
//UpdateTrayMenuLabel(menu *menu.TrayMenu)
|
//UpdateTrayMenuLabel(menu *menu.TrayMenu)
|
||||||
//UpdateContextMenu(contextMenu *menu.ContextMenu)
|
//UpdateContextMenu(contextMenu *menu.ContextMenu)
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
(() => {
|
(() => {
|
||||||
var __defProp = Object.defineProperty;
|
var __defProp = Object.defineProperty;
|
||||||
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
||||||
var __export = (target, all) => {
|
var __export = (target, all) => {
|
||||||
__markAsModule(target);
|
__markAsModule(target);
|
||||||
for (var name in all)
|
for (var name in all)
|
||||||
__defProp(target, name, {get: all[name], enumerable: true});
|
__defProp(target, name, {get: all[name], enumerable: true});
|
||||||
};
|
};
|
||||||
|
|
||||||
// desktop/log.js
|
// desktop/log.js
|
||||||
var log_exports = {};
|
var log_exports = {};
|
||||||
@ -138,17 +138,17 @@
|
|||||||
if (timeout == null) {
|
if (timeout == null) {
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
}
|
}
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
var callbackID;
|
var callbackID;
|
||||||
do {
|
do {
|
||||||
callbackID = name + "-" + randomFunc();
|
callbackID = name + "-" + randomFunc();
|
||||||
} while (callbacks[callbackID]);
|
} while (callbacks[callbackID]);
|
||||||
var timeoutHandle;
|
var timeoutHandle;
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
timeoutHandle = setTimeout(function () {
|
timeoutHandle = setTimeout(function () {
|
||||||
reject(Error("Call to " + name + " timed out. Request ID: " + callbackID));
|
reject(Error("Call to " + name + " timed out. Request ID: " + callbackID));
|
||||||
}, timeout);
|
}, timeout);
|
||||||
}
|
}
|
||||||
callbacks[callbackID] = {
|
callbacks[callbackID] = {
|
||||||
timeoutHandle,
|
timeoutHandle,
|
||||||
reject,
|
reject,
|
||||||
@ -205,20 +205,20 @@
|
|||||||
Object.keys(bindingsMap[packageName]).forEach((structName) => {
|
Object.keys(bindingsMap[packageName]).forEach((structName) => {
|
||||||
window.go[packageName][structName] = window.go[packageName][structName] || {};
|
window.go[packageName][structName] = window.go[packageName][structName] || {};
|
||||||
Object.keys(bindingsMap[packageName][structName]).forEach((methodName) => {
|
Object.keys(bindingsMap[packageName][structName]).forEach((methodName) => {
|
||||||
window.go[packageName][structName][methodName] = function () {
|
window.go[packageName][structName][methodName] = function () {
|
||||||
let timeout = 0;
|
let timeout = 0;
|
||||||
|
|
||||||
function dynamic() {
|
function dynamic() {
|
||||||
const args = [].slice.call(arguments);
|
const args = [].slice.call(arguments);
|
||||||
return Call([packageName, structName, methodName].join("."), args, timeout);
|
return Call([packageName, structName, methodName].join("."), args, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamic.setTimeout = function (newTimeout) {
|
dynamic.setTimeout = function (newTimeout) {
|
||||||
timeout = newTimeout;
|
timeout = newTimeout;
|
||||||
};
|
};
|
||||||
dynamic.getTimeout = function () {
|
dynamic.getTimeout = function () {
|
||||||
return timeout;
|
return timeout;
|
||||||
};
|
};
|
||||||
return dynamic;
|
return dynamic;
|
||||||
}();
|
}();
|
||||||
});
|
});
|
||||||
@ -231,23 +231,23 @@
|
|||||||
__export(window_exports, {
|
__export(window_exports, {
|
||||||
WindowCenter: () => WindowCenter,
|
WindowCenter: () => WindowCenter,
|
||||||
WindowClose: () => WindowClose,
|
WindowClose: () => WindowClose,
|
||||||
WindowFullscreen: () => WindowFullscreen,
|
WindowFullscreen: () => WindowFullscreen,
|
||||||
WindowGetPosition: () => WindowGetPosition,
|
WindowGetPosition: () => WindowGetPosition,
|
||||||
WindowGetSize: () => WindowGetSize,
|
WindowGetSize: () => WindowGetSize,
|
||||||
WindowHide: () => WindowHide,
|
WindowHide: () => WindowHide,
|
||||||
WindowMaximise: () => WindowMaximise,
|
WindowMaximise: () => WindowMaximise,
|
||||||
WindowMinimise: () => WindowMinimise,
|
WindowMinimise: () => WindowMinimise,
|
||||||
WindowReload: () => WindowReload,
|
WindowReload: () => WindowReload,
|
||||||
WindowSetMaxSize: () => WindowSetMaxSize,
|
WindowSetMaxSize: () => WindowSetMaxSize,
|
||||||
WindowSetMinSize: () => WindowSetMinSize,
|
WindowSetMinSize: () => WindowSetMinSize,
|
||||||
WindowSetPosition: () => WindowSetPosition,
|
WindowSetPosition: () => WindowSetPosition,
|
||||||
WindowSetRGBA: () => WindowSetRGBA,
|
WindowSetRGBA: () => WindowSetRGBA,
|
||||||
WindowSetSize: () => WindowSetSize,
|
WindowSetSize: () => WindowSetSize,
|
||||||
WindowSetTitle: () => WindowSetTitle,
|
WindowSetTitle: () => WindowSetTitle,
|
||||||
WindowShow: () => WindowShow,
|
WindowShow: () => WindowShow,
|
||||||
WindowUnFullscreen: () => WindowUnFullscreen,
|
WindowUnFullscreen: () => WindowUnFullscreen,
|
||||||
WindowUnmaximise: () => WindowUnmaximise,
|
WindowUnmaximise: () => WindowUnmaximise,
|
||||||
WindowUnminimise: () => WindowUnminimise
|
WindowUnminimise: () => WindowUnminimise
|
||||||
});
|
});
|
||||||
function WindowReload() {
|
function WindowReload() {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
@ -282,43 +282,46 @@
|
|||||||
function WindowGetPosition() {
|
function WindowGetPosition() {
|
||||||
return Call(":wails:WindowGetPos");
|
return Call(":wails:WindowGetPos");
|
||||||
}
|
}
|
||||||
|
|
||||||
function WindowHide() {
|
function WindowHide() {
|
||||||
window.WailsInvoke("WH");
|
window.WailsInvoke("WH");
|
||||||
}
|
}
|
||||||
|
|
||||||
function WindowShow() {
|
function WindowShow() {
|
||||||
window.WailsInvoke("WS");
|
window.WailsInvoke("WS");
|
||||||
}
|
}
|
||||||
|
|
||||||
function WindowMaximise() {
|
function WindowMaximise() {
|
||||||
window.WailsInvoke("WM");
|
window.WailsInvoke("WM");
|
||||||
}
|
}
|
||||||
|
|
||||||
function WindowUnmaximise() {
|
function WindowUnmaximise() {
|
||||||
window.WailsInvoke("WU");
|
window.WailsInvoke("WU");
|
||||||
}
|
}
|
||||||
|
|
||||||
function WindowMinimise() {
|
function WindowMinimise() {
|
||||||
window.WailsInvoke("Wm");
|
window.WailsInvoke("Wm");
|
||||||
}
|
}
|
||||||
|
|
||||||
function WindowUnminimise() {
|
function WindowUnminimise() {
|
||||||
window.WailsInvoke("Wu");
|
window.WailsInvoke("Wu");
|
||||||
}
|
}
|
||||||
|
|
||||||
function WindowSetRGBA(RGBA) {
|
function WindowSetRGBA(RGBA) {
|
||||||
let rgba = JSON.stringify(RGBA);
|
let rgba = JSON.stringify(RGBA);
|
||||||
window.WailsInvoke("Wr:" + rgba);
|
window.WailsInvoke("Wr:" + rgba);
|
||||||
}
|
}
|
||||||
|
|
||||||
function WindowClose() {
|
function WindowClose() {
|
||||||
window.WailsInvoke("WC");
|
window.WailsInvoke("WC");
|
||||||
}
|
}
|
||||||
|
|
||||||
// desktop/main.js
|
// desktop/main.js
|
||||||
window.runtime = {
|
window.runtime = {
|
||||||
...log_exports,
|
...log_exports,
|
||||||
...window_exports,
|
...window_exports,
|
||||||
EventsOn,
|
EventsOn,
|
||||||
EventsOnce,
|
EventsOnce,
|
||||||
EventsOnMultiple,
|
EventsOnMultiple,
|
||||||
EventsEmit,
|
EventsEmit,
|
||||||
EventsOff
|
EventsOff
|
||||||
|
@ -2,31 +2,15 @@ package runtime
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/wailsapp/wails/v2/pkg/menu"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateApplicationMenu(ctx context.Context) {
|
func MenuSetApplicationMenu(ctx context.Context, menu *menu.Menu) {
|
||||||
frontend := getFrontend(ctx)
|
frontend := getFrontend(ctx)
|
||||||
frontend.UpdateApplicationMenu()
|
frontend.MenuSetApplicationMenu(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
func MenuUpdateApplicationMenu(ctx context.Context) {
|
||||||
func UpdateContextMenu(ctx context.Context, contextMenu *menu.ContextMenu) {
|
|
||||||
frontend := getFrontend(ctx)
|
frontend := getFrontend(ctx)
|
||||||
bus.Publish("menu:updatecontextmenu", contextMenu)
|
frontend.MenuUpdateApplicationMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetTrayMenu(ctx context.Context, trayMenu *menu.TrayMenu) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
bus.Publish("menu:settraymenu", trayMenu)
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateTrayMenuLabel(ctx context.Context, trayMenu *menu.TrayMenu) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
bus.Publish("menu:updatetraymenulabel", trayMenu)
|
|
||||||
}
|
|
||||||
|
|
||||||
func DeleteTrayMenu(ctx context.Context, trayMenu *menu.TrayMenu) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
bus.Publish("menu:deletetraymenu", trayMenu)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
Loading…
Reference in New Issue
Block a user