forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
82 lines (64 loc) · 2.61 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package fyne
import (
"net/url"
"sync"
)
// An App is the definition of a graphical application.
// Apps can have multiple windows, it will exit when the first window to be
// shown is closed. You can also cause the app to exit by calling Quit().
// To start an application you need to call Run() somewhere in your main() function.
// Alternatively use the window.ShowAndRun() function for your main window.
type App interface {
// Create a new window for the application.
// The first window to open is considered the "master" and when closed
// the application will exit.
NewWindow(title string) Window
// Open a URL in the default browser application.
OpenURL(url *url.URL) error
// Icon returns the application icon, this is used in various ways
// depending on operating system.
// This is also the default icon for new windows.
Icon() Resource
// SetIcon sets the icon resource used for this application instance.
SetIcon(Resource)
// Run the application - this starts the event loop and waits until Quit()
// is called or the last window closes.
// This should be called near the end of a main() function as it will block.
Run()
// Calling Quit on the application will cause the application to exit
// cleanly, closing all open windows.
// This function does no thing on a mobile device as the application lifecycle is
// managed by the operating system.
Quit()
// Driver returns the driver that is rendering this application.
// Typically not needed for day to day work, mostly internal functionality.
Driver() Driver
// UniqueID returns the application unique identifier, if set.
// This must be set for use of the Preferences() functions... see NewWithId(string)
UniqueID() string
// SendNotification sends a system notification that will be displayed in the operating system's notification area.
SendNotification(*Notification)
// Settings return the globally set settings, determining theme and so on.
Settings() Settings
// Preferences returns the application preferences, used for storing configuration and state
Preferences() Preferences
// Storage returns a storage handler specific to this application.
Storage() Storage
}
var app App
var appLock sync.RWMutex
// SetCurrentApp is an internal function to set the app instance currently running.
func SetCurrentApp(current App) {
appLock.Lock()
defer appLock.Unlock()
app = current
}
// CurrentApp returns the current application, for which there is only 1 per process.
func CurrentApp() App {
appLock.RLock()
defer appLock.RUnlock()
if app == nil {
LogError("Attempt to access current Fyne app when none is started", nil)
}
return app
}