Skip to content

Commit

Permalink
Merge pull request #22 from kaleidot725/v1.7.0
Browse files Browse the repository at this point in the history
Release v1.7.0
  • Loading branch information
kaleidot725 authored Jul 16, 2022
2 parents fc2a4ee + 5a8a6d3 commit 63f55ec
Show file tree
Hide file tree
Showing 63 changed files with 682 additions and 661 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

group = "me.kaleidot725"
version = "1.6.0"
version = "1.7.0"

plugins {
kotlin("jvm") version "1.6.10"
kotlin("plugin.serialization") version "1.6.10"

id("org.jetbrains.compose") version "1.0.1"
id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
id("org.jlleitschuh.gradle.ktlint") version "10.3.0"
}

repositories {
google()
mavenCentral()
maven("https://jitpack.io")
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
mavenCentral()
google()
}

dependencies {
Expand Down
Binary file added icon.afdesign
Binary file not shown.
Binary file modified icon.icns
Binary file not shown.
Binary file modified icon.ico
Binary file not shown.
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 36 additions & 16 deletions src/main/kotlin/ScrcpyHub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import model.di.appModule
import org.koin.core.context.GlobalContext
import org.koin.core.context.GlobalContext.getOrNull
import org.koin.core.context.GlobalContext.startKoin
import resource.Images
import resource.Strings
import view.AppWindow
import view.MainContent
import viewmodel.MainContentViewModel
import view.MainContentStateHolder
import view.MainWindow
import view.resource.Images
import view.resource.Strings

fun main() = application {
if (getOrNull() == null) {
Expand All @@ -27,24 +27,44 @@ fun main() = application {

val trayState = rememberTrayState()
val windowState = rememberWindowState(width = 350.dp, height = 550.dp)
val viewModel by remember { mutableStateOf(GlobalContext.get().get<MainContentViewModel>()) }
val stateHolder by remember { mutableStateOf(GlobalContext.get().get<MainContentStateHolder>()) }
var isOpen by remember { mutableStateOf(true) }
var alwaysOnTop by remember { mutableStateOf(false) }

Tray(state = trayState, icon = painterResource(Images.TRAY), menu = {
Item(Strings.TRAY_TOGGLE_SCRCPY_HUB, onClick = { isOpen = !isOpen })
Tray(
state = trayState, icon = painterResource(Images.TRAY),
menu = {
CheckboxItem(
text = Strings.TRAY_SHOW_SCRCPY_HUB,
checked = isOpen,
onCheckedChange = { isOpen = it }
)

Item(Strings.TRAY_VERSION, enabled = false, onClick = {})
CheckboxItem(
text = Strings.TRAY_ENABLE_ALWAYS_TOP,
checked = alwaysOnTop,
onCheckedChange = { alwaysOnTop = it }
)

Separator()
Separator()

Item(Strings.QUIT, onClick = {
exitApplication()
})
})
Item(
Strings.QUIT,
onClick = { exitApplication() }
)
}
)

if (isOpen) {
AppWindow(onCloseRequest = { isOpen = false }, state = windowState) {
MainContent(windowScope = this, mainContentViewModel = viewModel)
}
MainWindow(
onCloseRequest = { isOpen = false },
state = windowState,
alwaysOnTop = alwaysOnTop
) {
MainContent(
windowScope = this,
mainStateHolder = stateHolder
)
}
}
}
2 changes: 0 additions & 2 deletions src/main/kotlin/model/command/AdbCommand.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package model.command

import model.command.creator.AdbCommandCreator

class AdbCommand(private val factory: AdbCommandCreator) {
fun isInstalled(): Boolean {
return try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package model.command.creator
package model.command

import java.io.File

Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/model/command/KillCommand.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package model.command

import model.command.creator.KillCommandCreator

class KillCommand(private val factory: KillCommandCreator) {
fun run(pid: Long): Process {
val command = factory.create(pid)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package model.command.creator
package model.command

interface KillCommandCreator {
fun create(pid: Long): List<String>
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/model/command/ScrcpyCommand.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package model.command

import model.command.creator.ScrcpyCommandCreator
import model.entity.Device
import java.io.File

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package model.command.creator
package model.command

import model.entity.Device
import java.io.File
Expand Down
35 changes: 21 additions & 14 deletions src/main/kotlin/model/di/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package model.di

import kotlinx.coroutines.runBlocking
import model.command.KillCommand
import model.command.KillCommandCreatorForLinux
import model.command.KillCommandCreatorForMacOS
import model.command.KillCommandCreatorForWindows
import model.command.ScrcpyCommand
import model.command.creator.KillCommandCreatorForLinux
import model.command.creator.KillCommandCreatorForMacOS
import model.command.creator.KillCommandCreatorForWindows
import model.command.creator.ScrcpyCommandCreator
import model.command.ScrcpyCommandCreator
import model.entity.Device
import model.os.OSContext
import model.os.OSContextForLinux
import model.os.OSContextForMac
import model.os.OSContextForWindows
import model.os.OSType
import model.os.factory.OSContextFactory
import model.os.getOSType
import model.repository.DeviceRepository
import model.repository.MessageRepository
import model.repository.ProcessRepository
Expand All @@ -31,18 +34,22 @@ import model.usecase.StopScrcpyUseCase
import model.usecase.UpdateDeviceSetting
import model.usecase.UpdateSettingUseCase
import org.koin.dsl.module
import viewmodel.DevicePageViewModel
import viewmodel.DevicesPageViewModel
import viewmodel.MainContentViewModel
import viewmodel.SettingPageViewModel
import view.MainContentStateHolder
import view.pages.DevicesPageStateHolder
import view.pages.device.DevicePageStateHolder
import view.pages.setting.SettingPageStateHolder

val appModule = module {
single {
MessageRepository()
}

factory {
OSContextFactory.create()
when (getOSType()) {
OSType.MAC_OS -> OSContextForMac()
OSType.LINUX -> OSContextForLinux()
OSType.WINDOWS -> OSContextForWindows()
}
}

factory {
Expand Down Expand Up @@ -133,18 +140,18 @@ val appModule = module {
}

factory {
DevicesPageViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get())
DevicesPageStateHolder(get(), get(), get(), get(), get(), get(), get(), get(), get())
}

factory { (context: Device.Context) ->
DevicePageViewModel(context, get())
DevicePageStateHolder(context, get())
}

factory {
MainContentViewModel(get(), get(), get(), get())
MainContentStateHolder(get(), get(), get(), get())
}

factory {
SettingPageViewModel(get(), get())
SettingPageStateHolder(get(), get())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class AppSetting(
data class Setting(
@SerialName("adbLocation")
val adbLocation: String = "",
@SerialName("theme")
Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/model/os/OSContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,23 @@ interface OSContext {
val settingPath: String
val desktopPath: String
}

class OSContextForMac : OSContext {
override val type: OSType = OSType.MAC_OS
override val settingPath: String =
System.getProperty("user.home") + "/Library/Application Support/ScrcpyHub/"
override val desktopPath: String =
System.getProperty("user.home") + "/Desktop/"
}

class OSContextForLinux : OSContext {
override val type: OSType = OSType.LINUX
override val settingPath: String = System.getProperty("user.home") + "/ScrcpyHub/"
override val desktopPath: String = System.getProperty("user.home") + "/Desktop/"
}

class OSContextForWindows : OSContext {
override val type: OSType = OSType.WINDOWS
override val settingPath: String = "./"
override val desktopPath: String = System.getProperty("user.home") + "/Desktop/"
}
8 changes: 8 additions & 0 deletions src/main/kotlin/model/os/OSType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ enum class OSType {
LINUX,
WINDOWS,
}

fun getOSType(): OSType {
return when (System.getProperty("os.name")) {
"Mac OS X" -> OSType.MAC_OS
"Linux" -> OSType.LINUX
else -> OSType.WINDOWS
}
}
38 changes: 0 additions & 38 deletions src/main/kotlin/model/os/factory/OSContextFactory.kt

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/kotlin/model/repository/ProcessRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withTimeout
import model.command.KillCommand
import model.command.ScrcpyCommand
import model.command.creator.ScrcpyCommandCreator
import model.command.ScrcpyCommandCreator
import model.entity.Device

private data class ProcessState(
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/model/repository/SettingRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import kotlinx.coroutines.withContext
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import model.entity.AppSetting
import model.entity.Setting
import model.os.OSContext
import java.io.File

class SettingRepository(private val osContext: OSContext) {
suspend fun get(): AppSetting {
suspend fun get(): Setting {
return withContext(Dispatchers.IO) {
load()
}
}

suspend fun update(setting: AppSetting) {
suspend fun update(setting: Setting) {
withContext(Dispatchers.IO) {
createDir()
write(setting)
}
}

private fun write(setting: AppSetting) {
private fun write(setting: Setting) {
try {
File(osContext.settingPath + SETTING_FILE_NAME).outputStream().apply {
this.write(Json.encodeToString(setting).toByteArray())
Expand All @@ -34,12 +34,12 @@ class SettingRepository(private val osContext: OSContext) {
}
}

private fun load(): AppSetting {
private fun load(): Setting {
return try {
val content = File(osContext.settingPath + SETTING_FILE_NAME).readText()
Json.decodeFromString(string = content)
} catch (e: Exception) {
AppSetting()
Setting()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/model/usecase/FetchSettingUseCase.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package model.usecase

import model.entity.AppSetting
import model.entity.Setting
import model.repository.SettingRepository

class FetchSettingUseCase(private val settingRepository: SettingRepository) {
suspend fun execute(): AppSetting {
suspend fun execute(): Setting {
return settingRepository.get()
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/model/usecase/IsSetupCompletedUseCase.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package model.usecase

import model.command.AdbCommand
import model.command.AdbCommandCreator
import model.command.ScrcpyCommand
import model.command.creator.AdbCommandCreator
import model.command.creator.ScrcpyCommandCreator
import model.command.ScrcpyCommandCreator
import model.repository.SettingRepository

class IsSetupCompletedUseCase(
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/model/usecase/StartAdbServerUseCase.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package model.usecase

import model.command.AdbCommand
import model.command.creator.AdbCommandCreator
import model.command.AdbCommandCreator
import model.repository.SettingRepository

class StartAdbServerUseCase(private val settingRepository: SettingRepository) {
Expand Down
Loading

0 comments on commit 63f55ec

Please sign in to comment.