-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathapp_lifecycle_hook.gd
More file actions
65 lines (50 loc) · 1.69 KB
/
app_lifecycle_hook.gd
File metadata and controls
65 lines (50 loc) · 1.69 KB
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
extends RefCounted
class_name AppLifecycleHook
## Base class for executing callbacks at certain points of an app's lifecycle.
##
## This class provides an interface for executing arbitrary callbacks at certain
## points of an application's lifecycle. This can allow [Library] implementations
## the ability to execute actions when apps are about to start, have started,
## or have exited.
## Emit this signal if you want to indicate progression of the hook.
signal progressed(percent: float)
## Emit this signal whenever you want custom text to be displayed
signal notified(text: String)
## The type of hook determines where in the application's lifecycle this hook
## should be executed.
enum TYPE {
## Executes right before an app is launched
PRE_LAUNCH,
## Executes right after an app is launched
LAUNCH,
## Executed after app exit
EXIT,
}
var _hook_type: TYPE
func _init(hook_type: TYPE) -> void:
_hook_type = hook_type
## Name of the lifecycle hook
func get_name() -> String:
return ""
## Executes whenever an app from this library reaches the stage in its lifecycle
## designated by the hook type. E.g. a `PRE_LAUNCH` hook will have this method
## called whenever an app is about to launch.
func execute(item: LibraryLaunchItem) -> void:
pass
## Returns the hook type, which designates where in the application's lifecycle
## the hook should be executed.
func get_type() -> TYPE:
return _hook_type
func _to_string() -> String:
var kind: String
match self.get_type():
TYPE.PRE_LAUNCH:
kind = "PreLaunch"
TYPE.LAUNCH:
kind = "Launch"
TYPE.EXIT:
kind = "Exit"
var name := self.get_name()
if name.is_empty():
name = "Anonymous"
return "<AppLifecycleHook.{0}-{1}>".format([kind, name])