mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 01:05:30 +08:00
1 parent
194dd0035b
commit
e5a1656644
10 files changed
+241
-19
No files matched your search
+21
-7
@@ -21,7 +21,10 @@ import { dirname, extname, join } from 'path'
|
||||
import { existsSync, promises as fsPromises } from 'fs'
|
||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||
import icon from '../../resources/icon.png?asset'
|
||||
import trayTemplateIcon from '../../resources/trayTemplate.png?asset'
|
||||
import trayTemplateRetinaIcon from '../../resources/trayTemplate@2x.png?asset'
|
||||
import { WechatDb } from './wechat-db'
|
||||
import { createTrayImage } from './tray-icon'
|
||||
import { bootstrapWcdbNativeAsync, Wcdb4Client } from './wcdb4-client'
|
||||
import { VoiceService } from './voice-service'
|
||||
import { StickerService } from './sticker-service'
|
||||
@@ -370,6 +373,18 @@ function configureRecallProtection(
|
||||
|
||||
const packagedIconPath = join(process.resourcesPath, 'resources', 'icon.png')
|
||||
const appIconPath = existsSync(packagedIconPath) ? packagedIconPath : icon
|
||||
const packagedTrayTemplateIconPath = join(process.resourcesPath, 'resources', 'trayTemplate.png')
|
||||
const packagedTrayTemplateRetinaIconPath = join(
|
||||
process.resourcesPath,
|
||||
'resources',
|
||||
'trayTemplate@2x.png'
|
||||
)
|
||||
const trayTemplateIconPath = existsSync(packagedTrayTemplateIconPath)
|
||||
? packagedTrayTemplateIconPath
|
||||
: trayTemplateIcon
|
||||
const trayTemplateRetinaIconPath = existsSync(packagedTrayTemplateRetinaIconPath)
|
||||
? packagedTrayTemplateRetinaIconPath
|
||||
: trayTemplateRetinaIcon
|
||||
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
{
|
||||
@@ -921,8 +936,6 @@ app.whenReady().then(async () => {
|
||||
// 设置应用程序用户模型 ID
|
||||
electronApp.setAppUserModelId('com.tracememo.app')
|
||||
|
||||
if (process.platform === 'darwin') app.dock?.setIcon(appIconPath)
|
||||
|
||||
// 开发环境中默认使用 F12 打开或关闭 DevTools
|
||||
// 生产环境中忽略 CommandOrControl + R
|
||||
// 参见 https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||
@@ -2875,11 +2888,12 @@ function buildTrayMenu(): Menu {
|
||||
function setupTray(): void {
|
||||
if (tray) return
|
||||
try {
|
||||
const image = nativeImage.createFromPath(appIconPath)
|
||||
const traySize = process.platform === 'darwin' ? 20 : 24
|
||||
const trayImage = image.isEmpty()
|
||||
? nativeImage.createEmpty()
|
||||
: image.resize({ width: traySize, height: traySize, quality: 'best' })
|
||||
const trayImage = createTrayImage(
|
||||
process.platform,
|
||||
appIconPath,
|
||||
{ oneX: trayTemplateIconPath, twoX: trayTemplateRetinaIconPath },
|
||||
nativeImage
|
||||
)
|
||||
tray = new Tray(trayImage)
|
||||
tray.setToolTip('TraceMemo')
|
||||
// macOS may show a Tray context menu on a primary click when it is set
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { readFileSync } from 'fs'
|
||||
|
||||
export interface TrayNativeImage {
|
||||
addRepresentation(options: { scaleFactor: number; dataURL: string }): void
|
||||
isEmpty(): boolean
|
||||
resize(options: { width: number; height: number; quality: 'best' }): TrayNativeImage
|
||||
setTemplateImage(option: boolean): void
|
||||
}
|
||||
|
||||
export interface TrayNativeImageFactory<T extends TrayNativeImage = TrayNativeImage> {
|
||||
createEmpty(): T
|
||||
createFromPath(path: string): T
|
||||
}
|
||||
|
||||
export interface TrayTemplateIconPaths {
|
||||
oneX: string
|
||||
twoX: string
|
||||
}
|
||||
|
||||
type ReadImageFile = (path: string) => Buffer
|
||||
|
||||
function toPngDataUrl(buffer: Buffer): string {
|
||||
return `data:image/png;base64,${buffer.toString('base64')}`
|
||||
}
|
||||
|
||||
export function createTrayImage<T extends TrayNativeImage>(
|
||||
platform: NodeJS.Platform,
|
||||
appIconPath: string,
|
||||
templateIconPaths: TrayTemplateIconPaths,
|
||||
nativeImage: TrayNativeImageFactory<T>,
|
||||
readImageFile: ReadImageFile = readFileSync
|
||||
): T {
|
||||
if (platform === 'darwin') {
|
||||
const image = nativeImage.createEmpty()
|
||||
image.addRepresentation({
|
||||
scaleFactor: 1,
|
||||
dataURL: toPngDataUrl(readImageFile(templateIconPaths.oneX))
|
||||
})
|
||||
image.addRepresentation({
|
||||
scaleFactor: 2,
|
||||
dataURL: toPngDataUrl(readImageFile(templateIconPaths.twoX))
|
||||
})
|
||||
image.setTemplateImage(true)
|
||||
return image
|
||||
}
|
||||
|
||||
const image = nativeImage.createFromPath(appIconPath)
|
||||
return image.isEmpty()
|
||||
? nativeImage.createEmpty()
|
||||
: (image.resize({ width: 24, height: 24, quality: 'best' }) as T)
|
||||
}
|
||||
@@ -26,11 +26,7 @@ export function AccountSummary({
|
||||
const displayName =
|
||||
showAccount && selfInfo ? selfInfo.nickname || selfInfo.wxid || '当前账号' : '未连接'
|
||||
const subtitle = showAccount && selfInfo ? selfInfo.wxid : '打开设置'
|
||||
const statusText = dbReady
|
||||
? '数据库已连接'
|
||||
: dbConnecting
|
||||
? '正在连接数据库'
|
||||
: '数据库未连接'
|
||||
const statusText = dbReady ? '数据库已连接' : dbConnecting ? '正在连接数据库' : '数据库未连接'
|
||||
const statusClass = dbReady ? 'ready' : dbConnecting ? 'connecting' : ''
|
||||
const initial = (displayName || '?').charAt(0)
|
||||
const title = `${displayName}\n${subtitle}`
|
||||
@@ -66,8 +62,8 @@ export function AccountSummary({
|
||||
</span>
|
||||
<button type="button" className="account-summary-settings" onClick={onClick} title="设置">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
||||
<path d="M12 8.5a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7Z" />
|
||||
<path d="M19.4 15a8.2 8.2 0 0 0 .1-1l2-1.5-2-3.5-2.4 1a7.5 7.5 0 0 0-1.7-1l-.3-2.5h-4l-.4 2.5a7.5 7.5 0 0 0-1.7 1l-2.3-1-2 3.5 2 1.5a8.2 8.2 0 0 0 0 2l-2 1.5 2 3.5 2.3-1a7.5 7.5 0 0 0 1.7 1l.4 2.5h4l.3-2.5a7.5 7.5 0 0 0 1.7-1l2.4 1 2-3.5-2.1-1.5Z" />
|
||||
<path d="M12.22 2h-.44a2 2 0 0 0-2 1.72l-.15 1.58a8 8 0 0 0-1.77 1.03l-1.48-.6a2 2 0 0 0-2.5.88l-.22.39a2 2 0 0 0 .51 2.68l1.25.98a8 8 0 0 0 0 2.08l-1.25.98a2 2 0 0 0-.51 2.68l.22.39a2 2 0 0 0 2.5.88l1.48-.6c.54.43 1.14.78 1.77 1.03l.15 1.58a2 2 0 0 0 2 1.72h.44a2 2 0 0 0 2-1.72l.15-1.58c.63-.25 1.23-.6 1.77-1.03l1.48.6a2 2 0 0 0 2.5-.88l.22-.39a2 2 0 0 0-.51-2.68l-1.25-.98a8 8 0 0 0 0-2.08l1.25-.98a2 2 0 0 0 .51-2.68l-.22-.39a2 2 0 0 0-2.5-.88l-1.48.6a8 8 0 0 0-1.77-1.03l-.15-1.58a2 2 0 0 0-2-1.72Z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -4,11 +4,36 @@ function DiagnosticIcon({ status }: { status: DiagnosticStatus }): React.ReactEl
|
||||
if (status === 'checking') {
|
||||
return <span className="settings-diagnostic-icon checking" aria-label="检测中" />
|
||||
}
|
||||
const symbol =
|
||||
status === 'success' ? '✓' : status === 'warning' ? '!' : status === 'error' ? '×' : '—'
|
||||
|
||||
const icon =
|
||||
status === 'success' ? (
|
||||
<path d="m5 12.5 4.5 4.5L19 7" />
|
||||
) : status === 'warning' ? (
|
||||
<>
|
||||
<path d="M12 6v7" />
|
||||
<circle cx="12" cy="17" r="1.5" fill="currentColor" stroke="none" />
|
||||
</>
|
||||
) : status === 'error' ? (
|
||||
<path d="m7 7 10 10M17 7 7 17" />
|
||||
) : (
|
||||
<path d="M6 12h12" />
|
||||
)
|
||||
|
||||
return (
|
||||
<span className={`settings-diagnostic-icon ${status}`} aria-hidden="true">
|
||||
{symbol}
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
width="12"
|
||||
height="12"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
focusable="false"
|
||||
>
|
||||
{icon}
|
||||
</svg>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -416,8 +416,9 @@
|
||||
border: 1px solid #929a96;
|
||||
border-radius: 50%;
|
||||
color: #929a96;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
}
|
||||
.settings-diagnostic-icon svg {
|
||||
display: block;
|
||||
}
|
||||
.settings-diagnostic-icon.success {
|
||||
border-color: #2e8b68;
|
||||
|
||||
Reference in new issue
Block a user