mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 07:29:56 +08:00

* Update nsis template * Move app data into config.yml * mac support * Add FileAssociations application config option Support `ApplicationOpenedWithFile` event on Windows Add docs * Add FileAssociations application config option Support `ApplicationOpenedWithFile` event on Windows Add docs Add test project * Update example & docs. Fix show window bug. * Fix window show event bug * Update changelog
80 lines
1.5 KiB
Go
80 lines
1.5 KiB
Go
package application
|
|
|
|
var blankApplicationEventContext = &ApplicationEventContext{}
|
|
|
|
const (
|
|
openedFiles = "openedFiles"
|
|
filename = "filename"
|
|
)
|
|
|
|
type ApplicationEventContext struct {
|
|
// contains filtered or unexported fields
|
|
data map[string]any
|
|
}
|
|
|
|
func (c ApplicationEventContext) OpenedFiles() []string {
|
|
files, ok := c.data[openedFiles]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
result, ok := files.([]string)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return result
|
|
}
|
|
|
|
func (c ApplicationEventContext) setOpenedFiles(files []string) {
|
|
c.data[openedFiles] = files
|
|
}
|
|
|
|
func (c ApplicationEventContext) setIsDarkMode(mode bool) {
|
|
c.data["isDarkMode"] = mode
|
|
}
|
|
|
|
func (c ApplicationEventContext) getBool(key string) bool {
|
|
mode, ok := c.data[key]
|
|
if !ok {
|
|
return false
|
|
}
|
|
result, ok := mode.(bool)
|
|
if !ok {
|
|
return false
|
|
}
|
|
return result
|
|
}
|
|
|
|
func (c ApplicationEventContext) IsDarkMode() bool {
|
|
return c.getBool("isDarkMode")
|
|
}
|
|
|
|
func (c ApplicationEventContext) HasVisibleWindows() bool {
|
|
return c.getBool("hasVisibleWindows")
|
|
}
|
|
|
|
func (c ApplicationEventContext) setData(data map[string]any) {
|
|
c.data = data
|
|
}
|
|
|
|
func (c ApplicationEventContext) setOpenedWithFile(filepath string) {
|
|
c.data[filename] = filepath
|
|
}
|
|
|
|
func (c ApplicationEventContext) Filename() string {
|
|
filename, ok := c.data[filename]
|
|
if !ok {
|
|
return ""
|
|
}
|
|
result, ok := filename.(string)
|
|
if !ok {
|
|
return ""
|
|
}
|
|
return result
|
|
}
|
|
|
|
func newApplicationEventContext() *ApplicationEventContext {
|
|
return &ApplicationEventContext{
|
|
data: make(map[string]any),
|
|
}
|
|
}
|