mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
[v3 mac] Support drag
This commit is contained in:
+8
-2
@@ -13,7 +13,7 @@ tasks:
|
||||
dir: internal/runtime
|
||||
internal: true
|
||||
cmds:
|
||||
- npx esbuild desktop/main.js --bundle --sourcemap=inline --outfile=runtime_debug_desktop_{{.PLATFORM}}.js --define:DEBUG=true --define:WINDOWS={{.WINDOWS}} --define:DARWIN={{.DARWIN}} --define:LINUX={{.LINUX}} --define:PLATFORM={{.PLATFORM}}
|
||||
- npx esbuild desktop/main.js --bundle --sourcemap=inline --outfile=runtime_debug_desktop_{{.PLATFORM}}.js --define:DEBUG=true --define:WINDOWS={{.WINDOWS}} --define:DARWIN={{.DARWIN}} --define:LINUX={{.LINUX}} --define:PLATFORM={{.PLATFORM}} --define:INVOKE={{.INVOKE}}
|
||||
|
||||
build:runtime:debug:windows:
|
||||
cmds:
|
||||
@@ -23,6 +23,7 @@ tasks:
|
||||
DARWIN: false
|
||||
LINUX: false
|
||||
PLATFORM: windows
|
||||
INVOKE: "chrome.webview.postMessage"
|
||||
|
||||
build:runtime:debug:linux:
|
||||
cmds:
|
||||
@@ -32,6 +33,7 @@ tasks:
|
||||
DARWIN: false
|
||||
LINUX: true
|
||||
PLATFORM: linux
|
||||
INVOKE: "webkit.messageHandlers.external.postMessage"
|
||||
|
||||
build:runtime:debug:darwin:
|
||||
cmds:
|
||||
@@ -41,12 +43,13 @@ tasks:
|
||||
DARWIN: true
|
||||
LINUX: false
|
||||
PLATFORM: darwin
|
||||
INVOKE: "webkit.messageHandlers.external.postMessage"
|
||||
|
||||
build:runtime:production:
|
||||
dir: internal/runtime
|
||||
internal: true
|
||||
cmds:
|
||||
- npx esbuild desktop/main.js --bundle --minify --outfile=runtime_production_desktop_{{.PLATFORM}}.js --define:DEBUG=true --define:WINDOWS={{.WINDOWS}} --define:DARWIN={{.DARWIN}} --define:LINUX={{.LINUX}} --define:PLATFORM={{.PLATFORM}}
|
||||
- npx esbuild desktop/main.js --bundle --minify --outfile=runtime_production_desktop_{{.PLATFORM}}.js --define:DEBUG=true --define:WINDOWS={{.WINDOWS}} --define:DARWIN={{.DARWIN}} --define:LINUX={{.LINUX}} --define:PLATFORM={{.PLATFORM}} --define:INVOKE={{.INVOKE}}
|
||||
|
||||
build:runtime:production:windows:
|
||||
cmds:
|
||||
@@ -56,6 +59,7 @@ tasks:
|
||||
DARWIN: false
|
||||
LINUX: false
|
||||
PLATFORM: windows
|
||||
INVOKE: "chrome.webview.postMessage"
|
||||
|
||||
build:runtime:production:linux:
|
||||
cmds:
|
||||
@@ -65,6 +69,7 @@ tasks:
|
||||
DARWIN: false
|
||||
LINUX: true
|
||||
PLATFORM: linux
|
||||
INVOKE: "webkit.messageHandlers.external.postMessage"
|
||||
|
||||
build:runtime:production:darwin:
|
||||
cmds:
|
||||
@@ -74,6 +79,7 @@ tasks:
|
||||
DARWIN: true
|
||||
LINUX: false
|
||||
PLATFORM: darwin
|
||||
INVOKE: "webkit.messageHandlers.external.postMessage"
|
||||
|
||||
install:runtime-dev-deps:
|
||||
dir: internal/runtime/dev
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
html, body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.quarter {
|
||||
flex: 50%; /* This will cause elements to take up 50% of the container's width, causing them to wrap into 4 equal sections. */
|
||||
box-sizing: border-box; /* This makes the padding part of the element's total width and height, ensuring they don't exceed 50%. */
|
||||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="quarter" style="background-color: lightblue; --wails-draggable: drag">Draggable</div>
|
||||
<div class="quarter" style="background-color: lightgreen;">Not Draggable</div>
|
||||
<div class="quarter" style="background-color: lightpink;">Not Draggable</div>
|
||||
<div class="quarter" style="background-color: lightyellow; --wails-draggable: drag">Draggable</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
_ "embed"
|
||||
"log"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
//go:embed assets
|
||||
var assets embed.FS
|
||||
|
||||
func main() {
|
||||
|
||||
app := application.New(application.Options{
|
||||
Name: "Frameless Demo",
|
||||
Description: "A demo of frameless windows",
|
||||
Mac: application.MacOptions{
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
},
|
||||
Assets: application.AssetOptions{
|
||||
FS: assets,
|
||||
},
|
||||
})
|
||||
|
||||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
||||
Frameless: true,
|
||||
})
|
||||
|
||||
err := app.Run()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
_ __ _ __
|
||||
| | / /___ _(_) /____
|
||||
| | /| / / __ `/ / / ___/
|
||||
| |/ |/ / /_/ / / (__ )
|
||||
|__/|__/\__,_/_/_/____/
|
||||
The electron alternative for Go
|
||||
(c) Lea Anthony 2019-present
|
||||
*/
|
||||
|
||||
/* jshint esversion: 9 */
|
||||
|
||||
import {invoke} from "./invoke";
|
||||
|
||||
let shouldDrag = false;
|
||||
|
||||
export function dragTest(e) {
|
||||
let val = window.getComputedStyle(e.target).getPropertyValue("--wails-draggable");
|
||||
if (val) {
|
||||
val = val.trim();
|
||||
}
|
||||
|
||||
if (val !== "drag") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only process the primary button
|
||||
if (e.buttons !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return e.detail === 1;
|
||||
}
|
||||
|
||||
export function setupDrag() {
|
||||
window.addEventListener('mousedown', onMouseDown);
|
||||
window.addEventListener('mousemove', onMouseMove);
|
||||
window.addEventListener('mouseup', onMouseUp);
|
||||
}
|
||||
|
||||
function onMouseDown(e) {
|
||||
if (dragTest(e)) {
|
||||
// Ignore drag on scrollbars
|
||||
if (e.offsetX > e.target.clientWidth || e.offsetY > e.target.clientHeight) {
|
||||
return;
|
||||
}
|
||||
shouldDrag = true;
|
||||
} else {
|
||||
shouldDrag = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseUp(e) {
|
||||
document.body.style.cursor = window.wails.previousCursor || 'auto';
|
||||
shouldDrag = false;
|
||||
}
|
||||
|
||||
function onMouseMove(e) {
|
||||
if (shouldDrag) {
|
||||
shouldDrag = false;
|
||||
let mousePressed = e.buttons !== undefined ? e.buttons : e.which;
|
||||
if (mousePressed > 0) {
|
||||
window.wails.previousCursor = document.body.style.cursor;
|
||||
document.body.style.cursor = 'grab';
|
||||
invoke("drag");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
_ __ _ __
|
||||
| | / /___ _(_) /____
|
||||
| | /| / / __ `/ / / ___/
|
||||
| |/ |/ / /_/ / / (__ )
|
||||
|__/|__/\__,_/_/_/____/
|
||||
The electron alternative for Go
|
||||
(c) Lea Anthony 2019-present
|
||||
*/
|
||||
|
||||
/* jshint esversion: 9 */
|
||||
|
||||
// defined in the Taskfile
|
||||
export let invoke = function(input) {
|
||||
if(WINDOWS) {
|
||||
chrome.webview.postMessage(input);
|
||||
} else {
|
||||
webkit.messageHandlers.external.postMessage(input);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import {dispatchWailsEvent, Emit, Off, OffAll, On, Once, OnMultiple} from "./eve
|
||||
import {dialogCallback, dialogErrorCallback, Error, Info, OpenFile, Question, SaveFile, Warning,} from "./dialogs";
|
||||
import {enableContextMenus} from "./contextmenu";
|
||||
import {reloadWML} from "./wml";
|
||||
import {setupDrag} from "./drag";
|
||||
|
||||
window.wails = {
|
||||
...newRuntime(null),
|
||||
@@ -78,6 +79,8 @@ if (DEBUG) {
|
||||
|
||||
enableContextMenus(true);
|
||||
|
||||
setupDrag();
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
reloadWML();
|
||||
});
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -63,18 +63,21 @@ extern bool hasListeners(unsigned int);
|
||||
// Handle script messages from the external bridge
|
||||
- (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message {
|
||||
NSString *m = message.body;
|
||||
/*
|
||||
// TODO: Check for drag
|
||||
|
||||
if ( [m isEqualToString:@"drag"] ) {
|
||||
/*
|
||||
if( [self IsFullScreen] ) {
|
||||
return;
|
||||
}
|
||||
if( self.mouseEvent != nil ) {
|
||||
[self.mainWindow performWindowDragWithEvent:self.mouseEvent];
|
||||
*/
|
||||
if( self.leftMouseEvent != nil ) {
|
||||
WKWebView *webView = message.webView;
|
||||
WebviewWindow *window = (WebviewWindow*)webView.window;
|
||||
[window performWindowDragWithEvent:self.leftMouseEvent];
|
||||
}
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
const char *_m = [m UTF8String];
|
||||
processMessage(self.windowId, _m);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user