Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35284395b3 | ||
|
|
38f5c400d6 | ||
|
|
704bfa1c8a |
No files matched your search
@@ -1,5 +1,26 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v2.2.0 (2026-10-23)
|
||||||
|
|
||||||
|
- ✨ **主界面停靠浏览器右侧(Side Panel)**:点扩展图标直接在浏览器右缘打开/收起侧栏,常驻停靠、随浏览器窗口走,可拖拽调宽
|
||||||
|
- 移除旧的气泡弹窗形态(default_popup → side_panel);保留「窗口」按钮用于桌面级右侧独立窗口
|
||||||
|
- 兼容:侧栏上下文中「窗口」按钮不再误关自己
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v2.1.5 (2026-10-23)
|
||||||
|
|
||||||
|
- ✨ 「窗口」按钮打开的独立窗口**固定停靠屏幕右侧**:贴右缘、占满可用高度(排除任务栏)、宽 440
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v2.1.4 (2026-10-23)
|
||||||
|
|
||||||
|
- ✨ 设置内容全部**移出抽屉、内联到首页**(同步桥接状态/Token/地址、悬浮按钮、自建站点、历史入口直接可见)
|
||||||
|
- 🗑️ 删除首页「谢谢支持」分享横幅(含分享/GitHub 文案);顶栏「设置」按钮与设置抽屉一并移除
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## v2.1.3 (2026-10-23)
|
## v2.1.3 (2026-10-23)
|
||||||
|
|
||||||
- 🆕 新增「窗口」入口:扩展可在**独立窗口**中打开并常驻保持(不随点击外部关闭,适合长期盯同步桥接/公众号在线状态)
|
- 🆕 新增「窗口」入口:扩展可在**独立窗口**中打开并常驻保持(不随点击外部关闭,适合长期盯同步桥接/公众号在线状态)
|
||||||
|
|||||||
@@ -2,15 +2,17 @@
|
|||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "文章同步助手",
|
"name": "文章同步助手",
|
||||||
"description": "一键同步文章到知乎、头条、掘金等 20+ 平台,支持公众号多账号保持在线",
|
"description": "一键同步文章到知乎、头条、掘金等 20+ 平台,支持公众号多账号保持在线",
|
||||||
"version": "2.1.3",
|
"version": "2.2.0",
|
||||||
"icons": {
|
"icons": {
|
||||||
"16": "assets/icon-16.png",
|
"16": "assets/icon-16.png",
|
||||||
"48": "assets/icon-48.png",
|
"48": "assets/icon-48.png",
|
||||||
"128": "assets/icon-128.png"
|
"128": "assets/icon-128.png"
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
"default_icon": "assets/icon-48.png",
|
"default_icon": "assets/icon-48.png"
|
||||||
"default_popup": "src/popup/index.html"
|
},
|
||||||
|
"side_panel": {
|
||||||
|
"default_path": "src/popup/index.html"
|
||||||
},
|
},
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"storage",
|
"storage",
|
||||||
@@ -22,7 +24,8 @@
|
|||||||
"tabs",
|
"tabs",
|
||||||
"alarms",
|
"alarms",
|
||||||
"contextMenus",
|
"contextMenus",
|
||||||
"downloads"
|
"downloads",
|
||||||
|
"sidePanel"
|
||||||
],
|
],
|
||||||
"host_permissions": [
|
"host_permissions": [
|
||||||
"http://*/*",
|
"http://*/*",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@wechatsync/extension",
|
"name": "@wechatsync/extension",
|
||||||
"version": "2.1.3",
|
"version": "2.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "微信公众号同步助手 Chrome 扩展",
|
"description": "微信公众号同步助手 Chrome 扩展",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -1147,6 +1147,25 @@ function getCmsIcon(type: string): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展主界面停靠浏览器右侧(sidePanel)
|
||||||
|
* - 点扩展图标直接在浏览器右缘打开/收起侧栏(常驻停靠,随浏览器窗口走)
|
||||||
|
* - setPanelBehavior 不可用时回退:图标点击手动开侧栏
|
||||||
|
*/
|
||||||
|
chrome.sidePanel
|
||||||
|
.setPanelBehavior({ openPanelOnActionClick: true })
|
||||||
|
.catch(() => {
|
||||||
|
chrome.action.onClicked.addListener(async (tab) => {
|
||||||
|
if (!tab.id) return
|
||||||
|
try {
|
||||||
|
await chrome.sidePanel.setOptions({ tabId: tab.id, enabled: true })
|
||||||
|
await chrome.sidePanel.open({ tabId: tab.id })
|
||||||
|
} catch {
|
||||||
|
/* 忽略:无侧栏权限的老环境 */
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理右键菜单点击
|
* 处理右键菜单点击
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,317 +0,0 @@
|
|||||||
import { useState, useEffect, useRef } from 'react'
|
|
||||||
import { X, Plug, PlugZap, Plus, Trash2, ChevronRight } from 'lucide-react'
|
|
||||||
import { cn } from '@/lib/utils'
|
|
||||||
import { trackFeatureDiscovery } from '../../lib/analytics'
|
|
||||||
|
|
||||||
interface SettingsDrawerProps {
|
|
||||||
open: boolean
|
|
||||||
onClose: () => void
|
|
||||||
}
|
|
||||||
|
|
||||||
interface McpStatus {
|
|
||||||
enabled: boolean
|
|
||||||
connected: boolean
|
|
||||||
token?: string
|
|
||||||
serverUrl?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CMSAccount {
|
|
||||||
id: string
|
|
||||||
name: string
|
|
||||||
type: string
|
|
||||||
url: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function SettingsDrawer({ open, onClose }: SettingsDrawerProps) {
|
|
||||||
const [mcpStatus, setMcpStatus] = useState<McpStatus>({ enabled: true, connected: false })
|
|
||||||
const [cmsAccounts, setCmsAccounts] = useState<CMSAccount[]>([])
|
|
||||||
const [loading, setLoading] = useState(false)
|
|
||||||
const [floatingButtonEnabled, setFloatingButtonEnabled] = useState(false)
|
|
||||||
const [serverUrlInput, setServerUrlInput] = useState('')
|
|
||||||
const serverUrlTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
||||||
|
|
||||||
// 获取状态
|
|
||||||
useEffect(() => {
|
|
||||||
if (!open) return
|
|
||||||
|
|
||||||
// MCP 状态
|
|
||||||
chrome.runtime.sendMessage({ type: 'MCP_STATUS' }, (response) => {
|
|
||||||
if (response && !response.error) {
|
|
||||||
setMcpStatus({
|
|
||||||
enabled: response.enabled ?? false,
|
|
||||||
connected: response.connected ?? false,
|
|
||||||
token: response.token,
|
|
||||||
serverUrl: response.serverUrl,
|
|
||||||
})
|
|
||||||
setServerUrlInput(response.serverUrl || '')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// CMS 账户
|
|
||||||
chrome.storage.local.get('cmsAccounts', (result) => {
|
|
||||||
setCmsAccounts(result.cmsAccounts || [])
|
|
||||||
})
|
|
||||||
|
|
||||||
// 悬浮按钮设置
|
|
||||||
chrome.storage.local.get('floatingButtonEnabled', (result) => {
|
|
||||||
setFloatingButtonEnabled(result.floatingButtonEnabled ?? false)
|
|
||||||
})
|
|
||||||
}, [open])
|
|
||||||
|
|
||||||
// MCP 状态轮询 + 通知 background 加速重连
|
|
||||||
useEffect(() => {
|
|
||||||
if (!open || !mcpStatus.enabled) return
|
|
||||||
|
|
||||||
// 通知 background:用户正在关注,加速重连
|
|
||||||
chrome.runtime.sendMessage({ type: 'MCP_WATCH_START' })
|
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
|
||||||
chrome.runtime.sendMessage({ type: 'MCP_STATUS' }, (response) => {
|
|
||||||
if (response && !response.error) {
|
|
||||||
setMcpStatus(prev => ({ ...prev, connected: response.connected ?? false }))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}, 3000)
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
clearInterval(interval)
|
|
||||||
// 设置页关闭,恢复正常重连策略
|
|
||||||
chrome.runtime.sendMessage({ type: 'MCP_WATCH_STOP' })
|
|
||||||
}
|
|
||||||
}, [open, mcpStatus.enabled])
|
|
||||||
|
|
||||||
// 同步桥接锁定为「始终连接」:点击只会确保开启,无法关闭
|
|
||||||
const toggleMcp = async () => {
|
|
||||||
setLoading(true)
|
|
||||||
// 追踪 MCP 功能发现
|
|
||||||
trackFeatureDiscovery('mcp', 'settings').catch(() => {})
|
|
||||||
|
|
||||||
chrome.runtime.sendMessage({ type: 'MCP_ENABLE' }, (response) => {
|
|
||||||
setLoading(false)
|
|
||||||
if (response?.success) {
|
|
||||||
setMcpStatus(prev => ({
|
|
||||||
...prev,
|
|
||||||
enabled: true,
|
|
||||||
token: response.token ?? prev.token, // 保存返回的 token
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 服务器地址变更(防抖 800ms)
|
|
||||||
const handleServerUrlChange = (value: string) => {
|
|
||||||
setServerUrlInput(value)
|
|
||||||
if (serverUrlTimer.current) {
|
|
||||||
clearTimeout(serverUrlTimer.current)
|
|
||||||
}
|
|
||||||
serverUrlTimer.current = setTimeout(() => {
|
|
||||||
chrome.runtime.sendMessage({
|
|
||||||
type: 'MCP_SET_SERVER_URL',
|
|
||||||
payload: { url: value.trim() },
|
|
||||||
})
|
|
||||||
setMcpStatus(prev => ({ ...prev, serverUrl: value.trim() }))
|
|
||||||
}, 800)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 切换悬浮按钮
|
|
||||||
const toggleFloatingButton = () => {
|
|
||||||
const next = !floatingButtonEnabled
|
|
||||||
setFloatingButtonEnabled(next)
|
|
||||||
chrome.storage.local.set({ floatingButtonEnabled: next })
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除 CMS 账户
|
|
||||||
const deleteCmsAccount = async (id: string) => {
|
|
||||||
// 直接从 storage 读取最新数据,避免多窗口操作时覆盖
|
|
||||||
const storage = await chrome.storage.local.get('cmsAccounts')
|
|
||||||
const accounts: CMSAccount[] = storage.cmsAccounts || []
|
|
||||||
const updated = accounts.filter(a => a.id !== id)
|
|
||||||
await chrome.storage.local.set({ cmsAccounts: updated })
|
|
||||||
await chrome.storage.local.remove(`cms_pwd_${id}`)
|
|
||||||
setCmsAccounts(updated)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!open) return null
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{/* 遮罩 */}
|
|
||||||
<div
|
|
||||||
className="fixed inset-0 bg-black/50 z-40"
|
|
||||||
onClick={onClose}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* 抽屉 */}
|
|
||||||
<div className={cn(
|
|
||||||
'fixed inset-y-0 right-0 w-80 bg-background z-50 shadow-xl',
|
|
||||||
'transform transition-transform duration-200',
|
|
||||||
open ? 'translate-x-0' : 'translate-x-full'
|
|
||||||
)}>
|
|
||||||
{/* 头部 */}
|
|
||||||
<div className="flex items-center justify-between p-4 border-b">
|
|
||||||
<h2 className="font-semibold">设置</h2>
|
|
||||||
<button
|
|
||||||
onClick={onClose}
|
|
||||||
className="p-1 rounded hover:bg-muted"
|
|
||||||
>
|
|
||||||
<X className="w-5 h-5" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 内容 */}
|
|
||||||
<div className="p-4 space-y-6 overflow-y-auto h-[calc(100%-57px)]">
|
|
||||||
{/* 同步桥接设置 */}
|
|
||||||
<div className="space-y-3">
|
|
||||||
<h3 className="text-sm font-medium text-muted-foreground">同步桥接</h3>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-between p-3 bg-muted/50 rounded-lg">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
{mcpStatus.connected ? (
|
|
||||||
<PlugZap className="w-5 h-5 text-green-500" />
|
|
||||||
) : (
|
|
||||||
<Plug className="w-5 h-5 text-muted-foreground" />
|
|
||||||
)}
|
|
||||||
<div>
|
|
||||||
<p className="text-sm font-medium">CLI / MCP 连接</p>
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{mcpStatus.enabled
|
|
||||||
? mcpStatus.connected
|
|
||||||
? '已连接'
|
|
||||||
: '等待连接...'
|
|
||||||
: '未启用'}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
onClick={toggleMcp}
|
|
||||||
disabled={loading}
|
|
||||||
title="始终连接(已锁定,不可关闭)"
|
|
||||||
className={cn(
|
|
||||||
'relative w-11 h-6 rounded-full transition-colors cursor-default',
|
|
||||||
'bg-primary opacity-100',
|
|
||||||
loading && 'opacity-50'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className={cn(
|
|
||||||
'absolute top-1 w-4 h-4 rounded-full bg-white transition-transform',
|
|
||||||
'translate-x-6'
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
供 CLI 和 MCP Server 通过 WebSocket 桥接同步文章 —— 始终连接,已锁定不可关闭
|
|
||||||
</p>
|
|
||||||
{mcpStatus.token && (
|
|
||||||
<div className="p-2 bg-muted/50 rounded text-xs">
|
|
||||||
<p className="text-muted-foreground mb-1">Token:</p>
|
|
||||||
<code className="block bg-background p-1.5 rounded break-all select-all">
|
|
||||||
{mcpStatus.token}
|
|
||||||
</code>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className="p-2 bg-muted/50 rounded text-xs">
|
|
||||||
<p className="text-muted-foreground mb-1">服务器地址 (留空使用本地默认):</p>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
value={serverUrlInput}
|
|
||||||
onChange={(e) => handleServerUrlChange(e.target.value)}
|
|
||||||
placeholder="ws://192.168.68.19:9600"
|
|
||||||
className="w-full bg-background p-1.5 rounded border border-border text-xs font-mono focus:outline-none focus:ring-1 focus:ring-primary"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 悬浮同步按钮 */}
|
|
||||||
<div className="space-y-3">
|
|
||||||
<h3 className="text-sm font-medium text-muted-foreground">网页功能</h3>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-between p-3 bg-muted/50 rounded-lg">
|
|
||||||
<div>
|
|
||||||
<p className="text-sm font-medium">悬浮同步按钮</p>
|
|
||||||
<p className="text-xs text-muted-foreground">在网页右下角显示快捷同步按钮</p>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
onClick={toggleFloatingButton}
|
|
||||||
className={cn(
|
|
||||||
'relative w-11 h-6 rounded-full transition-colors',
|
|
||||||
floatingButtonEnabled ? 'bg-primary' : 'bg-muted-foreground/30',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className={cn(
|
|
||||||
'absolute top-1 w-4 h-4 rounded-full bg-white transition-transform',
|
|
||||||
floatingButtonEnabled ? 'translate-x-6' : 'translate-x-1'
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* CMS 账户 */}
|
|
||||||
<div className="space-y-3">
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<h3 className="text-sm font-medium text-muted-foreground">自建站点</h3>
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
onClose()
|
|
||||||
window.location.hash = '/add-cms'
|
|
||||||
}}
|
|
||||||
className="flex items-center gap-1 text-xs text-primary hover:underline"
|
|
||||||
>
|
|
||||||
<Plus className="w-3 h-3" />
|
|
||||||
添加
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{cmsAccounts.length === 0 ? (
|
|
||||||
<p className="text-xs text-muted-foreground text-center py-4">
|
|
||||||
暂无自建站点
|
|
||||||
</p>
|
|
||||||
) : (
|
|
||||||
<div className="space-y-2">
|
|
||||||
{cmsAccounts.map(account => (
|
|
||||||
<div
|
|
||||||
key={account.id}
|
|
||||||
className="flex items-center justify-between p-2 bg-muted/50 rounded-lg"
|
|
||||||
>
|
|
||||||
<div className="flex-1 min-w-0">
|
|
||||||
<p className="text-sm font-medium truncate">{account.name}</p>
|
|
||||||
<p className="text-xs text-muted-foreground truncate">{account.url}</p>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
onClick={() => deleteCmsAccount(account.id)}
|
|
||||||
className="p-1 text-muted-foreground hover:text-destructive"
|
|
||||||
>
|
|
||||||
<Trash2 className="w-4 h-4" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 历史记录 */}
|
|
||||||
<div className="space-y-3">
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
onClose()
|
|
||||||
window.location.hash = '/history'
|
|
||||||
}}
|
|
||||||
className="flex items-center justify-between w-full p-3 bg-muted/50 rounded-lg hover:bg-muted"
|
|
||||||
>
|
|
||||||
<span className="text-sm font-medium">查看全部历史</span>
|
|
||||||
<ChevronRight className="w-4 h-4 text-muted-foreground" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,264 @@
|
|||||||
|
import { useState, useEffect, useRef } from 'react'
|
||||||
|
import { Plug, PlugZap, Plus, Trash2, ChevronRight } from 'lucide-react'
|
||||||
|
import { cn } from '@/lib/utils'
|
||||||
|
import { trackFeatureDiscovery } from '../../lib/analytics'
|
||||||
|
|
||||||
|
interface McpStatus {
|
||||||
|
enabled: boolean
|
||||||
|
connected: boolean
|
||||||
|
token?: string
|
||||||
|
serverUrl?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CMSAccount {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
type: string
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置面板(内联版)—— 从原设置抽屉移出,直接展示在首页上。
|
||||||
|
* 同步桥接锁定为始终连接,不可关闭。
|
||||||
|
*/
|
||||||
|
export function SettingsPanel() {
|
||||||
|
const [mcpStatus, setMcpStatus] = useState<McpStatus>({ enabled: true, connected: false })
|
||||||
|
const [cmsAccounts, setCmsAccounts] = useState<CMSAccount[]>([])
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [floatingButtonEnabled, setFloatingButtonEnabled] = useState(false)
|
||||||
|
const [serverUrlInput, setServerUrlInput] = useState('')
|
||||||
|
const serverUrlTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||||
|
|
||||||
|
// 获取状态(面板常驻,挂载即加载)
|
||||||
|
useEffect(() => {
|
||||||
|
// MCP 状态
|
||||||
|
chrome.runtime.sendMessage({ type: 'MCP_STATUS' }, (response) => {
|
||||||
|
if (response && !response.error) {
|
||||||
|
setMcpStatus({
|
||||||
|
enabled: response.enabled ?? false,
|
||||||
|
connected: response.connected ?? false,
|
||||||
|
token: response.token,
|
||||||
|
serverUrl: response.serverUrl,
|
||||||
|
})
|
||||||
|
setServerUrlInput(response.serverUrl || '')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// CMS 账户
|
||||||
|
chrome.storage.local.get('cmsAccounts', (result) => {
|
||||||
|
setCmsAccounts(result.cmsAccounts || [])
|
||||||
|
})
|
||||||
|
|
||||||
|
// 悬浮按钮设置
|
||||||
|
chrome.storage.local.get('floatingButtonEnabled', (result) => {
|
||||||
|
setFloatingButtonEnabled(result.floatingButtonEnabled ?? false)
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// MCP 状态轮询 + 通知 background 加速重连
|
||||||
|
useEffect(() => {
|
||||||
|
// 通知 background:用户正在关注,加速重连
|
||||||
|
chrome.runtime.sendMessage({ type: 'MCP_WATCH_START' })
|
||||||
|
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
chrome.runtime.sendMessage({ type: 'MCP_STATUS' }, (response) => {
|
||||||
|
if (response && !response.error) {
|
||||||
|
setMcpStatus(prev => ({ ...prev, connected: response.connected ?? false }))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, 3000)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearInterval(interval)
|
||||||
|
// 面板卸载,恢复正常重连策略
|
||||||
|
chrome.runtime.sendMessage({ type: 'MCP_WATCH_STOP' })
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// 桥接始终连接:点击只确保开启,不会关闭
|
||||||
|
const toggleMcp = async () => {
|
||||||
|
if (loading) return
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
chrome.runtime.sendMessage({ type: 'MCP_ENABLE' }, () => {
|
||||||
|
setMcpStatus(prev => ({ ...prev, enabled: true }))
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 服务器地址输入(防抖保存)
|
||||||
|
const handleServerUrlChange = (value: string) => {
|
||||||
|
setServerUrlInput(value)
|
||||||
|
trackFeatureDiscovery('mcp_server_url_input', 'home_panel')
|
||||||
|
if (serverUrlTimer.current) clearTimeout(serverUrlTimer.current)
|
||||||
|
serverUrlTimer.current = setTimeout(() => {
|
||||||
|
chrome.storage.local.set({ mcpServerUrl: value }, () => {
|
||||||
|
chrome.runtime.sendMessage({ type: 'MCP_SET_SERVER_URL', serverUrl: value })
|
||||||
|
})
|
||||||
|
}, 600)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 悬浮按钮开关
|
||||||
|
const toggleFloatingButton = () => {
|
||||||
|
const next = !floatingButtonEnabled
|
||||||
|
setFloatingButtonEnabled(next)
|
||||||
|
chrome.storage.local.set({ floatingButtonEnabled: next })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除 CMS 账户
|
||||||
|
const deleteCmsAccount = (id: string) => {
|
||||||
|
const next = cmsAccounts.filter(a => a.id !== id)
|
||||||
|
setCmsAccounts(next)
|
||||||
|
chrome.storage.local.set({ cmsAccounts: next })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="px-4 pt-3 space-y-4">
|
||||||
|
{/* 同步桥接设置 */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h3 className="text-sm font-medium text-muted-foreground">同步桥接</h3>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between p-3 bg-muted/50 rounded-lg">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{mcpStatus.connected ? (
|
||||||
|
<PlugZap className="w-5 h-5 text-green-500" />
|
||||||
|
) : (
|
||||||
|
<Plug className="w-5 h-5 text-muted-foreground" />
|
||||||
|
)}
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium">CLI / MCP 连接</p>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{mcpStatus.enabled
|
||||||
|
? mcpStatus.connected
|
||||||
|
? '已连接'
|
||||||
|
: '等待连接...'
|
||||||
|
: '未启用'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={toggleMcp}
|
||||||
|
disabled={loading}
|
||||||
|
title="始终连接(已锁定,不可关闭)"
|
||||||
|
className={cn(
|
||||||
|
'relative w-11 h-6 rounded-full transition-colors cursor-default',
|
||||||
|
'bg-primary opacity-100',
|
||||||
|
loading && 'opacity-50'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
'absolute top-1 w-4 h-4 rounded-full bg-white transition-transform',
|
||||||
|
'translate-x-6'
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
供 CLI 和 MCP Server 通过 WebSocket 桥接同步文章 —— 始终连接,已锁定不可关闭
|
||||||
|
</p>
|
||||||
|
{mcpStatus.token && (
|
||||||
|
<div className="p-2 bg-muted/50 rounded text-xs">
|
||||||
|
<p className="text-muted-foreground mb-1">Token:</p>
|
||||||
|
<code className="block bg-background p-1.5 rounded break-all select-all">
|
||||||
|
{mcpStatus.token}
|
||||||
|
</code>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="p-2 bg-muted/50 rounded text-xs">
|
||||||
|
<p className="text-muted-foreground mb-1">服务器地址 (留空使用本地默认):</p>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={serverUrlInput}
|
||||||
|
onChange={(e) => handleServerUrlChange(e.target.value)}
|
||||||
|
placeholder="ws://192.168.68.19:9600"
|
||||||
|
className="w-full bg-background p-1.5 rounded border border-border text-xs font-mono focus:outline-none focus:ring-1 focus:ring-primary"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 悬浮同步按钮 */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<h3 className="text-sm font-medium text-muted-foreground">网页功能</h3>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between p-3 bg-muted/50 rounded-lg">
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium">悬浮同步按钮</p>
|
||||||
|
<p className="text-xs text-muted-foreground">在网页右下角显示快捷同步按钮</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={toggleFloatingButton}
|
||||||
|
className={cn(
|
||||||
|
'relative w-11 h-6 rounded-full transition-colors',
|
||||||
|
floatingButtonEnabled ? 'bg-primary' : 'bg-muted-foreground/30',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
'absolute top-1 w-4 h-4 rounded-full bg-white transition-transform',
|
||||||
|
floatingButtonEnabled ? 'translate-x-6' : 'translate-x-1'
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* CMS 账户 */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<h3 className="text-sm font-medium text-muted-foreground">自建站点</h3>
|
||||||
|
<button
|
||||||
|
onClick={() => { window.location.hash = '/add-cms' }}
|
||||||
|
className="flex items-center gap-1 text-xs text-primary hover:underline"
|
||||||
|
>
|
||||||
|
<Plus className="w-3 h-3" />
|
||||||
|
添加
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{cmsAccounts.length === 0 ? (
|
||||||
|
<p className="text-xs text-muted-foreground text-center py-4">
|
||||||
|
暂无自建站点
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{cmsAccounts.map(account => (
|
||||||
|
<div
|
||||||
|
key={account.id}
|
||||||
|
className="flex items-center justify-between p-2 bg-muted/50 rounded-lg"
|
||||||
|
>
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<p className="text-sm font-medium truncate">{account.name}</p>
|
||||||
|
<p className="text-xs text-muted-foreground truncate">{account.url}</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={() => deleteCmsAccount(account.id)}
|
||||||
|
className="p-1 text-muted-foreground hover:text-destructive"
|
||||||
|
>
|
||||||
|
<Trash2 className="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 历史记录 */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<button
|
||||||
|
onClick={() => { window.location.hash = '/history' }}
|
||||||
|
className="flex items-center justify-between w-full p-3 bg-muted/50 rounded-lg hover:bg-muted"
|
||||||
|
>
|
||||||
|
<span className="text-sm font-medium">查看全部历史</span>
|
||||||
|
<ChevronRight className="w-4 h-4 text-muted-foreground" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { Settings, Plus, Clock, X, Download, Info, Wifi, Maximize2 } from 'lucide-react'
|
import { Plus, Clock, X, Download, Info, Wifi, Maximize2 } from 'lucide-react'
|
||||||
import { useSyncStore } from '../stores/sync'
|
import { useSyncStore } from '../stores/sync'
|
||||||
import { SettingsDrawer } from '../components/SettingsDrawer'
|
import { SettingsPanel } from '../components/SettingsPanel'
|
||||||
import { SyncDialog } from '@/components/sync-dialog'
|
import { SyncDialog } from '@/components/sync-dialog'
|
||||||
import type { Platform as DialogPlatform } from '@/components/sync-dialog'
|
import type { Platform as DialogPlatform } from '@/components/sync-dialog'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import { trackPageView, trackFeatureDiscovery } from '../../lib/analytics'
|
import { trackPageView } from '../../lib/analytics'
|
||||||
import { createLogger } from '../../lib/logger'
|
import { createLogger } from '../../lib/logger'
|
||||||
import { getCachedUpdateInfo, dismissUpdate, type UpdateCheckResult } from '../../lib/version-check'
|
import { getCachedUpdateInfo, dismissUpdate, type UpdateCheckResult } from '../../lib/version-check'
|
||||||
|
|
||||||
@@ -36,14 +36,12 @@ export function HomeNew() {
|
|||||||
checkRateLimit,
|
checkRateLimit,
|
||||||
} = useSyncStore()
|
} = useSyncStore()
|
||||||
|
|
||||||
const [settingsOpen, setSettingsOpen] = useState(false)
|
|
||||||
const [rateLimitWarning, setRateLimitWarning] = useState<string | null>(null)
|
const [rateLimitWarning, setRateLimitWarning] = useState<string | null>(null)
|
||||||
const [allPlatforms, setAllPlatforms] = useState<DialogPlatform[]>([])
|
const [allPlatforms, setAllPlatforms] = useState<DialogPlatform[]>([])
|
||||||
|
|
||||||
const [updateInfo, setUpdateInfo] = useState<UpdateCheckResult | null>(null)
|
const [updateInfo, setUpdateInfo] = useState<UpdateCheckResult | null>(null)
|
||||||
const [floatingEnabled, setFloatingEnabled] = useState(false)
|
const [floatingEnabled, setFloatingEnabled] = useState(false)
|
||||||
const [isFirstSync, setIsFirstSync] = useState(false)
|
const [isFirstSync, setIsFirstSync] = useState(false)
|
||||||
const [showShareTip, setShowShareTip] = useState(false)
|
|
||||||
|
|
||||||
// Load data
|
// Load data
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -62,12 +60,9 @@ export function HomeNew() {
|
|||||||
} catch {}
|
} catch {}
|
||||||
loadAllPlatforms()
|
loadAllPlatforms()
|
||||||
loadArticle()
|
loadArticle()
|
||||||
chrome.storage.local.get(['floatingButtonEnabled', 'syncHistory', 'dismissedShareTip'], (r) => {
|
chrome.storage.local.get(['floatingButtonEnabled', 'syncHistory'], (r) => {
|
||||||
setFloatingEnabled(r.floatingButtonEnabled ?? false)
|
setFloatingEnabled(r.floatingButtonEnabled ?? false)
|
||||||
setIsFirstSync(!r.syncHistory || r.syncHistory.length === 0)
|
setIsFirstSync(!r.syncHistory || r.syncHistory.length === 0)
|
||||||
if (!r.dismissedShareTip) {
|
|
||||||
setShowShareTip(true)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
const cached = await getCachedUpdateInfo()
|
const cached = await getCachedUpdateInfo()
|
||||||
if (cached?.hasUpdate && cached.info) {
|
if (cached?.hasUpdate && cached.info) {
|
||||||
@@ -107,14 +102,27 @@ export function HomeNew() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 在独立窗口打开扩展(popup 点外部会自动关闭,独立窗口可常驻保持打开)
|
// 在独立窗口打开扩展(popup 点外部会自动关闭,独立窗口可常驻保持打开)
|
||||||
|
// 固定停靠屏幕右侧:贴右缘、占满可用高度(排除任务栏),宽度 440 便于阅读
|
||||||
const handleOpenInWindow = async () => {
|
const handleOpenInWindow = async () => {
|
||||||
|
const width = 440
|
||||||
|
const height = screen.availHeight
|
||||||
|
const left = Math.max(0, screen.availWidth - width)
|
||||||
await chrome.windows.create({
|
await chrome.windows.create({
|
||||||
url: chrome.runtime.getURL('src/popup/index.html'),
|
url: chrome.runtime.getURL('src/popup/index.html'),
|
||||||
type: 'popup',
|
type: 'popup',
|
||||||
width: 420,
|
width,
|
||||||
height: 720,
|
height,
|
||||||
|
left,
|
||||||
|
top: 0,
|
||||||
|
focused: true,
|
||||||
})
|
})
|
||||||
window.close()
|
// 仅在扩展气泡上下文才关自己;侧栏(sidePanel)里 window.close 无效
|
||||||
|
try {
|
||||||
|
const ctx: any = await (chrome.runtime as any).getContext?.()
|
||||||
|
if (ctx?.contextType === 'POPUP') window.close()
|
||||||
|
} catch {
|
||||||
|
/* 忽略 */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start sync with rate-limit check
|
// Start sync with rate-limit check
|
||||||
@@ -170,21 +178,11 @@ export function HomeNew() {
|
|||||||
<button
|
<button
|
||||||
onClick={handleOpenInWindow}
|
onClick={handleOpenInWindow}
|
||||||
className="flex flex-col items-center gap-0.5 px-2 py-1 rounded-lg hover:bg-muted transition-colors"
|
className="flex flex-col items-center gap-0.5 px-2 py-1 rounded-lg hover:bg-muted transition-colors"
|
||||||
title="在独立窗口打开(常驻保持,不随点击关闭)"
|
title="在右侧独立窗口打开(贴屏幕右缘常驻,不随点击关闭)"
|
||||||
>
|
>
|
||||||
<Maximize2 className="w-3.5 h-3.5" />
|
<Maximize2 className="w-3.5 h-3.5" />
|
||||||
<span className="text-[10px] text-muted-foreground leading-none">窗口</span>
|
<span className="text-[10px] text-muted-foreground leading-none">窗口</span>
|
||||||
</button>
|
</button>
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
setSettingsOpen(true)
|
|
||||||
trackFeatureDiscovery('settings', 'header_icon').catch(() => {})
|
|
||||||
}}
|
|
||||||
className="flex flex-col items-center gap-0.5 px-2 py-1 rounded-lg hover:bg-muted transition-colors"
|
|
||||||
>
|
|
||||||
<Settings className="w-3.5 h-3.5" />
|
|
||||||
<span className="text-[10px] text-muted-foreground leading-none">设置</span>
|
|
||||||
</button>
|
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@@ -228,48 +226,8 @@ export function HomeNew() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Share / welcome banner (first time only) */}
|
{/* 设置(已从抽屉移出,直接内联在首页) */}
|
||||||
{showShareTip && (
|
<SettingsPanel />
|
||||||
<div className="px-4 pt-3">
|
|
||||||
<div className="bg-muted/50 rounded-lg p-3 text-sm relative">
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
setShowShareTip(false)
|
|
||||||
chrome.storage.local.set({ dismissedShareTip: true })
|
|
||||||
}}
|
|
||||||
className="absolute top-2 right-2 text-muted-foreground hover:text-foreground"
|
|
||||||
>
|
|
||||||
<X className="w-4 h-4" />
|
|
||||||
</button>
|
|
||||||
<p className="font-medium mb-1.5">谢谢支持!</p>
|
|
||||||
<p className="text-xs text-muted-foreground leading-relaxed">
|
|
||||||
如果觉得本工具不错,还请分享给你的朋友!
|
|
||||||
<br />
|
|
||||||
如果你是开发者,欢迎参与进来{' '}
|
|
||||||
<a
|
|
||||||
href="https://github.com/wechatsync/Wechatsync"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="text-primary hover:underline"
|
|
||||||
>
|
|
||||||
GitHub
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
<hr className="my-2 border-border" />
|
|
||||||
<p className="text-xs text-muted-foreground text-right">
|
|
||||||
by{' '}
|
|
||||||
<a
|
|
||||||
href="https://fun0.netlify.app/about/?utm_source=wechatsync"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="text-primary hover:underline"
|
|
||||||
>
|
|
||||||
fun
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* SyncDialog — the unified sync flow */}
|
{/* SyncDialog — the unified sync flow */}
|
||||||
<SyncDialog
|
<SyncDialog
|
||||||
@@ -316,9 +274,6 @@ export function HomeNew() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Settings drawer */}
|
|
||||||
<SettingsDrawer open={settingsOpen} onClose={() => setSettingsOpen(false)} />
|
|
||||||
|
|
||||||
{/* Rate limit warning (non-blocking toast) */}
|
{/* Rate limit warning (non-blocking toast) */}
|
||||||
{rateLimitWarning && (
|
{rateLimitWarning && (
|
||||||
<div className="fixed top-2 left-2 right-2 z-50 animate-in fade-in slide-in-from-top-2 duration-200">
|
<div className="fixed top-2 left-2 right-2 z-50 animate-in fade-in slide-in-from-top-2 duration-200">
|
||||||
|
|||||||
Reference in new issue
Block a user