From 72fc2204b4e1a0d75415f28a6c3d3201988ab4d4 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Thu, 24 Sep 2020 05:46:39 +1000 Subject: [PATCH] Moved options to own package --- v2/internal/app/default.go | 4 ++-- v2/internal/app/desktop.go | 4 ++-- v2/internal/ffenestri/ffenestri.go | 8 +++---- .../appoptions => pkg/options}/default.go | 4 ++-- .../appoptions => pkg/options}/mac.go | 6 ++--- .../appoptions => pkg/options}/options.go | 22 +++++++++---------- v2/test/runtime/main.go | 5 +++-- v2/wails.go | 12 +++------- 8 files changed, 30 insertions(+), 35 deletions(-) rename v2/{internal/appoptions => pkg/options}/default.go (76%) rename v2/{internal/appoptions => pkg/options}/mac.go (70%) rename v2/{internal/appoptions => pkg/options}/options.go (61%) diff --git a/v2/internal/app/default.go b/v2/internal/app/default.go index 35488847..cc128298 100644 --- a/v2/internal/app/default.go +++ b/v2/internal/app/default.go @@ -10,7 +10,7 @@ package app import ( "os" - "github.com/wailsapp/wails/v2/internal/appoptions" + "github.com/wailsapp/wails/v2/pkg/options" ) // App defines a Wails application structure @@ -25,7 +25,7 @@ type App struct { } // CreateApp returns a null application -func CreateApp(options *appoptions.Options) *App { +func CreateApp(options *options.App) *App { return &App{} } diff --git a/v2/internal/app/desktop.go b/v2/internal/app/desktop.go index 5f249511..39d6c0fb 100644 --- a/v2/internal/app/desktop.go +++ b/v2/internal/app/desktop.go @@ -5,7 +5,6 @@ package app import ( "os" - "github.com/wailsapp/wails/v2/internal/appoptions" "github.com/wailsapp/wails/v2/internal/binding" "github.com/wailsapp/wails/v2/internal/ffenestri" "github.com/wailsapp/wails/v2/internal/logger" @@ -13,6 +12,7 @@ import ( "github.com/wailsapp/wails/v2/internal/servicebus" "github.com/wailsapp/wails/v2/internal/signal" "github.com/wailsapp/wails/v2/internal/subsystem" + "github.com/wailsapp/wails/v2/pkg/options" ) // App defines a Wails application structure @@ -38,7 +38,7 @@ type App struct { } // Create App -func CreateApp(options *appoptions.Options) *App { +func CreateApp(options *options.App) *App { // Merge default options options.MergeDefaults() diff --git a/v2/internal/ffenestri/ffenestri.go b/v2/internal/ffenestri/ffenestri.go index 2d5b7330..66900445 100644 --- a/v2/internal/ffenestri/ffenestri.go +++ b/v2/internal/ffenestri/ffenestri.go @@ -5,9 +5,9 @@ import ( "strings" "unsafe" - "github.com/wailsapp/wails/v2/internal/appoptions" "github.com/wailsapp/wails/v2/internal/logger" "github.com/wailsapp/wails/v2/internal/messagedispatcher" + "github.com/wailsapp/wails/v2/pkg/options" ) /* @@ -58,7 +58,7 @@ var DEBUG bool = true // Application is our main application object type Application struct { - config *appoptions.Options + config *options.App memory []unsafe.Pointer // This is the main app pointer @@ -83,7 +83,7 @@ func init() { } // NewApplicationWithConfig creates a new application based on the given config -func NewApplicationWithConfig(config *appoptions.Options, logger *logger.Logger) *Application { +func NewApplicationWithConfig(config *options.App, logger *logger.Logger) *Application { return &Application{ config: config, logger: logger.CustomLogger("Ffenestri"), @@ -93,7 +93,7 @@ func NewApplicationWithConfig(config *appoptions.Options, logger *logger.Logger) // NewApplication creates a new Application with the default config func NewApplication(logger *logger.Logger) *Application { return &Application{ - config: appoptions.Default, + config: options.Default, logger: logger.CustomLogger("Ffenestri"), } } diff --git a/v2/internal/appoptions/default.go b/v2/pkg/options/default.go similarity index 76% rename from v2/internal/appoptions/default.go rename to v2/pkg/options/default.go index 1c0d17b4..3762dd5e 100644 --- a/v2/internal/appoptions/default.go +++ b/v2/pkg/options/default.go @@ -1,7 +1,7 @@ -package appoptions +package options // Default options for creating the App -var Default = &Options{ +var Default = &App{ Title: "My Wails App", Width: 1024, Height: 768, diff --git a/v2/internal/appoptions/mac.go b/v2/pkg/options/mac.go similarity index 70% rename from v2/internal/appoptions/mac.go rename to v2/pkg/options/mac.go index 155434b5..2ed5509c 100644 --- a/v2/internal/appoptions/mac.go +++ b/v2/pkg/options/mac.go @@ -1,7 +1,7 @@ -package appoptions +package options -// MacOptions ae options speific to Mas -type MacOptions struct { +// Mac ae options speific to Mas +type Mac struct { TitlebarAppearsTransparent bool HideTitle bool HideTitleBar bool diff --git a/v2/internal/appoptions/options.go b/v2/pkg/options/options.go similarity index 61% rename from v2/internal/appoptions/options.go rename to v2/pkg/options/options.go index 068ac516..a77f2bea 100644 --- a/v2/internal/appoptions/options.go +++ b/v2/pkg/options/options.go @@ -1,7 +1,7 @@ -package appoptions +package options -// Options for creating the App -type Options struct { +// App contains options for creating the App +type App struct { Title string Width int Height int @@ -15,24 +15,24 @@ type Options struct { StartHidden bool DevTools bool Colour int - Mac MacOptions + Mac Mac } // MergeDefaults will set the minimum default values for an application -func (o *Options) MergeDefaults() { +func (a *App) MergeDefaults() { // Create a default title - if len(o.Title) == 0 { - o.Title = "My Wails App" + if len(a.Title) == 0 { + a.Title = "My Wails App" } // Default width - if o.Width == 0 { - o.Width = 1024 + if a.Width == 0 { + a.Width = 1024 } // Default height - if o.Height == 0 { - o.Height = 768 + if a.Height == 0 { + a.Height = 768 } } diff --git a/v2/test/runtime/main.go b/v2/test/runtime/main.go index e65d0df4..dc242ef7 100644 --- a/v2/test/runtime/main.go +++ b/v2/test/runtime/main.go @@ -2,6 +2,7 @@ package main import ( wails "github.com/wailsapp/wails/v2" + "github.com/wailsapp/wails/v2/pkg/options" ) type Echo struct { @@ -14,14 +15,14 @@ func (e *Echo) Echo(message string) string { func main() { // Create application with options - app := wails.CreateAppWithOptions(&wails.Options{ + app := wails.CreateAppWithOptions(&options.App{ Title: "Runtime Tester!", Width: 850, Height: 620, DisableResize: false, Fullscreen: false, Colour: 0xFF000088, - Mac: wails.MacOptions{ + Mac: options.Mac{ HideTitle: false, HideTitleBar: false, TitlebarAppearsTransparent: true, diff --git a/v2/wails.go b/v2/wails.go index 6a50a695..02433eaa 100644 --- a/v2/wails.go +++ b/v2/wails.go @@ -4,28 +4,22 @@ package wails import ( "github.com/wailsapp/wails/v2/internal/app" - "github.com/wailsapp/wails/v2/internal/appoptions" "github.com/wailsapp/wails/v2/internal/runtime/goruntime" + "github.com/wailsapp/wails/v2/pkg/options" ) // Runtime is an alias for the goruntime.Runtime struct type Runtime = goruntime.Runtime -// Options is an alias for the app.Options struct -type Options = appoptions.Options - -// MacOptions are Mac specific options -type MacOptions = appoptions.MacOptions - // CreateAppWithOptions creates an application based on the given config -func CreateAppWithOptions(options *Options) *app.App { +func CreateAppWithOptions(options *options.App) *app.App { return app.CreateApp(options) } // CreateApp creates an application based on the given title, width and height func CreateApp(title string, width int, height int) *app.App { - options := &Options{ + options := &options.App{ Title: title, Width: width, Height: height,