Skip to content

Commit 17eb9c0

Browse files
authored
Merge pull request #234 from kdroidFilter/feat-improved-tray-position
Refactor tray logic for improved cross-platform consistency
2 parents 65a957e + 9927170 commit 17eb9c0

51 files changed

Lines changed: 3622 additions & 895 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ bin/
4646

4747
.idea
4848
tray_position.properties
49+
50+
linuxlib/build-x86-64
51+
linuxlibdbus/build-x86-64

build.gradle.kts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import com.vanniktech.maven.publish.SonatypeHost
21
import org.jetbrains.dokka.gradle.DokkaTask
32

43
plugins {
@@ -38,11 +37,14 @@ kotlin {
3837
commonMain.dependencies {
3938
implementation(compose.runtime)
4039
implementation(compose.foundation)
40+
implementation(compose.ui)
4141
implementation(libs.jna)
4242
implementation(libs.jna.platform)
4343
implementation(libs.kotlinx.coroutines.core)
44-
implementation(libs.kmp.log)
44+
implementation(libs.kotlinx.coroutines.swing)
4545
implementation(libs.platformtools.core)
46+
implementation(libs.platformtools.darkmodedetector)
47+
4648
}
4749
}
4850

@@ -54,8 +56,20 @@ val buildWin: TaskProvider<Exec> = tasks.register<Exec>("buildNativeWin") {
5456
commandLine("cmd", "/c", "build.bat")
5557
}
5658

59+
val buildMac: TaskProvider<Exec> = tasks.register<Exec>("buildNativeMac") {
60+
onlyIf { System.getProperty("os.name").startsWith("Mac") }
61+
workingDir(rootDir.resolve("maclib"))
62+
commandLine("sh", "build.sh")
63+
}
64+
65+
val buildLinux: TaskProvider<Exec> = tasks.register<Exec>("buildNativeLinux") {
66+
// onlyIf { System.getProperty("os.name").toLowerCase().contains("linux") }
67+
// workingDir(rootDir.resolve("linuxlibdbus"))
68+
//// commandLine("./build.sh")
69+
}
70+
5771
tasks.register("buildNativeLibraries") {
58-
dependsOn(buildWin)
72+
dependsOn(buildWin, buildLinux, buildMac)
5973
}
6074

6175
mavenPublishing {
@@ -95,7 +109,7 @@ mavenPublishing {
95109
}
96110

97111
// Configure publishing to Maven Central
98-
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
112+
publishToMavenCentral()
99113

100114

101115
// Enable GPG signing for all publications

demo/build.gradle.kts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
2+
import org.gradle.api.tasks.JavaExec
23

34
plugins {
45
alias(libs.plugins.multiplatform)
@@ -18,8 +19,10 @@ kotlin {
1819
implementation(compose.desktop.currentOs)
1920
implementation(compose.components.resources)
2021
implementation(compose.material3)
21-
implementation("org.jetbrains.compose.material:material-icons-core:1.7.3")
22-
implementation(libs.kmp.log)
22+
implementation(compose.materialIconsExtended)
23+
implementation(libs.kermit)
24+
implementation(libs.platformtools.darkmodedetector)
25+
2326
}
2427
}
2528
}
@@ -41,3 +44,22 @@ compose.desktop {
4144
}
4245
}
4346
}
47+
48+
// Task to build native libraries and run the demo
49+
tasks.register("buildAndRunDemo") {
50+
// Depend on the buildNativeLibraries task from the root project
51+
dependsOn(rootProject.tasks.named("buildNativeLibraries"))
52+
53+
// This task doesn't do anything by itself, it just depends on buildNativeLibraries
54+
// and will be followed by the run task
55+
doLast {
56+
println("Native libraries built successfully. Starting demo application...")
57+
}
58+
59+
// Make sure the run task is executed after this task
60+
finalizedBy(tasks.named("run"))
61+
62+
// Description for the task
63+
description = "Builds the native libraries and then runs the demo application"
64+
group = "application"
65+
}

demo/src/jvmMain/kotlin/com/kdroid/composetray/demo/App.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.kdroid.composetray.demo
22

33
import androidx.compose.desktop.ui.tooling.preview.Preview
4+
import androidx.compose.foundation.isSystemInDarkTheme
45
import androidx.compose.foundation.layout.*
56
import androidx.compose.material3.*
67
import androidx.compose.runtime.*
78
import androidx.compose.ui.Alignment
89
import androidx.compose.ui.Modifier
910
import androidx.compose.ui.unit.dp
11+
import io.github.kdroidfilter.platformtools.darkmodedetector.isSystemInDarkMode
1012
import kotlin.system.exitProcess
1113

1214
@OptIn(ExperimentalMaterial3Api::class)
@@ -19,14 +21,17 @@ fun App(
1921
onToggleChange: (Boolean, Boolean) -> Unit
2022
) {
2123
var currentScreen by remember { mutableStateOf(Screen.Screen1) }
24+
25+
// Automatically detect system theme
26+
val isDarkTheme = isSystemInDarkMode()
2227

23-
// Material3 Theme
28+
// Material3 Theme with dark mode support
2429
MaterialTheme(
25-
colorScheme = lightColorScheme(
26-
primary = MaterialTheme.colorScheme.primary,
27-
secondary = MaterialTheme.colorScheme.secondary,
28-
tertiary = MaterialTheme.colorScheme.tertiary
29-
)
30+
colorScheme = if (isDarkTheme) {
31+
darkColorScheme()
32+
} else {
33+
lightColorScheme()
34+
}
3035
) {
3136
Scaffold(
3237
topBar = {

demo/src/jvmMain/kotlin/com/kdroid/composetray/demo/DemoAdaptivePositionWindows.kt

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,33 @@ import androidx.compose.ui.Modifier
1111
import androidx.compose.ui.graphics.Color
1212
import androidx.compose.ui.unit.dp
1313
import androidx.compose.ui.window.Window
14+
import androidx.compose.ui.window.WindowState
1415
import androidx.compose.ui.window.application
1516
import androidx.compose.ui.window.rememberWindowState
1617
import com.kdroid.composetray.tray.api.Tray
18+
import com.kdroid.composetray.utils.ComposeNativeTrayLoggingLevel
1719
import com.kdroid.composetray.utils.SingleInstanceManager
20+
import com.kdroid.composetray.utils.allowComposeNativeTrayLogging
21+
import com.kdroid.composetray.utils.composeNativeTrayloggingLevel
1822
import com.kdroid.composetray.utils.getTrayPosition
1923
import com.kdroid.composetray.utils.getTrayWindowPosition
20-
import com.kdroid.kmplog.Log
21-
import com.kdroid.kmplog.d
22-
import com.kdroid.kmplog.i
2324
import composenativetray.demo.generated.resources.Res
2425
import composenativetray.demo.generated.resources.icon
2526
import org.jetbrains.compose.resources.painterResource
2627

2728
fun main() = application {
28-
Log.setDevelopmentMode(true)
29+
allowComposeNativeTrayLogging = false
30+
composeNativeTrayloggingLevel = ComposeNativeTrayLoggingLevel.DEBUG
2931
val logTag = "NativeTray"
30-
31-
Log.d("TrayPosition", getTrayPosition().toString())
32+
33+
println("$logTag: TrayPosition: ${getTrayPosition()}")
3234

3335
var isWindowVisible by remember { mutableStateOf(true) }
3436
var textVisible by remember { mutableStateOf(false) }
35-
var alwaysShowTray by remember { mutableStateOf(false) }
37+
var alwaysShowTray by remember { mutableStateOf(true) }
3638
var hideOnClose by remember { mutableStateOf(true) }
39+
var notificationsEnabled by remember { mutableStateOf(false) }
40+
var initialChecked by remember { mutableStateOf(true) }
3741

3842
val isSingleInstance = SingleInstanceManager.isSingleInstance(onRestoreRequest = {
3943
isWindowVisible = true
@@ -62,7 +66,7 @@ fun main() = application {
6266
},
6367
primaryAction = {
6468
isWindowVisible = true
65-
Log.i(logTag, "On Primary Clicked")
69+
println("$logTag: On Primary Clicked")
6670
},
6771
primaryActionLabel = "Open the Application",
6872
tooltip = "My Application"
@@ -71,46 +75,64 @@ fun main() = application {
7175
// Tools SubMenu
7276
SubMenu(label = "Tools") {
7377
Item(label = "Calculator") {
74-
Log.i(logTag, "Calculator launched")
78+
println("$logTag: Calculator launched")
7579
}
7680
Item(label = "Notepad") {
77-
Log.i(logTag, "Notepad opened")
81+
println("$logTag: Notepad opened")
7882
}
7983
}
8084

8185
Divider()
8286

8387
// Checkable Items
84-
CheckableItem(label = "Enable notifications") { isChecked ->
85-
Log.i(logTag, "Notifications ${if (isChecked) "enabled" else "disabled"}")
86-
}
87-
CheckableItem(label = "Initial Checked", checked = true) { isChecked ->
88-
Log.i(logTag, "Initial Checked ${if (isChecked) "enabled" else "disabled"}")
89-
}
88+
CheckableItem(
89+
label = "Enable notifications",
90+
checked = notificationsEnabled,
91+
onCheckedChange = { isChecked ->
92+
notificationsEnabled = isChecked
93+
println("$logTag: Notifications ${if (isChecked) "enabled" else "disabled"}")
94+
}
95+
)
96+
CheckableItem(
97+
label = "Initial Checked",
98+
checked = initialChecked,
99+
onCheckedChange = { isChecked ->
100+
initialChecked = isChecked
101+
println("$logTag: Initial Checked ${if (isChecked) "enabled" else "disabled"}")
102+
}
103+
)
90104

91105
Divider()
92106

93107
Item(label = "About") {
94-
Log.i(logTag, "Application v1.0 - Developed by Elyahou")
108+
println("$logTag: Application v1.0 - Developed by Elyahou")
95109
}
96110

97111
Divider()
98112

99-
CheckableItem(label = "Always show tray", checked = alwaysShowTray) { isChecked ->
100-
alwaysShowTray = isChecked
101-
Log.i(logTag, "Always show tray ${if (isChecked) "enabled" else "disabled"}")
102-
}
103-
104-
CheckableItem(label = "Hide on close", checked = hideOnClose) { isChecked ->
105-
hideOnClose = isChecked
106-
Log.i(logTag, "Hide on close ${if (isChecked) "enabled" else "disabled"}")
107-
}
113+
CheckableItem(
114+
label = "Always show tray",
115+
checked = alwaysShowTray,
116+
onCheckedChange = { isChecked ->
117+
alwaysShowTray = isChecked
118+
println("$logTag: Always show tray ${if (isChecked) "enabled" else "disabled"}")
119+
}
120+
)
121+
122+
CheckableItem(
123+
label = "Hide on close",
124+
checked = hideOnClose,
125+
onCheckedChange = { isChecked ->
126+
hideOnClose = isChecked
127+
println("$logTag: Hide on close ${if (isChecked) "enabled" else "disabled"}")
128+
}
129+
)
108130

109131
Divider()
110132

111133

112134
Item(label = "Exit", isEnabled = true) {
113-
Log.i(logTag, "Exiting the application")
135+
println("$logTag: Exiting the application")
114136
dispose()
115137
exitApplication()
116138
}
@@ -120,7 +142,7 @@ fun main() = application {
120142
}
121143

122144

123-
val windowWidth = 800
145+
val windowWidth = 300
124146
val windowHeight = 600
125147
val windowPosition = getTrayWindowPosition(windowWidth, windowHeight)
126148

@@ -132,7 +154,7 @@ fun main() = application {
132154
exitApplication()
133155
}
134156
},
135-
state = rememberWindowState(
157+
state = WindowState(
136158
width = windowWidth.dp,
137159
height = windowHeight.dp,
138160
position = windowPosition
@@ -146,4 +168,4 @@ fun main() = application {
146168
hideOnClose = hideOnCloseState
147169
}
148170
}
149-
}
171+
}

0 commit comments

Comments
 (0)