Skip to content

Commit

Permalink
feat(Library): add app lifecycle hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Dec 22, 2024
1 parent 23511bd commit c61d51c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
39 changes: 39 additions & 0 deletions core/systems/launcher/app_lifecycle_hook.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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.

## 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


## 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
8 changes: 8 additions & 0 deletions core/systems/library/library.gd
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,13 @@ func has_update(item: LibraryLaunchItem) -> bool:
return false


## This method should be overridden if the library requires executing callbacks
## at certain points in an app's lifecycle, such as when an app is starting or
## stopping.
func get_app_lifecycle_hooks() -> Array[AppLifecycleHook]:
var hooks: Array[AppLifecycleHook]
return hooks


func _exit_tree() -> void:
LibraryManager.unregister_library(self)

0 comments on commit c61d51c

Please sign in to comment.