mirror of
https://github.com/ArvinLovegood/go-stock.git
synced 2025-07-19 00:00:09 +08:00
feat(browser):使用Edge替代Chrome执行AI分析时的依赖
- 新增 checkEdgeOnWindows 函数以检查 Edge 浏览器安装情况 - 修改 AI 分析相关功能,使用 Edge 浏览器代替 Chrome - 更新相关日志和错误处理
This commit is contained in:
parent
7e5d135483
commit
e24965393b
37
app.go
37
app.go
@ -127,11 +127,22 @@ func (a *App) domReady(ctx context.Context) {
|
||||
go func() {
|
||||
checkUpdate(a)
|
||||
}()
|
||||
|
||||
//检查谷歌浏览器
|
||||
//go func() {
|
||||
// f := checkChromeOnWindows()
|
||||
// if !f {
|
||||
// go runtime.EventsEmit(a.ctx, "warnMsg", "谷歌浏览器未安装,ai分析功能可能无法使用")
|
||||
// }
|
||||
//}()
|
||||
|
||||
//检查Edge浏览器
|
||||
go func() {
|
||||
f := checkChromeOnWindows()
|
||||
if !f {
|
||||
go runtime.EventsEmit(a.ctx, "warnMsg", "谷歌浏览器未安装,ai分析功能可能无法使用")
|
||||
path, e := checkEdgeOnWindows()
|
||||
if !e {
|
||||
go runtime.EventsEmit(a.ctx, "warnMsg", "Edge浏览器未安装,ai分析功能可能无法使用")
|
||||
} else {
|
||||
logger.SugaredLogger.Infof("Edge浏览器已安装,路径为: %s", path)
|
||||
}
|
||||
}()
|
||||
}
|
||||
@ -464,6 +475,26 @@ func checkChromeOnWindows() bool {
|
||||
_, _, err = key.GetValue("Path", nil)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// checkEdgeOnWindows 在 Windows 系统上检查Edge浏览器是否安装,并返回安装路径
|
||||
func checkEdgeOnWindows() (string, bool) {
|
||||
key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe`, registry.QUERY_VALUE)
|
||||
if err != nil {
|
||||
// 尝试在 WOW6432Node 中查找(适用于 64 位系统上的 32 位程序)
|
||||
key, err = registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe`, registry.QUERY_VALUE)
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
defer key.Close()
|
||||
}
|
||||
defer key.Close()
|
||||
path, _, err := key.GetStringValue("Path")
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
return path, true
|
||||
}
|
||||
|
||||
func GetImageBase(bytes []byte) string {
|
||||
return "data:image/jpeg;base64," + base64.StdEncoding.EncodeToString(bytes)
|
||||
}
|
||||
|
@ -294,8 +294,16 @@ func GetFinancialReports(stockCode string) *[]string {
|
||||
timeoutCtx, timeoutCtxCancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer timeoutCtxCancel()
|
||||
|
||||
ctx, cancel := chromedp.NewContext(
|
||||
edgePath := `C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe`
|
||||
|
||||
pctx, pcancel := chromedp.NewExecAllocator(
|
||||
timeoutCtx,
|
||||
chromedp.ExecPath(edgePath),
|
||||
chromedp.Flag("headless", true),
|
||||
)
|
||||
defer pcancel()
|
||||
ctx, cancel := chromedp.NewContext(
|
||||
pctx,
|
||||
chromedp.WithLogf(logger.SugaredLogger.Infof),
|
||||
chromedp.WithErrorf(logger.SugaredLogger.Errorf),
|
||||
)
|
||||
|
@ -522,11 +522,20 @@ func SearchStockPriceInfo(stockCode string) *[]string {
|
||||
timeoutCtx, timeoutCtxCancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer timeoutCtxCancel()
|
||||
|
||||
ctx, cancel := chromedp.NewContext(
|
||||
edgePath := `C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe`
|
||||
|
||||
pctx, pcancel := chromedp.NewExecAllocator(
|
||||
timeoutCtx,
|
||||
chromedp.ExecPath(edgePath),
|
||||
chromedp.Flag("headless", true),
|
||||
)
|
||||
defer pcancel()
|
||||
ctx, cancel := chromedp.NewContext(
|
||||
pctx,
|
||||
chromedp.WithLogf(logger.SugaredLogger.Infof),
|
||||
chromedp.WithErrorf(logger.SugaredLogger.Errorf),
|
||||
)
|
||||
|
||||
defer cancel()
|
||||
|
||||
defer func(ctx context.Context) {
|
||||
@ -594,9 +603,16 @@ func SearchStockInfo(stock, msgType string) *[]string {
|
||||
// 创建一个 chromedp 上下文
|
||||
timeoutCtx, timeoutCtxCancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer timeoutCtxCancel()
|
||||
edgePath := `C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe`
|
||||
|
||||
ctx, cancel := chromedp.NewContext(
|
||||
pctx, pcancel := chromedp.NewExecAllocator(
|
||||
timeoutCtx,
|
||||
chromedp.ExecPath(edgePath),
|
||||
chromedp.Flag("headless", true),
|
||||
)
|
||||
defer pcancel()
|
||||
ctx, cancel := chromedp.NewContext(
|
||||
pctx,
|
||||
chromedp.WithLogf(logger.SugaredLogger.Infof),
|
||||
chromedp.WithErrorf(logger.SugaredLogger.Errorf),
|
||||
)
|
||||
|
@ -1 +1 @@
|
||||
663ba262da70968efc6e3c699fb685b3
|
||||
3234b0467a05bbf094762aef81a1e9b0
|
Loading…
x
Reference in New Issue
Block a user