Skip to content

Commit

Permalink
feat: setup chrome command, close #29
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed Sep 2, 2023
1 parent 2823f4b commit f3f00ee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public object MiraiSeleniumPlugin : KotlinPlugin(
@JvmOverloads
public fun chromium(version: String = ""): File = setupChromium(folder = dataFolder, version = version)

/**
* 下载解压 chrome
* @param version 浏览器版本
* @see setupChrome
*/
@JvmOverloads
public fun chrome(version: String = ""): File = setupChrome(folder = dataFolder, version = version)

override fun PluginComponentStorage.onLoad() {
SeleniumLogger.level = Level.OFF
System.setProperty(CHROME_DRIVER_MIRRORS, "https://npm.taobao.org/mirrors/chromedriver")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ public object SeleniumCommand : CompositeCommand(
}
}

/**
* 安装 chrome
* @param version 版本
*/
@SubCommand
@Description("下载解压 chrome")
public suspend fun CommandSender.chrome(version: String = "") {
sendMessage("下载 chrome 开始, version: ${version.ifBlank { "latest" }}")
try {
val binary = MiraiSeleniumPlugin.chrome(version = version)
sendMessage("下载结束,binary: ${binary.absolutePath}")
} catch (cause: IOException) {
logger.warning("下载 chrome 异常", cause)
sendMessage("下载 chrome 异常")
} finally {
MiraiBrowserConfig.chrome = System.getProperty(CHROME_BROWSER_BINARY).orEmpty()
}
}

/**
* 测试 图表绘制功能
*/
Expand Down

0 comments on commit f3f00ee

Please sign in to comment.