mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Ensure icon cache is cleared at exit
This commit is contained in:
@@ -237,7 +237,9 @@ func (p *parsed_data) load_image_data() (err error) {
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
_, imgfmt, err := image.DecodeConfig(f)
|
_, imgfmt, err := image.DecodeConfig(f)
|
||||||
f.Seek(0, io.SeekStart)
|
if _, err = f.Seek(0, io.SeekStart); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err == nil && imgfmt != "" && strings.Contains("jpeg jpg gif png", strings.ToLower(imgfmt)) {
|
if err == nil && imgfmt != "" && strings.Contains("jpeg jpg gif png", strings.ToLower(imgfmt)) {
|
||||||
p.image_data, err = io.ReadAll(f)
|
p.image_data, err = io.ReadAll(f)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -671,7 +671,8 @@ class NotificationManager:
|
|||||||
channel: Channel = Channel(),
|
channel: Channel = Channel(),
|
||||||
log: Log = Log(),
|
log: Log = Log(),
|
||||||
debug: bool = False,
|
debug: bool = False,
|
||||||
base_cache_dir: str = ''
|
base_cache_dir: str = '',
|
||||||
|
cleanup_at_exit: bool = True,
|
||||||
):
|
):
|
||||||
global debug_desktop_integration
|
global debug_desktop_integration
|
||||||
debug_desktop_integration = debug
|
debug_desktop_integration = debug
|
||||||
@@ -693,6 +694,9 @@ class NotificationManager:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log(f'Failed to load {script_path} with error: {e}')
|
self.log(f'Failed to load {script_path} with error: {e}')
|
||||||
self.reset()
|
self.reset()
|
||||||
|
if cleanup_at_exit:
|
||||||
|
import atexit
|
||||||
|
atexit.register(self.cleanup)
|
||||||
|
|
||||||
def reset(self) -> None:
|
def reset(self) -> None:
|
||||||
self.icon_data_cache.clear()
|
self.icon_data_cache.clear()
|
||||||
@@ -892,3 +896,6 @@ class NotificationManager:
|
|||||||
parts = raw.split(';', 1)
|
parts = raw.split(';', 1)
|
||||||
n.title, n.body = parts[0], (parts[1] if len(parts) > 1 else '')
|
n.title, n.body = parts[0], (parts[1] if len(parts) > 1 else '')
|
||||||
self.notify_with_command(n, channel_id)
|
self.notify_with_command(n, channel_id)
|
||||||
|
|
||||||
|
def cleanup(self) -> None:
|
||||||
|
del self.icon_data_cache
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class NotificationManager(NotificationManager):
|
|||||||
def do_test(self: 'TestNotifications', tdir: str) -> None:
|
def do_test(self: 'TestNotifications', tdir: str) -> None:
|
||||||
di = DesktopIntegration(None)
|
di = DesktopIntegration(None)
|
||||||
ch = Channel()
|
ch = Channel()
|
||||||
nm = NotificationManager(di, ch, lambda *a, **kw: None, base_cache_dir=tdir)
|
nm = NotificationManager(di, ch, lambda *a, **kw: None, base_cache_dir=tdir, cleanup_at_exit=False)
|
||||||
di.notification_manager = nm
|
di.notification_manager = nm
|
||||||
|
|
||||||
def reset():
|
def reset():
|
||||||
|
|||||||
Reference in New Issue
Block a user