mirror of
https://github.com/ILoveBingLu/CipherTalk.git
synced 2026-05-12 23:28:30 +08:00
fix: update mac packaging and icon handling
This commit is contained in:
+38
-20
@@ -171,6 +171,18 @@ function getAppIconPath(): string {
|
||||
const isDev = !!process.env.VITE_DEV_SERVER_URL
|
||||
const iconName = configService?.get('appIcon') || 'default'
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
if (iconName === 'xinnian') {
|
||||
return isDev
|
||||
? join(__dirname, '../public/xinnian.icns')
|
||||
: join(process.resourcesPath, 'icon.icns')
|
||||
}
|
||||
|
||||
return isDev
|
||||
? join(__dirname, '../public/icon.icns')
|
||||
: join(process.resourcesPath, 'icon.icns')
|
||||
}
|
||||
|
||||
if (iconName === 'xinnian') {
|
||||
return isDev
|
||||
? join(__dirname, '../public/xinnian.ico')
|
||||
@@ -958,10 +970,7 @@ function createImageViewerWindow(
|
||||
liveVideoPath?: string,
|
||||
options?: { sessionId?: string; imageMd5?: string; imageDatName?: string }
|
||||
) {
|
||||
const isDev = !!process.env.VITE_DEV_SERVER_URL
|
||||
const iconPath = isDev
|
||||
? join(__dirname, '../public/icon.ico')
|
||||
: join(process.resourcesPath, 'icon.ico')
|
||||
const iconPath = getAppIconPath()
|
||||
|
||||
const win = new BrowserWindow({
|
||||
width: 800,
|
||||
@@ -1026,10 +1035,7 @@ function createImageViewerWindow(
|
||||
* 窗口大小会根据视频比例自动调整
|
||||
*/
|
||||
function createVideoPlayerWindow(videoPath: string, videoWidth?: number, videoHeight?: number) {
|
||||
const isDev = !!process.env.VITE_DEV_SERVER_URL
|
||||
const iconPath = isDev
|
||||
? join(__dirname, '../public/icon.ico')
|
||||
: join(process.resourcesPath, 'icon.ico')
|
||||
const iconPath = getAppIconPath()
|
||||
|
||||
// 获取屏幕尺寸
|
||||
const { screen } = require('electron')
|
||||
@@ -1130,10 +1136,7 @@ function createVideoPlayerWindow(videoPath: string, videoWidth?: number, videoHe
|
||||
* 创建内置浏览器窗口
|
||||
*/
|
||||
function createBrowserWindow(url: string, title?: string) {
|
||||
const isDev = !!process.env.VITE_DEV_SERVER_URL
|
||||
const iconPath = isDev
|
||||
? join(__dirname, '../public/icon.ico')
|
||||
: join(process.resourcesPath, 'icon.ico')
|
||||
const iconPath = getAppIconPath()
|
||||
|
||||
const win = new BrowserWindow({
|
||||
width: 1200,
|
||||
@@ -1203,10 +1206,7 @@ function createAISummaryWindow(sessionId: string, sessionName: string) {
|
||||
aiSummaryWindow = null
|
||||
}
|
||||
|
||||
const isDev = !!process.env.VITE_DEV_SERVER_URL
|
||||
const iconPath = isDev
|
||||
? join(__dirname, '../public/icon.ico')
|
||||
: join(process.resourcesPath, 'icon.ico')
|
||||
const iconPath = getAppIconPath()
|
||||
|
||||
const isDark = nativeTheme.shouldUseDarkColors
|
||||
|
||||
@@ -2490,6 +2490,27 @@ function registerIpcHandlers() {
|
||||
return result
|
||||
})
|
||||
|
||||
ipcMain.handle('chat:getMessagesAfter', async (
|
||||
_,
|
||||
sessionId: string,
|
||||
cursorSortSeq: number,
|
||||
limit?: number,
|
||||
cursorCreateTime?: number,
|
||||
cursorLocalId?: number
|
||||
) => {
|
||||
const result = await chatService.getMessagesAfter(sessionId, cursorSortSeq, limit, cursorCreateTime, cursorLocalId)
|
||||
if (!result.success) {
|
||||
logService?.warn('Chat', '按游标获取更新消息失败', {
|
||||
sessionId,
|
||||
cursorSortSeq,
|
||||
cursorCreateTime,
|
||||
cursorLocalId,
|
||||
error: result.error
|
||||
})
|
||||
}
|
||||
return result
|
||||
})
|
||||
|
||||
ipcMain.handle('chat:getAllVoiceMessages', async (_, sessionId: string) => {
|
||||
const result = await chatService.getAllVoiceMessages(sessionId)
|
||||
|
||||
@@ -3917,10 +3938,7 @@ let startupDbConnected = false
|
||||
* 创建启动屏窗口
|
||||
*/
|
||||
function createSplashWindow(): BrowserWindow {
|
||||
const isDev = !!process.env.VITE_DEV_SERVER_URL
|
||||
const iconPath = isDev
|
||||
? join(__dirname, '../public/icon.ico')
|
||||
: join(process.resourcesPath, 'icon.ico')
|
||||
const iconPath = getAppIconPath()
|
||||
|
||||
const splash = new BrowserWindow({
|
||||
width: 420,
|
||||
|
||||
@@ -305,6 +305,14 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||
cursorLocalId?: number
|
||||
) =>
|
||||
ipcRenderer.invoke('chat:getMessagesBefore', sessionId, cursorSortSeq, limit, cursorCreateTime, cursorLocalId),
|
||||
getMessagesAfter: (
|
||||
sessionId: string,
|
||||
cursorSortSeq: number,
|
||||
limit?: number,
|
||||
cursorCreateTime?: number,
|
||||
cursorLocalId?: number
|
||||
) =>
|
||||
ipcRenderer.invoke('chat:getMessagesAfter', sessionId, cursorSortSeq, limit, cursorCreateTime, cursorLocalId),
|
||||
getAllVoiceMessages: (sessionId: string) =>
|
||||
ipcRenderer.invoke('chat:getAllVoiceMessages', sessionId),
|
||||
getAllImageMessages: (sessionId: string) =>
|
||||
|
||||
+7
-1
@@ -8,8 +8,12 @@
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"icon:mac": "bash scripts/build-macos-icon.sh",
|
||||
"build:prepare:mac": "node scripts/patch-dmg-builder.cjs",
|
||||
"build:prepare": "node scripts/update-readme-version.js && node scripts/prepare-release-announcement.js",
|
||||
"prebuild": "node scripts/update-readme-version.js && node scripts/prepare-release-announcement.js",
|
||||
"build": "tsc && vite build && electron-builder && node scripts/add-size-to-yml.js",
|
||||
"build:win": "npm run build:prepare && tsc && vite build && CSC_IDENTITY_AUTO_DISCOVERY=false node scripts/run-electron-builder.cjs win && node scripts/add-size-to-yml.js",
|
||||
"build:mac": "npm run build:prepare && npm run build:prepare:mac && tsc && vite build && CSC_IDENTITY_AUTO_DISCOVERY=false node scripts/run-electron-builder.cjs mac && node scripts/add-size-to-yml.js",
|
||||
"build:ci": "node scripts/prepare-release-announcement.js && tsc && vite build && electron-builder --publish never && node scripts/add-size-to-yml.js",
|
||||
"build:mcp": "tsc && vite build",
|
||||
"build:force-update-manifest": "node scripts/generate-force-update-manifest.js",
|
||||
@@ -94,7 +98,8 @@
|
||||
"publish": {
|
||||
"provider": "github",
|
||||
"owner": "ILoveBingLu",
|
||||
"repo": "CipherTalk"
|
||||
"repo": "CipherTalk",
|
||||
"publishAutoUpdate": false
|
||||
},
|
||||
"win": {
|
||||
"icon": "public/icon.ico",
|
||||
@@ -103,6 +108,7 @@
|
||||
},
|
||||
"mac": {
|
||||
"icon": "public/icon.icns",
|
||||
"target": "dmg",
|
||||
"category": "public.app-category.utilities",
|
||||
"hardenedRuntime": true,
|
||||
"gatekeeperAssess": false,
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
const pkg = require('../package.json')
|
||||
|
||||
const target = process.env.CIPHERTALK_BUILD_TARGET
|
||||
const base = pkg.build || {}
|
||||
|
||||
function getExtraResources(buildTarget) {
|
||||
const common = [
|
||||
{
|
||||
from: 'electron/assets/',
|
||||
to: 'assets/',
|
||||
filter: ['**/*']
|
||||
},
|
||||
{
|
||||
from: '.tmp/release-announcement.json',
|
||||
to: 'release-announcement.json'
|
||||
}
|
||||
]
|
||||
|
||||
if (buildTarget === 'mac') {
|
||||
return [
|
||||
{
|
||||
from: 'resources/macos/',
|
||||
to: 'resources/macos/',
|
||||
filter: ['**/*']
|
||||
},
|
||||
...common
|
||||
]
|
||||
}
|
||||
|
||||
if (buildTarget === 'win') {
|
||||
return [
|
||||
{
|
||||
from: 'resources/',
|
||||
to: 'resources/',
|
||||
filter: ['*.dll']
|
||||
},
|
||||
...common,
|
||||
{
|
||||
from: 'public/icon.ico',
|
||||
to: 'icon.ico'
|
||||
},
|
||||
{
|
||||
from: 'public/xinnian.ico',
|
||||
to: 'xinnian.ico'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
return base.extraResources || []
|
||||
}
|
||||
|
||||
function getExtraFiles(buildTarget) {
|
||||
if (buildTarget === 'win') {
|
||||
return base.extraFiles || []
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
...base,
|
||||
extraResources: getExtraResources(target),
|
||||
extraFiles: getExtraFiles(target)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const targetFile = path.join(__dirname, '..', 'node_modules', 'dmg-builder', 'out', 'dmg.js')
|
||||
|
||||
if (!fs.existsSync(targetFile)) {
|
||||
console.warn(`[patch-dmg-builder] skip, file not found: ${targetFile}`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const source = fs.readFileSync(targetFile, 'utf8')
|
||||
const oldSnippet = ` const expandingFinalSize = finalSize * 0.1 + finalSize;
|
||||
await (0, hdiuil_1.hdiUtil)(["resize", "-size", expandingFinalSize.toString(), tempDmg]);`
|
||||
const newSnippet = ` const expandingFinalSize = Math.ceil(finalSize * 0.1 + finalSize);
|
||||
await (0, hdiuil_1.hdiUtil)(["resize", "-size", expandingFinalSize.toString(), tempDmg]);`
|
||||
|
||||
if (source.includes(newSnippet)) {
|
||||
console.log('[patch-dmg-builder] already patched')
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
if (!source.includes(oldSnippet)) {
|
||||
console.warn('[patch-dmg-builder] target snippet not found, skip')
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
fs.writeFileSync(targetFile, source.replace(oldSnippet, newSnippet))
|
||||
console.log('[patch-dmg-builder] patched dmg-builder resize rounding')
|
||||
@@ -0,0 +1,28 @@
|
||||
const { spawnSync } = require('child_process')
|
||||
const path = require('path')
|
||||
|
||||
const target = process.argv[2]
|
||||
|
||||
if (!target || !['win', 'mac'].includes(target)) {
|
||||
console.error('Usage: node scripts/run-electron-builder.cjs <win|mac>')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const cliPath = require.resolve('electron-builder/cli.js')
|
||||
const configPath = path.join(__dirname, 'electron-builder.config.cjs')
|
||||
|
||||
const result = spawnSync(
|
||||
process.execPath,
|
||||
[cliPath, `--${target}`, '--config', configPath],
|
||||
{
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
...process.env,
|
||||
CIPHERTALK_BUILD_TARGET: target
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if (result.status !== 0) {
|
||||
process.exit(result.status || 1)
|
||||
}
|
||||
@@ -735,7 +735,7 @@ function ChatPage(_props: ChatPageProps) {
|
||||
const existingKeys = new Set(
|
||||
messagesRef.current.map(m => `${m.serverId}-${m.localId}-${m.createTime}-${m.sortSeq}`)
|
||||
)
|
||||
const uniqueNewerMessages = result.messages.filter(msg =>
|
||||
const uniqueNewerMessages = result.messages.filter((msg: Message) =>
|
||||
!existingKeys.has(`${msg.serverId}-${msg.localId}-${msg.createTime}-${msg.sortSeq}`)
|
||||
)
|
||||
|
||||
|
||||
Vendored
+12
@@ -468,6 +468,18 @@ export interface ElectronAPI {
|
||||
hasMore?: boolean;
|
||||
error?: string
|
||||
}>
|
||||
getMessagesAfter: (
|
||||
sessionId: string,
|
||||
cursorSortSeq: number,
|
||||
limit?: number,
|
||||
cursorCreateTime?: number,
|
||||
cursorLocalId?: number
|
||||
) => Promise<{
|
||||
success: boolean;
|
||||
messages?: Message[];
|
||||
hasMore?: boolean;
|
||||
error?: string
|
||||
}>
|
||||
getAllVoiceMessages: (sessionId: string) => Promise<{
|
||||
success: boolean;
|
||||
messages?: Message[];
|
||||
|
||||
Reference in New Issue
Block a user