diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-09 08:38:33 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-09 08:38:33 +0300 |
| commit | 7c08fe44282c076e2470fe19a1eacff209cfa4f2 (patch) | |
| tree | 65410fe3a626740a33861d93995335bb735fdece /main.go | |
| parent | a4d5a70aa998b315e69d7a945a57ade083505011 (diff) | |
Fix shared text cache cleanup
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 72 |
1 files changed, 56 insertions, 16 deletions
@@ -52,6 +52,44 @@ func prepareSharedTextLoad(text string, autoLog bool) (sharedTextLoadMode, strin return sharedTextLoadPrefill, text, true } +func clearSharedTextCache() { + if path := sharedTextCachePath(); path != "" { + _ = os.Remove(path) + } +} + +func handleSharedTextLoad( + text string, + autoLog bool, + dir string, + prefill func(string), + focus func(), + resetInput func(), + clearCache func(), + logFn func(string, string) error, + showInfo func(string, string), + showError func(error), +) { + mode, sharedText, ok := prepareSharedTextLoad(text, autoLog) + if !ok { + clearCache() + return + } + if mode == sharedTextLoadAutoLog { + if err := logFn(dir, sharedText); err != nil { + showError(err) + return + } + showInfo("Logged", "Shared text has been logged.") + resetInput() + clearCache() + return + } + prefill(sharedText) + focus() + clearCache() +} + // newInputWidget creates the multi-line text entry with platform-appropriate // wrapping and row count settings. func newInputWidget() *widget.Entry { @@ -152,27 +190,29 @@ func createMainWindow(a fyne.App) fyne.Window { } return } - mode, sharedText, ok := prepareSharedTextLoad(txt, a.Preferences().BoolWithFallback("AutoLogSharedText", false)) - if !ok { - return - } loadingSharedText = true defer func() { loadingSharedText = false }() - if mode == sharedTextLoadAutoLog { - dir := a.Preferences().StringWithFallback("Directory", defaultDirectory) - if err := logEntry(dir, sharedText); err != nil { + handleSharedTextLoad( + txt, + a.Preferences().BoolWithFallback("AutoLogSharedText", false), + a.Preferences().StringWithFallback("Directory", defaultDirectory), + input.SetText, + func() { + window.Canvas().Focus(input) + }, + resetInput, + clearSharedTextCache, + logEntry, + func(title, message string) { + dialog.ShowInformation(title, message, window) + }, + func(err error) { dialog.ShowError(err, window) - return - } - dialog.ShowInformation("Logged", "Shared text has been logged.", window) - resetInput() - return - } - input.SetText(sharedText) - charCount.SetText(fmt.Sprintf("%d chars", len(sharedText))) - window.Canvas().Focus(input) + }, + ) + charCount.SetText(fmt.Sprintf("%d chars", len(input.Text))) } if fyne.CurrentDevice().IsMobile() { |
