mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 03:40:45 +08:00
[windows] ON_MAIN_THEAD macro. Misc updates
This commit is contained in:
parent
385988989b
commit
ee05884c9c
@ -13,17 +13,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
#cgo linux CFLAGS: -DFFENESTRI_LINUX=1
|
#cgo linux CFLAGS: -DFFENESTRI_LINUX=1
|
||||||
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0
|
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0
|
||||||
|
|
||||||
#cgo darwin CFLAGS: -DFFENESTRI_DARWIN=1
|
#cgo darwin CFLAGS: -DFFENESTRI_DARWIN=1
|
||||||
#cgo darwin LDFLAGS: -framework WebKit -lobjc
|
#cgo darwin LDFLAGS: -framework WebKit -lobjc
|
||||||
|
|
||||||
|
#cgo windows CPPFLAGS: -std=c++11
|
||||||
|
#cgo windows,amd64 LDFLAGS: -L./windows/x64 -lwebview -lWebView2Loader -lgdi32
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "ffenestri.h"
|
#include "ffenestri.h"
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
@ -139,9 +139,9 @@ func (a *Application) Run(incomingDispatcher Dispatcher, bindings string, debug
|
|||||||
C.SetDebug(app, a.bool2Cint(debug))
|
C.SetDebug(app, a.bool2Cint(debug))
|
||||||
|
|
||||||
// TODO: Move frameless to Linux options
|
// TODO: Move frameless to Linux options
|
||||||
// if a.config.Frameless {
|
if a.config.Frameless {
|
||||||
// C.DisableFrame(a.app)
|
C.DisableFrame(a.app)
|
||||||
// }
|
}
|
||||||
|
|
||||||
if a.config.RGBA != 0 {
|
if a.config.RGBA != 0 {
|
||||||
r, g, b, alpha := intToColour(a.config.RGBA)
|
r, g, b, alpha := intToColour(a.config.RGBA)
|
||||||
|
@ -1,13 +1,7 @@
|
|||||||
package ffenestri
|
package ffenestri
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
#cgo linux CFLAGS: -DFFENESTRI_LINUX=1
|
|
||||||
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "ffenestri.h"
|
#include "ffenestri.h"
|
||||||
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
@ -1,34 +1,22 @@
|
|||||||
// Some code may be inspired by or directly used from Webview.
|
// Some code may be inspired by or directly used from Webview.
|
||||||
#include "ffenestri_windows.h"
|
#include "ffenestri_windows.h"
|
||||||
|
//#include "wv2ComHandler_windows.h"
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
DWORD mainThread;
|
DWORD mainThread;
|
||||||
|
|
||||||
typedef void(*dispatchMethod)(void);
|
|
||||||
typedef void(*dispatchMethod1)(void*);
|
|
||||||
typedef void(*dispatchMethod2)(void*,void*);
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
void* func;
|
|
||||||
void* args[5];
|
|
||||||
int argc;
|
|
||||||
} dispatchFunction;
|
|
||||||
|
|
||||||
dispatchFunction* NewDispatchFunction(void *func) {
|
|
||||||
dispatchFunction *result = (dispatchFunction *)malloc(sizeof(dispatchFunction));
|
|
||||||
result->func = func;
|
|
||||||
result->argc = 0;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// dispatch will execute the given `func` pointer
|
// dispatch will execute the given `func` pointer
|
||||||
void dispatch(dispatchFunction *func) {
|
void dispatch(dispatchFunction func) {
|
||||||
PostThreadMessage(mainThread, WM_APP, 0, (LPARAM) func);
|
PostThreadMessage(mainThread, WM_APP, 0, (LPARAM) new dispatchFunction(func));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Application{
|
struct Application{
|
||||||
// Window specific
|
// Window specific
|
||||||
HWND window;
|
HWND window;
|
||||||
|
// WebViewControl webview;
|
||||||
|
// ICoreWebView2Controller* controller;
|
||||||
|
|
||||||
|
|
||||||
// Application
|
// Application
|
||||||
const char *title;
|
const char *title;
|
||||||
@ -54,6 +42,10 @@ struct Application *NewApplication(const char *title, int width, int height, int
|
|||||||
// Create application
|
// Create application
|
||||||
struct Application *result = (struct Application*)malloc(sizeof(struct Application));
|
struct Application *result = (struct Application*)malloc(sizeof(struct Application));
|
||||||
|
|
||||||
|
result->window = nullptr;
|
||||||
|
// result->webview = nullptr;
|
||||||
|
// result->controller = nullptr;
|
||||||
|
|
||||||
result->title = title;
|
result->title = title;
|
||||||
result->width = width;
|
result->width = width;
|
||||||
result->height = height;
|
result->height = height;
|
||||||
@ -138,6 +130,43 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//void initWebView2(struct Application *app, int debug, messageCallback cb) {
|
||||||
|
// CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||||
|
//
|
||||||
|
// std::atomic_flag flag = ATOMIC_FLAG_INIT;
|
||||||
|
// flag.test_and_set();
|
||||||
|
//
|
||||||
|
// char currentExePath[MAX_PATH];
|
||||||
|
// GetModuleFileNameA(NULL, currentExePath, MAX_PATH);
|
||||||
|
// char *currentExeName = PathFindFileNameA(currentExePath);
|
||||||
|
//
|
||||||
|
// std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> wideCharConverter;
|
||||||
|
// std::wstring userDataFolder = wideCharConverter.from_bytes(std::getenv("APPDATA"));
|
||||||
|
// std::wstring currentExeNameW = wideCharConverter.from_bytes(currentExeName);
|
||||||
|
//
|
||||||
|
// HRESULT res = CreateCoreWebView2EnvironmentWithOptions(
|
||||||
|
// nullptr, (userDataFolder + L"/" + currentExeNameW).c_str(), nullptr,
|
||||||
|
// new wv2ComHandler(app->window, cb,
|
||||||
|
// [&](ICoreWebView2Controller *controller) {
|
||||||
|
// app->controller = controller;
|
||||||
|
// app->controller->get_CoreWebView2(&(app->webview));
|
||||||
|
// app->webview->AddRef();
|
||||||
|
// flag.clear();
|
||||||
|
// }));
|
||||||
|
// if (res != S_OK) {
|
||||||
|
// CoUninitialize();
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// MSG msg = {};
|
||||||
|
// while (flag.test_and_set() && GetMessage(&msg, NULL, 0, 0)) {
|
||||||
|
// TranslateMessage(&msg);
|
||||||
|
// DispatchMessage(&msg);
|
||||||
|
// }
|
||||||
|
// init("window.external={invoke:s=>window.chrome.webview.postMessage(s)}");
|
||||||
|
// return true;
|
||||||
|
//}
|
||||||
|
|
||||||
void Run(struct Application* app, int argc, char **argv) {
|
void Run(struct Application* app, int argc, char **argv) {
|
||||||
|
|
||||||
WNDCLASSEX wc;
|
WNDCLASSEX wc;
|
||||||
@ -163,9 +192,9 @@ void Run(struct Application* app, int argc, char **argv) {
|
|||||||
app->window = CreateWindow((LPCWSTR)"ffenestri", (LPCWSTR)"", windowStyle, CW_USEDEFAULT,
|
app->window = CreateWindow((LPCWSTR)"ffenestri", (LPCWSTR)"", windowStyle, CW_USEDEFAULT,
|
||||||
CW_USEDEFAULT, app->width, app->height, NULL, NULL,
|
CW_USEDEFAULT, app->width, app->height, NULL, NULL,
|
||||||
GetModuleHandle(NULL), NULL);
|
GetModuleHandle(NULL), NULL);
|
||||||
// Set Title
|
|
||||||
setTitle(app, app->title);
|
|
||||||
|
|
||||||
|
// Private setTitle as we're on the main thread
|
||||||
|
setTitle(app, app->title);
|
||||||
|
|
||||||
// Store application pointer in window handle
|
// Store application pointer in window handle
|
||||||
SetWindowLongPtr(app->window, GWLP_USERDATA, (LONG_PTR)app);
|
SetWindowLongPtr(app->window, GWLP_USERDATA, (LONG_PTR)app);
|
||||||
@ -175,6 +204,7 @@ void Run(struct Application* app, int argc, char **argv) {
|
|||||||
if ( app->startHidden == 1 ) {
|
if ( app->startHidden == 1 ) {
|
||||||
startVisibility = SW_HIDE;
|
startVisibility = SW_HIDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private center() as we are on main thread
|
// private center() as we are on main thread
|
||||||
center(app);
|
center(app);
|
||||||
ShowWindow(app->window, startVisibility);
|
ShowWindow(app->window, startVisibility);
|
||||||
@ -182,6 +212,7 @@ void Run(struct Application* app, int argc, char **argv) {
|
|||||||
SetFocus(app->window);
|
SetFocus(app->window);
|
||||||
|
|
||||||
// TODO: Add webview2
|
// TODO: Add webview2
|
||||||
|
// initWebView2(app->window);
|
||||||
|
|
||||||
// Main event loop
|
// Main event loop
|
||||||
MSG msg;
|
MSG msg;
|
||||||
@ -193,15 +224,9 @@ void Run(struct Application* app, int argc, char **argv) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (msg.message == WM_APP) {
|
if (msg.message == WM_APP) {
|
||||||
dispatchFunction *m = (dispatchFunction*) msg.lParam;
|
dispatchFunction *f = (dispatchFunction*) msg.lParam;
|
||||||
void *method = m->func;
|
(*f)();
|
||||||
if (m->argc == 1) {
|
delete(f);
|
||||||
((dispatchMethod1)method)(m->args[0]);
|
|
||||||
}
|
|
||||||
if (m->argc == 2) {
|
|
||||||
((dispatchMethod2)method)(m->args[0], m->args[1]);
|
|
||||||
}
|
|
||||||
free(m);
|
|
||||||
} else if (msg.message == WM_QUIT) {
|
} else if (msg.message == WM_QUIT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -226,10 +251,9 @@ void hide(struct Application* app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Hide(struct Application* app) {
|
void Hide(struct Application* app) {
|
||||||
dispatchFunction *f = NewDispatchFunction((void*)hide);
|
ON_MAIN_THREAD(
|
||||||
f->args[0] = app;
|
hide(app);
|
||||||
f->argc = 1;
|
);
|
||||||
dispatch(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void show(struct Application* app) {
|
void show(struct Application* app) {
|
||||||
@ -237,10 +261,9 @@ void show(struct Application* app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Show(struct Application* app) {
|
void Show(struct Application* app) {
|
||||||
dispatchFunction *f = NewDispatchFunction((void*)show);
|
ON_MAIN_THREAD(
|
||||||
f->args[0] = app;
|
show(app);
|
||||||
f->argc = 1;
|
);
|
||||||
dispatch(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void center(struct Application* app) {
|
void center(struct Application* app) {
|
||||||
@ -268,10 +291,9 @@ void center(struct Application* app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Center(struct Application* app) {
|
void Center(struct Application* app) {
|
||||||
dispatchFunction *f = NewDispatchFunction((void*)center);
|
ON_MAIN_THREAD(
|
||||||
f->args[0] = app;
|
center(app);
|
||||||
f->argc = 1;
|
);
|
||||||
dispatch(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT getWindowPlacement(struct Application* app) {
|
UINT getWindowPlacement(struct Application* app) {
|
||||||
@ -294,10 +316,9 @@ void maximise(struct Application* app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Maximise(struct Application* app) {
|
void Maximise(struct Application* app) {
|
||||||
dispatchFunction *f = NewDispatchFunction((void*)maximise);
|
ON_MAIN_THREAD(
|
||||||
f->args[0] = app;
|
maximise(app);
|
||||||
f->argc = 1;
|
);
|
||||||
dispatch(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void unmaximise(struct Application* app) {
|
void unmaximise(struct Application* app) {
|
||||||
@ -305,10 +326,9 @@ void unmaximise(struct Application* app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Unmaximise(struct Application* app) {
|
void Unmaximise(struct Application* app) {
|
||||||
dispatchFunction *f = NewDispatchFunction((void*)unmaximise);
|
ON_MAIN_THREAD(
|
||||||
f->args[0] = app;
|
unmaximise(app);
|
||||||
f->argc = 1;
|
);
|
||||||
dispatch(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -328,10 +348,9 @@ void minimise(struct Application* app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Minimise(struct Application* app) {
|
void Minimise(struct Application* app) {
|
||||||
dispatchFunction *f = NewDispatchFunction((void*)minimise);
|
ON_MAIN_THREAD(
|
||||||
f->args[0] = app;
|
minimise(app);
|
||||||
f->argc = 1;
|
);
|
||||||
dispatch(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void unminimise(struct Application* app) {
|
void unminimise(struct Application* app) {
|
||||||
@ -339,10 +358,9 @@ void unminimise(struct Application* app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Unminimise(struct Application* app) {
|
void Unminimise(struct Application* app) {
|
||||||
dispatchFunction *f = NewDispatchFunction((void*)unminimise);
|
ON_MAIN_THREAD(
|
||||||
f->args[0] = app;
|
unminimise(app);
|
||||||
f->argc = 1;
|
);
|
||||||
dispatch(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToggleMinimise(struct Application* app) {
|
void ToggleMinimise(struct Application* app) {
|
||||||
@ -353,13 +371,23 @@ void ToggleMinimise(struct Application* app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SetColour(struct Application* app, int red, int green, int blue, int alpha) {
|
void SetColour(struct Application* app, int red, int green, int blue, int alpha) {
|
||||||
|
// TBD
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetSize(struct Application* app, int width, int height) {
|
void SetSize(struct Application* app, int width, int height) {
|
||||||
|
// TBD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPosition(struct Application* app, int x, int y) {
|
||||||
|
// TBD
|
||||||
|
}
|
||||||
|
|
||||||
void SetPosition(struct Application* app, int x, int y) {
|
void SetPosition(struct Application* app, int x, int y) {
|
||||||
|
ON_MAIN_THREAD(
|
||||||
|
setPosition(app, x, y);
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quit(struct Application* app) {
|
void Quit(struct Application* app) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,11 +401,9 @@ void setTitle(struct Application* app, const char *title) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SetTitle(struct Application* app, const char *title) {
|
void SetTitle(struct Application* app, const char *title) {
|
||||||
dispatchFunction *f = NewDispatchFunction((void*)setTitle);
|
ON_MAIN_THREAD(
|
||||||
f->args[0] = app;
|
setTitle(app, title);
|
||||||
f->args[1] = (void*)title;
|
);
|
||||||
f->argc = 2;
|
|
||||||
dispatch(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fullscreen(struct Application* app) {
|
void Fullscreen(struct Application* app) {
|
||||||
|
@ -1,15 +1,5 @@
|
|||||||
package ffenestri
|
package ffenestri
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
#cgo windows,amd64 LDFLAGS: -L./windows/x64 -lwebview -lWebView2Loader -lgdi32
|
|
||||||
|
|
||||||
#include "ffenestri.h"
|
|
||||||
#include "ffenestri_windows.h"
|
|
||||||
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
func (a *Application) processPlatformSettings() error {
|
func (a *Application) processPlatformSettings() error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -7,6 +7,13 @@
|
|||||||
#include "ffenestri.h"
|
#include "ffenestri.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <wingdi.h>
|
#include <wingdi.h>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#define ON_MAIN_THREAD(code) dispatch( [=]{ code; } )
|
||||||
|
|
||||||
|
typedef std::function<void()> dispatchFunction;
|
||||||
|
//typedef std::function<void(const std::string)> messageCallback;
|
||||||
|
//typedef std::function<void(ICoreWebView2Controller *)> comHandlerCallback;
|
||||||
|
|
||||||
void center(struct Application*);
|
void center(struct Application*);
|
||||||
void setTitle(struct Application* app, const char *title);
|
void setTitle(struct Application* app, const char *title);
|
||||||
|
@ -1,2 +1 @@
|
|||||||
g++ main.c ..\..\ffenestri_windows.cpp -lgdi32
|
g++ main.c ..\..\ffenestri_windows.cpp -lgdi32 -std=c++11
|
||||||
a.exe
|
|
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
struct Application *app = NewApplication("Wails ❤️ Unicode", 800, 600, 1, 1, 0, 0, 1, 0);
|
struct Application *app = NewApplication("Wails ❤️ Unicode", 800, 600, 1, 1, 0, 0, 1, 0);
|
||||||
SetMinWindowSize(app, 100, 100);
|
// SetMinWindowSize(app, 100, 100);
|
||||||
SetMaxWindowSize(app, 800, 800);
|
// SetMaxWindowSize(app, 800, 800);
|
||||||
Run(app,0, NULL);
|
Run(app,0, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ type App struct {
|
|||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
DisableResize bool
|
DisableResize bool
|
||||||
|
Frameless bool
|
||||||
Fullscreen bool
|
Fullscreen bool
|
||||||
Frameless bool
|
Frameless bool
|
||||||
MinWidth int
|
MinWidth int
|
||||||
|
Loading…
Reference in New Issue
Block a user