From d5cbfa67490b223c76bd148a3db6c781e51037d4 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Fri, 4 Jun 2021 20:36:56 +1000 Subject: [PATCH] [linux] Support `wails build` and `wails dev` --- v2/cmd/wails/internal/commands/build/build.go | 1 + v2/internal/ffenestri/ffenestri_linux.c | 61 +++++++++++-------- v2/internal/ffenestri/ffenestri_linux.go | 17 ++++++ v2/internal/ffenestri/ffenestri_linux.h | 6 ++ v2/pkg/commands/build/desktop_linux.go | 2 +- 5 files changed, 61 insertions(+), 26 deletions(-) create mode 100644 v2/internal/ffenestri/ffenestri_linux.go create mode 100644 v2/internal/ffenestri/ffenestri_linux.h diff --git a/v2/cmd/wails/internal/commands/build/build.go b/v2/cmd/wails/internal/commands/build/build.go index 5bc79e668..7d6953615 100644 --- a/v2/cmd/wails/internal/commands/build/build.go +++ b/v2/cmd/wails/internal/commands/build/build.go @@ -98,6 +98,7 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { "darwin/amd64", "darwin/arm64", "darwin/universal", + "linux", //"linux/amd64", //"linux/arm-7", "windows", diff --git a/v2/internal/ffenestri/ffenestri_linux.c b/v2/internal/ffenestri/ffenestri_linux.c index b06a4d681..f31cb6205 100644 --- a/v2/internal/ffenestri/ffenestri_linux.c +++ b/v2/internal/ffenestri/ffenestri_linux.c @@ -2,6 +2,7 @@ #ifndef __FFENESTRI_LINUX_H__ #define __FFENESTRI_LINUX_H__ +#include "common.h" #include "gtk/gtk.h" #include "webkit2/webkit2.h" #include @@ -11,9 +12,10 @@ #include // References to assets -extern const unsigned char *assets[]; extern const unsigned char runtime; -extern const char *icon[]; + +#include "icon.h" +#include "assets.h" // Constants #define PRIMARY_MOUSE_BUTTON 1 @@ -23,17 +25,6 @@ extern const char *icon[]; // MAIN DEBUG FLAG int debug; -// Credit: https://stackoverflow.com/a/8465083 -char *concat(const char *s1, const char *s2) -{ - const size_t len1 = strlen(s1); - const size_t len2 = strlen(s2); - char *result = malloc(len1 + len2 + 1); - memcpy(result, s1, len1); - memcpy(result + len1, s2, len2 + 1); - return result; -} - // Debug works like sprintf but mutes if the global debug flag is true // Credit: https://stackoverflow.com/a/20639708 void Debug(char *message, ...) @@ -312,17 +303,17 @@ void SetMaxWindowSize(struct Application *app, int maxWidth, int maxHeight) } // SetColour sets the colour of the webview to the given colour string -int SetColour(struct Application *app, const char *colourString) +void SetColour(struct Application *app, int red, int green, int blue, int alpha) { - GdkRGBA rgba; - gboolean result = gdk_rgba_parse(&rgba, colourString); - if (result == FALSE) - { - return 0; - } - // Debug("Setting webview colour to: %s", colourString); - webkit_web_view_get_background_color((WebKitWebView *)(app->webView), &rgba); - return 1; +// GdkRGBA rgba; +// rgba. +// gboolean result = gdk_rgba_parse(&rgba, colourString); +// if (result == FALSE) +// { +// return 0; +// } +// // Debug("Setting webview colour to: %s", colourString); +// webkit_web_view_get_background_color((WebKitWebView *)(app->webView), &rgba); } // DisableFrame disables the window frame @@ -523,6 +514,11 @@ static void load_finished_cb(WebKitWebView *webView, Debug("Binding Methods"); syncEval(app, app->bindings); + // Setup IPC commands + Debug("Setting up IPC methods"); + const char *invoke = "window.wailsInvoke=function(message){window.webkit.messageHandlers.external.postMessage(message);};window.wailsDrag=function(message){window.webkit.messageHandlers.windowDrag.postMessage(message);};window.wailsContextMenuMessage=function(message){window.webkit.messageHandlers.contextMenu.postMessage(message);};"; + syncEval(app, invoke); + // Runtime Debug("Setting up Wails runtime"); syncEval(app, &runtime); @@ -824,7 +820,7 @@ void Show(struct Application *app) { // maximiseInternal maximises the main window void maximiseInternal(struct Application *app) { - gtk_window_maximize(GTK_WIDGET(app->mainWindow)); + gtk_window_maximize(GTK_WINDOW(app->mainWindow)); } // Maximise places the maximiseInternal method onto the main thread for execution @@ -841,7 +837,7 @@ void Maximise(struct Application *app) { // unmaximiseInternal unmaximises the main window void unmaximiseInternal(struct Application *app) { - gtk_window_unmaximize(GTK_WIDGET(app->mainWindow)); + gtk_window_unmaximize(GTK_WINDOW(app->mainWindow)); } // Unmaximise places the unmaximiseInternal method onto the main thread for execution @@ -857,6 +853,21 @@ void Unmaximise(struct Application *app) { } +void DarkModeEnabled(struct Application*, char *callbackID) {} +void SetApplicationMenu(struct Application*, const char *) {} +void AddTrayMenu(struct Application*, const char *menuTrayJSON) {} +void SetTrayMenu(struct Application*, const char *menuTrayJSON) {} +void DeleteTrayMenuByID(struct Application*, const char *id) {} +void UpdateTrayMenuLabel(struct Application*, const char* JSON) {} +void AddContextMenu(struct Application*, char *contextMenuJSON) {} +void UpdateContextMenu(struct Application*, char *contextMenuJSON) {} +void WebviewIsTransparent(struct Application*) {} +void WindowBackgroundIsTranslucent(struct Application*) {} +void OpenDialog(struct Application*, char *callbackID, char *title, char *filters, char *defaultFilename, char *defaultDir, int allowFiles, int allowDirs, int allowMultiple, int showHiddenFiles, int canCreateDirectories, int resolvesAliases, int treatPackagesAsDirectories) {} +void SaveDialog(struct Application*, char *callbackID, char *title, char *filters, char *defaultFilename, char *defaultDir, int showHiddenFiles, int canCreateDirectories, int treatPackagesAsDirectories) {} +void MessageDialog(struct Application*, char *callbackID, char *type, char *title, char *message, char *icon, char *button1, char *button2, char *button3, char *button4, char *defaultButton, char *cancelButton) {} + + // minimiseInternal minimises the main window void minimiseInternal(struct Application *app) { gtk_window_iconify(app->mainWindow); diff --git a/v2/internal/ffenestri/ffenestri_linux.go b/v2/internal/ffenestri/ffenestri_linux.go new file mode 100644 index 000000000..ca7abe7a1 --- /dev/null +++ b/v2/internal/ffenestri/ffenestri_linux.go @@ -0,0 +1,17 @@ +package ffenestri + +/* +#cgo linux CFLAGS: -DFFENESTRI_LINUX=1 +#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0 + + +#include "ffenestri.h" +#include "ffenestri_linux.h" + +*/ +import "C" + +func (a *Application) processPlatformSettings() error { + + return nil +} diff --git a/v2/internal/ffenestri/ffenestri_linux.h b/v2/internal/ffenestri/ffenestri_linux.h new file mode 100644 index 000000000..26902d334 --- /dev/null +++ b/v2/internal/ffenestri/ffenestri_linux.h @@ -0,0 +1,6 @@ + +#ifndef FFENESTRI_LINUX_H +#define FFENESTRI_LINUX_H + + +#endif \ No newline at end of file diff --git a/v2/pkg/commands/build/desktop_linux.go b/v2/pkg/commands/build/desktop_linux.go index 1ad17de8c..f72100ffb 100644 --- a/v2/pkg/commands/build/desktop_linux.go +++ b/v2/pkg/commands/build/desktop_linux.go @@ -17,7 +17,7 @@ func (d *DesktopBuilder) compileIcon(assetDir string, iconFile string) error { // Load icon into a databuffer targetFilename := "icon" - targetFile := filepath.Join(assetDir, targetFilename+".c") + targetFile := filepath.Join(assetDir, targetFilename+".h") d.addFileToDelete(targetFile)