-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from opatry/tasks-app-desktop
Add :tasks-app-desktop module
- Loading branch information
Showing
6 changed files
with
239 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) 2024 Olivier Patry | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software | ||
* is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | ||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat | ||
|
||
plugins { | ||
alias(libs.plugins.jetbrains.kotlin.jvm) | ||
alias(libs.plugins.jetbrains.kotlin.compose.compiler) | ||
alias(libs.plugins.jetbrains.compose) | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(17) | ||
|
||
dependencies { | ||
implementation(libs.kotlinx.coroutines.swing) { | ||
because("requires Dispatchers.Main & co at runtime for Jvm") | ||
// java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core' | ||
// see also https://github.com/JetBrains/compose-jb/releases/tag/v1.1.1 | ||
} | ||
|
||
implementation(libs.kotlinx.datetime) | ||
|
||
implementation(project.dependencies.platform(libs.koin.bom)) | ||
implementation(libs.koin.core) | ||
implementation(libs.koin.compose) | ||
implementation(libs.koin.compose.viewmodel) | ||
|
||
implementation(compose.material3) | ||
implementation(compose.desktop.currentOs) | ||
|
||
implementation(project(":google:oauth")) | ||
implementation(project(":google:tasks")) | ||
implementation(project(":tasks-app-shared")) | ||
} | ||
} | ||
|
||
compose.desktop { | ||
application { | ||
mainClass = "MainAppKt" | ||
|
||
nativeDistributions { | ||
packageVersion = "1.0.0" | ||
packageName = "Tasks app" | ||
version = "1.0.0" | ||
targetFormats( | ||
TargetFormat.Dmg, | ||
) | ||
|
||
modules( | ||
// for org.apache.logging.log4j.core.LoggerContext | ||
"java.management", | ||
// for DriverManager (required by SQLite JDBC driver) | ||
"java.sql", | ||
) | ||
|
||
macOS { | ||
bundleID = "net.opatry.tasks.app" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* Copyright (c) 2024 Olivier Patry | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software | ||
* is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | ||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.DpSize | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.window.Window | ||
import androidx.compose.ui.window.WindowPlacement | ||
import androidx.compose.ui.window.WindowPosition | ||
import androidx.compose.ui.window.WindowState | ||
import androidx.compose.ui.window.application | ||
import androidx.compose.ui.window.rememberWindowState | ||
import net.opatry.tasks.app.di.authModule | ||
import net.opatry.tasks.app.di.dataModule | ||
import net.opatry.tasks.app.di.networkModule | ||
import net.opatry.tasks.app.di.platformModule | ||
import net.opatry.tasks.app.di.tasksAppModule | ||
import net.opatry.tasks.app.ui.TaskListsViewModel | ||
import net.opatry.tasks.app.ui.TasksApp | ||
import net.opatry.tasks.app.ui.UserState | ||
import net.opatry.tasks.app.ui.UserViewModel | ||
import net.opatry.tasks.app.ui.screen.AuthorizationScreen | ||
import net.opatry.tasks.app.ui.theme.TasksAppTheme | ||
import org.koin.compose.KoinApplication | ||
import org.koin.compose.viewmodel.koinViewModel | ||
import java.awt.Dimension | ||
import java.awt.Toolkit | ||
import javax.swing.UIManager | ||
|
||
private const val GCP_CLIENT_ID = "191682949161-esokhlfh7uugqptqnu3su9vgqmvltv95.apps.googleusercontent.com" | ||
|
||
fun main() { | ||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) | ||
|
||
application { | ||
val screenSize by remember { | ||
mutableStateOf(Toolkit.getDefaultToolkit().screenSize) | ||
} | ||
|
||
val defaultSize = DpSize(1024.dp, 800.dp) | ||
val minSize = Dimension(600, 400) | ||
|
||
var windowState = rememberWindowState( | ||
position = WindowPosition(Alignment.Center), width = defaultSize.width, height = defaultSize.height | ||
) | ||
|
||
Window( | ||
onCloseRequest = ::exitApplication, | ||
state = windowState, | ||
title = "Tasks App", | ||
) { | ||
if (window.minimumSize != minSize) window.minimumSize = minSize | ||
|
||
if (windowState.placement == WindowPlacement.Floating) { | ||
val insets = window.insets | ||
val maxWidth = screenSize.width - insets.left - insets.right | ||
val finalWidth = if (window.size.width > maxWidth) maxWidth else window.size.width | ||
val maxHeight = screenSize.height - insets.bottom - insets.top | ||
val finalHeight = if (window.size.height > maxHeight) maxHeight else window.size.height | ||
|
||
if (finalWidth != window.size.width || finalHeight != window.size.height) { | ||
windowState = WindowState( | ||
placement = windowState.placement, | ||
position = windowState.position, | ||
isMinimized = windowState.isMinimized, | ||
width = finalWidth.dp, | ||
height = finalHeight.dp | ||
) | ||
} | ||
} | ||
|
||
KoinApplication(application = { | ||
modules( | ||
platformModule(), | ||
dataModule, | ||
authModule(GCP_CLIENT_ID), | ||
networkModule, | ||
tasksAppModule, | ||
) | ||
}) { | ||
val userViewModel = koinViewModel<UserViewModel>() | ||
val userState by userViewModel.state.collectAsState(null) | ||
|
||
if (userState == null) { | ||
LaunchedEffect(userState) { | ||
userViewModel.refreshUserState() | ||
} | ||
} | ||
|
||
TasksAppTheme { | ||
Surface { | ||
when (userState) { | ||
null -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { | ||
CircularProgressIndicator(Modifier.size(24.dp), strokeWidth = 1.dp) | ||
} | ||
|
||
is UserState.Unsigned, | ||
is UserState.SignedIn -> { | ||
val tasksViewModel = koinViewModel<TaskListsViewModel>() | ||
TasksApp(userViewModel, tasksViewModel) | ||
} | ||
|
||
is UserState.Newcomer -> AuthorizationScreen( | ||
onSkip = userViewModel::skipSignIn, | ||
onSuccess = userViewModel::signIn, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |