mirror of
https://github.com/amir1376/ab-download-manager.git
synced 2025-02-20 11:43:24 +08:00
Exception will not throw if System tray is not supported by the OS
This commit is contained in:
parent
0dfbdbc576
commit
41a300051e
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Exception will not throw if System Tray is not supported by the OS
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|
||||||
## 1.0.5
|
## 1.0.5
|
||||||
|
@ -31,16 +31,7 @@ fun AwtTray(
|
|||||||
val density by rememberUpdatedState(GlobalDensity)
|
val density by rememberUpdatedState(GlobalDensity)
|
||||||
if (!isTraySupported) {
|
if (!isTraySupported) {
|
||||||
DisposableEffect(Unit) {
|
DisposableEffect(Unit) {
|
||||||
// We should notify developer, but shouldn't throw an exception.
|
System.err.println("System tray is not supported")
|
||||||
// If we would throw an exception, some application wouldn't work on some platforms at
|
|
||||||
// all, if developer doesn't check that application crashes.
|
|
||||||
//
|
|
||||||
// We can do this because we don't return anything in Tray function, and following
|
|
||||||
// code doesn't depend on something that is created/calculated in this function.
|
|
||||||
System.err.println(
|
|
||||||
"Tray is not supported on the current platform. " +
|
|
||||||
"Use the global property `isTraySupported` to check."
|
|
||||||
)
|
|
||||||
onDispose {}
|
onDispose {}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -58,11 +49,11 @@ fun AwtTray(
|
|||||||
icon.toAwtImage(GlobalDensity, GlobalLayoutDirection, trayIconSize)
|
icon.toAwtImage(GlobalDensity, GlobalLayoutDirection, trayIconSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
val tray = remember {
|
val trayIcon = remember {
|
||||||
TrayIcon(awtIcon)
|
TrayIcon(awtIcon)
|
||||||
}
|
}
|
||||||
DisposableEffect(tray) {
|
DisposableEffect(trayIcon) {
|
||||||
with(tray) {
|
with(trayIcon) {
|
||||||
val doubleClickListener = object : MouseListener {
|
val doubleClickListener = object : MouseListener {
|
||||||
override fun mouseClicked(p0: MouseEvent?) {
|
override fun mouseClicked(p0: MouseEvent?) {
|
||||||
when (p0?.button) {
|
when (p0?.button) {
|
||||||
@ -95,21 +86,32 @@ fun AwtTray(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SideEffect {
|
SideEffect {
|
||||||
if (tray.image != awtIcon) tray.image = awtIcon
|
if (trayIcon.image != awtIcon) trayIcon.image = awtIcon
|
||||||
if (tray.toolTip != tooltip) tray.toolTip = tooltip
|
if (trayIcon.toolTip != tooltip) trayIcon.toolTip = tooltip
|
||||||
}
|
}
|
||||||
|
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
DisposableEffect(Unit) {
|
DisposableEffect(Unit) {
|
||||||
SystemTray.getSystemTray().add(tray)
|
val systemTray = kotlin.runCatching {
|
||||||
|
// some linux users reporting that system tray will not support by distro and throws exception after entering to lock screen
|
||||||
|
// I have to investigate why!
|
||||||
|
SystemTray.getSystemTray()
|
||||||
|
}.getOrNull()
|
||||||
|
|
||||||
|
if (systemTray!=null){
|
||||||
|
systemTray.add(trayIcon)
|
||||||
state.notificationFlow
|
state.notificationFlow
|
||||||
.onEach(tray::displayMessage)
|
.onEach(trayIcon::displayMessage)
|
||||||
.launchIn(coroutineScope)
|
.launchIn(coroutineScope)
|
||||||
|
}
|
||||||
|
|
||||||
onDispose {
|
onDispose {
|
||||||
SystemTray.getSystemTray().remove(tray)
|
// don't get hard!
|
||||||
|
// linux have some strange behaviors in system tray I have to improve this
|
||||||
|
runCatching {
|
||||||
|
systemTray?.remove(trayIcon)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user