commit 18fa4f139784a422f19ac60a2360fed9d6307b97
parent 22ffab1ebd1a9aac944f1e5fe844d41113aa2217
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Wed, 18 Dec 2024 13:06:42 +0800
noti: migrate types to separate file
This lets the types be available on all platforms.
Diffstat:
| M | noti.go | | | 71 | ----------------------------------------------------------------------- |
| A | types.go | | | 72 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 72 insertions(+), 71 deletions(-)
diff --git a/noti.go b/noti.go
@@ -66,77 +66,6 @@ func Cancel() {
C.noti_cancel()
}
-type (
- CategoryID = string
- ActionID = string
- UserText = string
- UserData = map[string]string
-)
-
-// CallbackArgs contains the data from a user interaction of a notification.
-type CallbackArgs struct {
- Category CategoryID
- Action ActionID
- UserData UserData // data attached to the notification by the application
- UserText string // text input by the user (applies to text actions)
- Err error // any error that occured processing the user data
-}
-
-// CallbackFunc signature. Switch on the action to know how to interpret the dynamic data.
-type CallbackFunc func(CallbackArgs)
-
-// Category defines a set of actions that a notification can reference by ID to
-// have them be applied.
-type Category struct {
- ID CategoryID
- Summary string // summarise the category
- Preview string // hidden preview body placeholder
- Actions []Action
- TextInputActions []TextInputAction
-}
-
-// Notification describes
-type Notification struct {
- Title string
- Subtitle string
- Body string
-
- // UserData is app supplied data that is passed back upon user interaction.
- UserData UserData
-
- // Attachments is a list of image names.
- // If the image name is an absolute path it will be followed literally.
- // If the image name is just a base name, the bundle will be searched for it.
- // The named image must exist on disk, must be PNG, JPEG or GIF and must be
- // less than 10MB.
- Attachments []string
-
- // Category to apply. If supplied the actions attached on this notification will be
- // ignored and the pre-existing category used.
- Category CategoryID
-
- // Actions, if supplied here, will provoke an ad-hoc Category to be created to
- // contain them on the native side. This is for convenience.
- Actions []Action // button action
- TextInputActions []TextInputAction // text input action
-}
-
-// Action is a button action.
-type Action struct {
- ID ActionID // globally unique, used in callback
- Title string
- Icon string // name of asset within bundle to use as icon; TODO: could support system defined icons as well
-}
-
-// TextInputAction allows for text input from user.
-type TextInputAction struct {
- ID ActionID // globally unique, used in callback
- Title string
- Icon string // name of asset within bundle to use as icon; TODO: could support system defined icons as well
- ButtonTitle string
- Placeholder string
-}
-
/*
To keep things simple (dealing with nested objects), we tie the C memory
to the lifetime of the various Go objects by doing the frees in a runtime
diff --git a/types.go b/types.go
@@ -0,0 +1,72 @@
+package notify
+
+type (
+ CategoryID = string
+ ActionID = string
+ UserText = string
+ UserData = map[string]string
+)
+
+// CallbackArgs contains the data from a user interaction of a notification.
+type CallbackArgs struct {
+ Category CategoryID
+ Action ActionID
+ UserData UserData // data attached to the notification by the application
+ UserText string // text input by the user (applies to text actions)
+ Err error // any error that occured processing the user data
+}
+
+// CallbackFunc signature. Switch on the action to know how to interpret the dynamic data.
+type CallbackFunc func(CallbackArgs)
+
+// Category defines a set of actions that a notification can reference by ID to
+// have them be applied.
+type Category struct {
+ ID CategoryID
+ Summary string // summarise the category
+ Preview string // hidden preview body placeholder
+ Actions []Action
+ TextInputActions []TextInputAction
+}
+
+// Notification describes
+type Notification struct {
+ Title string
+ Subtitle string
+ Body string
+
+ // UserData is app supplied data that is passed back upon user interaction.
+ UserData UserData
+
+ // Attachments is a list of image names.
+ // If the image name is an absolute path it will be followed literally.
+ // If the image name is just a base name, the bundle will be searched for it.
+ // The named image must exist on disk, must be PNG, JPEG or GIF and must be
+ // less than 10MB.
+ Attachments []string
+
+ // Category to apply. If supplied the actions attached on this notification will be
+ // ignored and the pre-existing category used.
+ Category CategoryID
+
+ // Actions, if supplied here, will provoke an ad-hoc Category to be created to
+ // contain them on the native side. This is for convenience.
+ Actions []Action // button action
+ TextInputActions []TextInputAction // text input action
+}
+
+// Action is a button action.
+type Action struct {
+ ID ActionID // globally unique, used in callback
+ Title string
+ Icon string // name of asset within bundle to use as icon; TODO: could support system defined icons as well
+}
+
+// TextInputAction allows for text input from user.
+type TextInputAction struct {
+ ID ActionID // globally unique, used in callback
+ Title string
+ Icon string // name of asset within bundle to use as icon; TODO: could support system defined icons as well
+ ButtonTitle string
+ Placeholder string
+}