mirror of
https://github.com/taigrr/wails.git
synced 2026-04-17 12:15:02 -07:00
feat: major refactor
This commit is contained in:
21
runtime/go/runtime/browser.go
Normal file
21
runtime/go/runtime/browser.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package runtime
|
||||
|
||||
import "github.com/pkg/browser"
|
||||
|
||||
// Browser exposes browser methods to the runtime
|
||||
type Browser struct{}
|
||||
|
||||
// NewBrowser creates a new runtime Browser struct
|
||||
func NewBrowser() *Browser {
|
||||
return &Browser{}
|
||||
}
|
||||
|
||||
// OpenURL opens the given url in the system's default browser
|
||||
func (r *Browser) OpenURL(url string) error {
|
||||
return browser.OpenURL(url)
|
||||
}
|
||||
|
||||
// OpenFile opens the given file in the system's default browser
|
||||
func (r *Browser) OpenFile(filePath string) error {
|
||||
return browser.OpenFile(filePath)
|
||||
}
|
||||
30
runtime/go/runtime/dialog.go
Normal file
30
runtime/go/runtime/dialog.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package runtime
|
||||
|
||||
import "github.com/wailsapp/wails/lib/interfaces"
|
||||
|
||||
// Dialog exposes an interface to native dialogs
|
||||
type Dialog struct {
|
||||
renderer interfaces.Renderer
|
||||
}
|
||||
|
||||
// newDialog creates a new Dialog struct
|
||||
func newDialog(renderer interfaces.Renderer) *Dialog {
|
||||
return &Dialog{
|
||||
renderer: renderer,
|
||||
}
|
||||
}
|
||||
|
||||
// SelectFile prompts the user to select a file
|
||||
func (r *Dialog) SelectFile() string {
|
||||
return r.renderer.SelectFile()
|
||||
}
|
||||
|
||||
// SelectDirectory prompts the user to select a directory
|
||||
func (r *Dialog) SelectDirectory() string {
|
||||
return r.renderer.SelectDirectory()
|
||||
}
|
||||
|
||||
// SelectSaveFile prompts the user to select a file for saving
|
||||
func (r *Dialog) SelectSaveFile() string {
|
||||
return r.renderer.SelectSaveFile()
|
||||
}
|
||||
24
runtime/go/runtime/events.go
Normal file
24
runtime/go/runtime/events.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package runtime
|
||||
|
||||
import "github.com/wailsapp/wails/lib/interfaces"
|
||||
|
||||
// Events exposes the events interface
|
||||
type Events struct {
|
||||
eventManager interfaces.EventManager
|
||||
}
|
||||
|
||||
func newEvents(eventManager interfaces.EventManager) *Events {
|
||||
return &Events{
|
||||
eventManager: eventManager,
|
||||
}
|
||||
}
|
||||
|
||||
// On pass through
|
||||
func (r *Events) On(eventName string, callback func(optionalData ...interface{})) {
|
||||
r.eventManager.On(eventName, callback)
|
||||
}
|
||||
|
||||
// Emit pass through
|
||||
func (r *Events) Emit(eventName string, optionalData ...interface{}) {
|
||||
r.eventManager.Emit(eventName, optionalData...)
|
||||
}
|
||||
16
runtime/go/runtime/filesystem.go
Normal file
16
runtime/go/runtime/filesystem.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package runtime
|
||||
|
||||
import homedir "github.com/mitchellh/go-homedir"
|
||||
|
||||
// FileSystem exposes file system utilities to the runtime
|
||||
type FileSystem struct {}
|
||||
|
||||
// Creates a new FileSystem struct
|
||||
func newFileSystem() *FileSystem {
|
||||
return &FileSystem{}
|
||||
}
|
||||
|
||||
// HomeDir returns the user's home directory
|
||||
func (r *FileSystem) HomeDir() (string, error) {
|
||||
return homedir.Dir()
|
||||
}
|
||||
16
runtime/go/runtime/log.go
Normal file
16
runtime/go/runtime/log.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package runtime
|
||||
|
||||
import "github.com/wailsapp/wails/lib/logger"
|
||||
|
||||
// Log exposes the logging interface to the runtime
|
||||
type Log struct{}
|
||||
|
||||
// newLog creates a new Log struct
|
||||
func newLog() *Log {
|
||||
return &Log{}
|
||||
}
|
||||
|
||||
// New creates a new logger
|
||||
func (r *Log) New(prefix string) *logger.CustomLogger {
|
||||
return logger.NewCustomLogger(prefix)
|
||||
}
|
||||
25
runtime/go/runtime/runtime.go
Normal file
25
runtime/go/runtime/runtime.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package runtime
|
||||
|
||||
import "github.com/wailsapp/wails/lib/interfaces"
|
||||
|
||||
// Runtime is the Wails Runtime Interface, given to a user who has defined the WailsInit method
|
||||
type Runtime struct {
|
||||
Events *Events
|
||||
Log *Log
|
||||
Dialog *Dialog
|
||||
Window *Window
|
||||
Browser *Browser
|
||||
FileSystem *FileSystem
|
||||
}
|
||||
|
||||
// NewRuntime creates a new Runtime struct
|
||||
func NewRuntime(eventManager interfaces.EventManager, renderer interfaces.Renderer) *Runtime {
|
||||
return &Runtime{
|
||||
Events: newEvents(eventManager),
|
||||
Log: newLog(),
|
||||
Dialog: newDialog(renderer),
|
||||
Window: newWindow(renderer),
|
||||
Browser: NewBrowser(),
|
||||
FileSystem: newFileSystem(),
|
||||
}
|
||||
}
|
||||
39
runtime/go/runtime/window.go
Normal file
39
runtime/go/runtime/window.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package runtime
|
||||
|
||||
import "github.com/wailsapp/wails/lib/interfaces"
|
||||
|
||||
// Window exposes an interface for manipulating the window
|
||||
type Window struct {
|
||||
renderer interfaces.Renderer
|
||||
}
|
||||
|
||||
func newWindow(renderer interfaces.Renderer) *Window {
|
||||
return &Window{
|
||||
renderer: renderer,
|
||||
}
|
||||
}
|
||||
|
||||
// SetColour sets the the window colour
|
||||
func (r *Window) SetColour(colour string) error {
|
||||
return r.renderer.SetColour(colour)
|
||||
}
|
||||
|
||||
// Fullscreen makes the window fullscreen
|
||||
func (r *Window) Fullscreen() {
|
||||
r.renderer.Fullscreen()
|
||||
}
|
||||
|
||||
// UnFullscreen attempts to restore the window to the size/position before fullscreen
|
||||
func (r *Window) UnFullscreen() {
|
||||
r.renderer.UnFullscreen()
|
||||
}
|
||||
|
||||
// SetTitle sets the the window title
|
||||
func (r *Window) SetTitle(title string) {
|
||||
r.renderer.SetTitle(title)
|
||||
}
|
||||
|
||||
// Close shuts down the window and therefore the app
|
||||
func (r *Window) Close() {
|
||||
r.renderer.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user