| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- // ============================================================================
- // ticker.go — 滚动条窗口
- //
- // 股票条 / 新闻条:无边框、透明、置顶、可拖动的屏幕顶部一行窗口;
- // 位置拖动后延迟保存,重启恢复。
- // ============================================================================
- package main
- import (
- "github.com/wailsapp/wails/v3/pkg/application"
- )
- // 滚动条窗口(股票条 / 新闻条):无边框、透明、置顶、可拖动的一行窗口
- var (
- stockTickerWin *application.WebviewWindow // 股票滚动条窗口
- newsTickerWin *application.WebviewWindow // 新闻滚动条窗口
- mobileMode bool // 移动端(窄屏)模式:禁止创建滚动条窗口
- )
- // SetMobileMode 由前端在窗口尺寸变化时调用:移动端隐藏主机 Tab 并禁止滚动条
- func SetMobileMode(mobile bool) {
- mobileMode = mobile
- syncTickerWindows(loadSettings()) // 立即按新模式刷新滚动条
- }
- // syncTickerWindows 按配置创建 / 关闭 / 刷新两个滚动条窗口
- func syncTickerWindows(settings AppSettings) {
- stockTickerWin = syncTickerWindow("stock", settings.StockTicker, stockTickerWin)
- newsTickerWin = syncTickerWindow("news", settings.NewsTicker, newsTickerWin)
- }
- // syncTickerWindow 同步单个滚动条窗口状态:
- // 关闭 → 已开启则创建;配置变化 → 重载页面(ticker.js 启动时读取最新配置);已开启 → 关闭
- func syncTickerWindow(kind string, cfg TickerConfig, win *application.WebviewWindow) *application.WebviewWindow {
- if mobileMode { // 移动端禁止滚动文本:已开则关闭,不创建
- if win != nil {
- win.Close()
- }
- return nil
- }
- if !cfg.Enabled {
- if win != nil {
- win.Close() // 配置关闭时销毁窗口
- }
- return nil
- }
- if win != nil {
- width := cfg.Width
- if width < 200 {
- width = 1400 // 未配置时用默认宽度
- }
- win.SetSize(width, cfg.FontSize+18) // 宽度 / 字号变化时同步窗口尺寸
- win.Reload() // 让页面重新读取颜色 / 速度等配置
- return win
- }
- x, y := cfg.X, cfg.Y
- if x < 0 || y < 0 {
- x, y = 100, 0 // 首次显示默认放在屏幕顶部
- }
- width := cfg.Width
- if width < 200 {
- width = 1400 // 未配置时用默认宽度
- }
- return app.Window.NewWithOptions(application.WebviewWindowOptions{
- Name: "ticker-" + kind,
- Title: "腾图滚动条",
- Width: width,
- Height: cfg.FontSize + 18, // 一行文字高度
- X: x,
- Y: y,
- AlwaysOnTop: true, // 置顶显示
- DisableResize: true, // 固定尺寸
- Frameless: true, // 无边框
- BackgroundType: application.BackgroundTypeTransparent, // 透明背景
- URL: "/ticker.html?kind=" + kind,
- DevToolsEnabled: false,
- DefaultContextMenuDisabled: true,
- Windows: application.WindowsWindow{
- HiddenOnTaskbar: true, // 不占任务栏
- },
- })
- }
|