Skip to content

Commit

Permalink
🐛 Fix the problem that chrome-driver chrome-headless-shell does not h…
Browse files Browse the repository at this point in the history
…ave executable permissions in the packaged application package (#759)
  • Loading branch information
guiyanakuang authored Apr 18, 2024
1 parent ea9ead4 commit 2642ff5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
3 changes: 3 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ compose.desktop {
packageName = "Clipevery"
packageVersion = "1.0.0"

// If we want to use arthas attach application in production environment,
// we need to use
// includeAllModules = true
modules("jdk.charsets")

val properties = Properties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.openqa.selenium.Dimension
import org.openqa.selenium.OutputType
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import java.io.File
import java.nio.file.Path
import kotlin.io.path.absolutePathString
import kotlin.math.max
Expand Down Expand Up @@ -50,19 +51,35 @@ object DesktopChromeService : ChromeService {
}

private val initChromeDriver: (String, String, String, Path) -> Unit = { chromeSuffix, driverName, headlessName, resourcesPath ->
val chromeDriverFile =
File(
resourcesPath
.resolve("$CHROME_DRIVER-$chromeSuffix")
.resolve(driverName)
.absolutePathString(),
)

val chromeHeadlessShellFile =
File(
resourcesPath
.resolve("$CHROME_HEADLESS_SHELL-$chromeSuffix")
.resolve(headlessName)
.absolutePathString(),
)

if (!chromeDriverFile.canExecute()) {
chromeDriverFile.setExecutable(true)
}

if (!chromeHeadlessShellFile.canExecute()) {
chromeHeadlessShellFile.setExecutable(true)
}

System.setProperty(
"webdriver.chrome.driver",
resourcesPath
.resolve("$CHROME_DRIVER-$chromeSuffix")
.resolve(driverName)
.absolutePathString(),
)
options.setBinary(
resourcesPath
.resolve("$CHROME_HEADLESS_SHELL-$chromeSuffix")
.resolve(headlessName)
.absolutePathString(),
chromeDriverFile.absolutePath,
)
options.setBinary(chromeHeadlessShellFile.absolutePath)
}

private val windowDimension: Dimension =
Expand Down
21 changes: 12 additions & 9 deletions composeApp/src/desktopMain/kotlin/com/clipevery/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,24 @@ fun main() {
val logger = KotlinLogging.logger {}

logger.info { "Starting Clipevery" }
try {
val koinApplication = Dependencies.koinApplication

val koinApplication = Dependencies.koinApplication

initInject(koinApplication)
initInject(koinApplication)

val clipboardService = koinApplication.koin.get<ClipboardService>()
clipboardService.start()
val clipboardService = koinApplication.koin.get<ClipboardService>()
clipboardService.start()

val cleanClipScheduler = koinApplication.koin.get<CleanClipScheduler>()
cleanClipScheduler.start()
val cleanClipScheduler = koinApplication.koin.get<CleanClipScheduler>()
cleanClipScheduler.start()
} catch (throwable: Throwable) {
logger.error(throwable) { "cant start clipevery" }
}

application {
val ioScope = rememberCoroutineScope { ioDispatcher }

val appUI = koinApplication.koin.get<AppUI>()
val appUI = Dependencies.koinApplication.koin.get<AppUI>()

val trayIcon =
if (currentPlatform().isMacos()) {
Expand Down Expand Up @@ -129,7 +132,7 @@ fun main() {
)
}
ClipeveryApp(
koinApplication,
Dependencies.koinApplication,
hideWindow = { appUI.showMainWindow = false },
exitApplication = exitApplication,
)
Expand Down

0 comments on commit 2642ff5

Please sign in to comment.