summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-13 10:54:41 +0300
committerPaul Buetow <paul@buetow.org>2025-09-13 10:54:41 +0300
commitb93fcd57868a53ad0f98ed450bd4c964f370442b (patch)
tree6d2c398496dae417a98e2705dd13f8c7e8bef3f8 /main.go
parent4f4d430db11f4d7be9cb7c6562d611f088cc01cc (diff)
Android share integration: add overlay manifest and ShareActivity, move Java to android/src/main/java for fyne-cross merge; read shared text from UserCacheDir; load on startup and foreground. Update README for Mage usage.
Diffstat (limited to 'main.go')
-rw-r--r--main.go55
1 files changed, 37 insertions, 18 deletions
diff --git a/main.go b/main.go
index 863a40d..0a32930 100644
--- a/main.go
+++ b/main.go
@@ -58,20 +58,20 @@ func createMainWindow(a fyne.App) fyne.Window {
input.Wrapping = fyne.TextWrapWord
}
input.SetPlaceHolder(placeholderText)
- // Optimization 2: Reduce visible rows on mobile to limit rendering area
- if fyne.CurrentDevice().IsMobile() {
- input.SetMinRowsVisible(10)
- } else {
- input.SetMinRowsVisible(30)
- }
+ // Optimization 2: Reduce visible rows on mobile to limit rendering area
+ if fyne.CurrentDevice().IsMobile() {
+ input.SetMinRowsVisible(10)
+ } else {
+ input.SetMinRowsVisible(30)
+ }
// Optimization 3: Add text length indicator
charCount := widget.NewLabel("0 chars")
- // Optimization 4: Throttle text changes with validation
- input.OnChanged = func(text string) {
- // Update character count
- charCount.SetText(fmt.Sprintf("%d chars", len(text)))
+ // Optimization 4: Throttle text changes with validation
+ input.OnChanged = func(text string) {
+ // Update character count
+ charCount.SetText(fmt.Sprintf("%d chars", len(text)))
// Warn if text is getting too long
if len(text) > maxTextLength {
@@ -96,12 +96,20 @@ func createMainWindow(a fyne.App) fyne.Window {
charCount.SetText("0 chars")
})
- // Optimization 5: Add clear button for quick text clearing
- clearButton := widget.NewButton("Clear", func() {
- input.SetText("")
- charCount.SetText("0 chars")
- window.Canvas().Focus(input)
- })
+ // Optimization 5: Add clear button for quick text clearing
+ clearButton := widget.NewButton("Clear", func() {
+ input.SetText("")
+ charCount.SetText("0 chars")
+ window.Canvas().Focus(input)
+ })
+
+ // If running on Android and shared text file exists, load it into the input
+ if fyne.CurrentDevice().IsMobile() {
+ if txt, err := readSharedFromCache(); err == nil && txt != "" {
+ input.SetText(txt)
+ charCount.SetText(fmt.Sprintf("%d chars", len(txt)))
+ }
+ }
window.SetContent(container.NewVBox(
input,
@@ -114,8 +122,19 @@ func createMainWindow(a fyne.App) fyne.Window {
charCount, // Show character count
),
))
- window.Resize(windowSize)
- window.Canvas().Focus(input)
+ window.Resize(windowSize)
+ window.Canvas().Focus(input)
+
+ // On Android, also check for new shared text whenever app returns to foreground.
+ if lc := a.Lifecycle(); lc != nil {
+ lc.SetOnEnteredForeground(func() {
+ if txt, err := readSharedFromCache(); err == nil && txt != "" {
+ input.SetText(txt)
+ charCount.SetText(fmt.Sprintf("%d chars", len(txt)))
+ window.Canvas().Focus(input)
+ }
+ })
+ }
return window
}