mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-19 02:19:31 +08:00
Add Center + refactor prefs
This commit is contained in:
parent
d42b84abc1
commit
dd3e6de9b2
@ -62,7 +62,6 @@ BOOL yes(id self, SEL cmd)
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Debug works like sprintf but mutes if the global debug flag is true
|
// Debug works like sprintf but mutes if the global debug flag is true
|
||||||
// Credit: https://stackoverflow.com/a/20639708
|
// Credit: https://stackoverflow.com/a/20639708
|
||||||
void Debug(char *message, ... ) {
|
void Debug(char *message, ... ) {
|
||||||
@ -122,6 +121,11 @@ void messageHandler(id self, SEL cmd, id contentController, id message) {
|
|||||||
app->sendMessageToBackend(m);
|
app->sendMessageToBackend(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// closeWindow is called when the close button is pressed
|
||||||
|
void closeWindow(id self, SEL cmd, id sender) {
|
||||||
|
struct Application *app = (struct Application *) objc_getAssociatedObject(self, "application");
|
||||||
|
app->sendMessageToBackend("WC");
|
||||||
|
}
|
||||||
|
|
||||||
void* NewApplication(const char *title, int width, int height, int resizable, int devtools, int fullscreen) {
|
void* NewApplication(const char *title, int width, int height, int resizable, int devtools, int fullscreen) {
|
||||||
// Setup main application struct
|
// Setup main application struct
|
||||||
@ -163,9 +167,6 @@ void DestroyApplication(void *appPointer) {
|
|||||||
// used by the application
|
// used by the application
|
||||||
void Quit(void *appPointer) {
|
void Quit(void *appPointer) {
|
||||||
Debug("Quit Called");
|
Debug("Quit Called");
|
||||||
// struct Application *app = (struct Application*) appPointer;
|
|
||||||
// gtk_window_close((GtkWindow*)app->mainWindow);
|
|
||||||
// g_application_quit((GApplication*)app->application);
|
|
||||||
DestroyApplication(appPointer);
|
DestroyApplication(appPointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,8 +193,8 @@ void UnFullscreen(void *appPointer) {
|
|||||||
|
|
||||||
void Center(void *appPointer) {
|
void Center(void *appPointer) {
|
||||||
Debug("Center Called");
|
Debug("Center Called");
|
||||||
// struct Application *app = (struct Application*) appPointer;
|
struct Application *app = (struct Application *)appPointer;
|
||||||
// gtk_window_set_position(app->mainWindow, GTK_WIN_POS_CENTER);
|
objc_msgSend(app->mainWindow, s("center"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetMaximumSize(void *appPointer, int width, int height) {
|
void SetMaximumSize(void *appPointer, int width, int height) {
|
||||||
@ -639,20 +640,9 @@ void SetBindings(void* applicationPointer, const char *bindings) {
|
|||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
void enableBoolConfig(id config, const char *setting) {
|
||||||
// static void
|
msg(msg(config, s("preferences")), s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 1), str(setting));
|
||||||
// activate (GtkApplication* app,
|
}
|
||||||
// gpointer user_data)
|
|
||||||
// {
|
|
||||||
// struct Application *mainApp = (struct Application*) user_data;
|
|
||||||
|
|
||||||
// // Main Window
|
|
||||||
// setupWindow(mainApp);
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Run(void *applicationPointer, int argc, char **argv) {
|
void Run(void *applicationPointer, int argc, char **argv) {
|
||||||
struct Application *app = (struct Application*) applicationPointer;
|
struct Application *app = (struct Application*) applicationPointer;
|
||||||
@ -688,6 +678,9 @@ void Run(void *applicationPointer, int argc, char **argv) {
|
|||||||
// Set the main window title
|
// Set the main window title
|
||||||
SetTitle(app, app->title);
|
SetTitle(app, app->title);
|
||||||
|
|
||||||
|
// Center Window
|
||||||
|
Center(app);
|
||||||
|
|
||||||
// Setup webview
|
// Setup webview
|
||||||
id config = msg(c("WKWebViewConfiguration"), s("new"));
|
id config = msg(c("WKWebViewConfiguration"), s("new"));
|
||||||
id manager = msg(config, s("userContentController"));
|
id manager = msg(config, s("userContentController"));
|
||||||
@ -697,7 +690,7 @@ void Run(void *applicationPointer, int argc, char **argv) {
|
|||||||
// TODO: Fix "NSWindow warning: adding an unknown subview: <WKInspectorWKWebView: 0x465ed90>. Break on NSLog to debug." error
|
// TODO: Fix "NSWindow warning: adding an unknown subview: <WKInspectorWKWebView: 0x465ed90>. Break on NSLog to debug." error
|
||||||
if (app->devtools) {
|
if (app->devtools) {
|
||||||
Debug("Enabling devtools");
|
Debug("Enabling devtools");
|
||||||
msg(msg(config, s("preferences")), s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 1), str("developerExtrasEnabled"));
|
enableBoolConfig(config, "developerExtrasEnabled");
|
||||||
}
|
}
|
||||||
// TODO: Understand why this shouldn't be CGRectMake(0, 0, app->width, app->height)
|
// TODO: Understand why this shouldn't be CGRectMake(0, 0, app->width, app->height)
|
||||||
msg(wkwebview, s("initWithFrame:configuration:"), CGRectMake(0, 0, 0, 0), config);
|
msg(wkwebview, s("initWithFrame:configuration:"), CGRectMake(0, 0, 0, 0), config);
|
||||||
@ -705,6 +698,8 @@ void Run(void *applicationPointer, int argc, char **argv) {
|
|||||||
msg(manager, s("addScriptMessageHandler:name:"), delegate, str("external"));
|
msg(manager, s("addScriptMessageHandler:name:"), delegate, str("external"));
|
||||||
msg(mainWindow, s("setContentView:"), wkwebview);
|
msg(mainWindow, s("setContentView:"), wkwebview);
|
||||||
msg(mainWindow, s("makeKeyAndOrderFront:"), NULL);
|
msg(mainWindow, s("makeKeyAndOrderFront:"), NULL);
|
||||||
|
// msg(mainWindow, s("setHidden:"), true);
|
||||||
|
|
||||||
|
|
||||||
// Load HTML
|
// Load HTML
|
||||||
id html = msg(c("NSURL"), s("URLWithString:"), msg(c("NSString"), s("stringWithUTF8String:"), assets[0]));
|
id html = msg(c("NSURL"), s("URLWithString:"), msg(c("NSString"), s("stringWithUTF8String:"), assets[0]));
|
||||||
@ -737,6 +732,7 @@ void Run(void *applicationPointer, int argc, char **argv) {
|
|||||||
index++;
|
index++;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class_addMethod(delegateClass, s("closeWindow"), closeWindow, "v@:@");
|
||||||
// TODO: Check if we can split out the User JS/CSS from the MOAE
|
// TODO: Check if we can split out the User JS/CSS from the MOAE
|
||||||
|
|
||||||
// Debug("MOAE: %s", internalCode);
|
// Debug("MOAE: %s", internalCode);
|
||||||
@ -753,6 +749,7 @@ void Run(void *applicationPointer, int argc, char **argv) {
|
|||||||
|
|
||||||
// Finally call run
|
// Finally call run
|
||||||
Debug("Run called");
|
Debug("Run called");
|
||||||
|
msg(application, s("activateIgnoringOtherApps:"), true);
|
||||||
msg(application, s("run"));
|
msg(application, s("run"));
|
||||||
|
|
||||||
free((void*)internalCode);
|
free((void*)internalCode);
|
||||||
|
Loading…
Reference in New Issue
Block a user