Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Use chrome-headless-shell for HTML rendering without window creation #1925

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface ModuleLoader : Loader<ModuleLoaderConfig, Boolean> {
* Install module from path to path
*/
fun installModule(
fileName: String,
downloadPath: Path,
installPath: Path,
): Boolean
Expand All @@ -54,42 +55,52 @@ interface ModuleLoader : Loader<ModuleLoaderConfig, Boolean> {

override fun load(value: ModuleLoaderConfig): Boolean {
val installPath = value.installPath
for (moduleItem in value.moduleItems) {
val urls = moduleItem.getUrls()
val installResult: Boolean? =
retryUtils.retry(value.retryNumber) {
val downTempPath = userDataPathProvider.resolve(moduleItem.downloadFileName, AppFileType.TEMP)
if (!fileUtils.existFile(downTempPath)) {
if (!downloadModule(urls[it], downTempPath)) {

if (!installed(installPath)) {
for (moduleItem in value.moduleItems) {
val urls = moduleItem.getUrls()
val installResult: Boolean? =
retryUtils.retry(value.retryNumber) {
val downTempPath =
userDataPathProvider.resolve(
moduleItem.downloadFileName,
AppFileType.TEMP,
)
if (!fileUtils.existFile(downTempPath)) {
if (!downloadModule(urls[it], downTempPath)) {
fileUtils.deleteFile(downTempPath)
return@retry null
}
}

if (!verifyInstall(downTempPath, moduleItem.sha256)) {
fileUtils.deleteFile(downTempPath)
return@retry null
}
}

if (!verifyInstall(downTempPath, moduleItem.sha256)) {
fileUtils.deleteFile(downTempPath)
return@retry null
if (installModule(moduleItem.downloadFileName, downTempPath, installPath)) {
return@retry true
} else {
return@retry null
}
}

if (installModule(downTempPath, installPath)) {
return@retry true
} else {
return@retry null
}
if (installResult != true) {
return false
}

if (installResult != true) {
return false
}
makeInstalled(installPath)
}

makeInstalled(installPath)

for (moduleItem in value.moduleItems) {
val downTempPath = userDataPathProvider.resolve(moduleItem.downloadFileName, AppFileType.TEMP)
fileUtils.deleteFile(downTempPath)
if (installed(installPath)) {
for (moduleItem in value.moduleItems) {
val downTempPath =
userDataPathProvider.resolve(moduleItem.downloadFileName, AppFileType.TEMP)
fileUtils.deleteFile(downTempPath)
}
return true
} else {
return false
}

return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ class ChromeModuleLoader(
override val logger: KLogger = KotlinLogging.logger {}

override fun installModule(
fileName: String,
downloadPath: Path,
installPath: Path,
): Boolean {
if (!downloadPath.toString().lowercase().endsWith(".zip")) {
logger.error { "Error: Downloaded file is not a zip archive" }
logger.error { "Error: Downloaded $fileName is not a zip archive" }
return false
}

try {
// Decompress the downloaded file to installPath, this function needs to be idempotent and can be executed repeatedly
// Decompress the downloaded file to installPath,
// this function needs to be idempotent and can be executed repeatedly
unzipFile(downloadPath, installPath)
logger.info { "Module installed successfully" }
logger.info { "$fileName installed successfully" }
return true
} catch (e: Exception) {
logger.error { "Error during module installation: ${e.message}" }
logger.error { "Error during $fileName installation: ${e.message}" }
return false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,16 @@ class DesktopChromeService(
val chromeServiceModule = ChromeServiceServiceModule(chromeDriverProperties)

val optLoaderConfig = chromeServiceModule.getModuleLoaderConfig()
optLoaderConfig?.let { loaderConfig ->
if (chromeModuleLoader.installed(loaderConfig.installPath)) {
startByLoaderModule(loaderConfig)
startSuccess = true
return
}
}

try {
chromeDriverService = ChromeDriverService.createDefaultService()
chromeDriver = ChromeDriver(chromeDriverService, options)
startSuccess = true
} catch (e: Exception) {
logger.error(e) { "chromeDriver auto init fail" }
optLoaderConfig?.let { loaderConfig ->
if (chromeModuleLoader.load(loaderConfig)) {
startByLoaderModule(loaderConfig)
startSuccess = true
return
}
}
} catch (e: Exception) {
startSuccess = false
return
}
Expand Down
Loading