feat: авто-обновление приложения через Forgejo релизы
- Forgejo CI workflow: при пуше в master создаёт semver-тег (bump patch), собирает Linux AppImage и публикует релиз с артефактом - UpdaterService: проверяет API Forgejo, сравнивает semver, скачивает AppImage, заменяет текущий файл через APPIMAGE env и перезапускает приложение - IPC-каналы update:check / update:download / update:install - IPC-события update:available / progress / downloaded / not-available / error - UpdateBanner — фиксированный баннер (снизу экрана): кнопка «Скачать», прогресс-бар, кнопка «Установить и перезапустить» - Секция «Приложение» в настройках: текущая версия, ручная проверка - Автопроверка при старте упакованного приложения (через 10 с) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3c9c4344bc
commit
8917aba6d0
11 changed files with 677 additions and 0 deletions
98
.forgejo/workflows/release.yml
Normal file
98
.forgejo/workflows/release.yml
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
- '.forgejo/**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: docker
|
||||||
|
|
||||||
|
container:
|
||||||
|
image: node:20-bookworm
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout (full history for tags)
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Determine next version
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
LATEST=$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' --sort=-version:refname | head -1)
|
||||||
|
if [ -z "$LATEST" ]; then
|
||||||
|
# First release — use version from package.json
|
||||||
|
NEW=$(node -p "require('./package.json').version")
|
||||||
|
else
|
||||||
|
IFS='.' read -r maj min pat <<< "${LATEST#v}"
|
||||||
|
NEW="${maj}.${min}.$((pat + 1))"
|
||||||
|
fi
|
||||||
|
echo "version=$NEW" >> $GITHUB_OUTPUT
|
||||||
|
echo "tag=v$NEW" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Set version in package.json
|
||||||
|
run: npm version ${{ steps.version.outputs.version }} --no-git-tag-version --allow-same-version
|
||||||
|
|
||||||
|
- name: Build Linux AppImage
|
||||||
|
run: npm run build:linux
|
||||||
|
env:
|
||||||
|
# Подавляем попытку electron-builder публиковать на GitHub
|
||||||
|
GH_TOKEN: ""
|
||||||
|
|
||||||
|
- name: Find built AppImage
|
||||||
|
id: artifact
|
||||||
|
run: |
|
||||||
|
APPIMAGE=$(ls dist/*.AppImage | head -1)
|
||||||
|
echo "path=$APPIMAGE" >> $GITHUB_OUTPUT
|
||||||
|
echo "name=$(basename $APPIMAGE)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Create and push tag
|
||||||
|
env:
|
||||||
|
TAG: ${{ steps.version.outputs.tag }}
|
||||||
|
GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
git config user.email "ci@vodyanoysh.ru"
|
||||||
|
git config user.name "Forgejo CI"
|
||||||
|
git remote set-url origin "https://x-token:${GIT_TOKEN}@git.vodyanoysh.ru/vodyanoy/aero-mail.git"
|
||||||
|
git tag "$TAG"
|
||||||
|
git push origin "$TAG"
|
||||||
|
|
||||||
|
- name: Create Forgejo release
|
||||||
|
id: release
|
||||||
|
env:
|
||||||
|
TAG: ${{ steps.version.outputs.tag }}
|
||||||
|
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
BODY=$(cat <<'NOTES'
|
||||||
|
Автоматический релиз.
|
||||||
|
NOTES
|
||||||
|
)
|
||||||
|
|
||||||
|
RELEASE=$(curl -sf -X POST \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"Aero Mail ${TAG}\",\"body\":\"${BODY}\",\"draft\":false,\"prerelease\":false}" \
|
||||||
|
"https://git.vodyanoysh.ru/api/v1/repos/vodyanoy/aero-mail/releases")
|
||||||
|
|
||||||
|
echo "id=$(echo "$RELEASE" | python3 -c 'import sys,json; print(json.load(sys.stdin)["id"])')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Upload AppImage to release
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
RELEASE_ID: ${{ steps.release.outputs.id }}
|
||||||
|
ASSET_PATH: ${{ steps.artifact.outputs.path }}
|
||||||
|
ASSET_NAME: ${{ steps.artifact.outputs.name }}
|
||||||
|
run: |
|
||||||
|
curl -sf -X POST \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
--data-binary @"${ASSET_PATH}" \
|
||||||
|
"https://git.vodyanoysh.ru/api/v1/repos/vodyanoy/aero-mail/releases/${RELEASE_ID}/assets?name=${ASSET_NAME}"
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
|
import { readFileSync } from 'fs'
|
||||||
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
|
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import { config as dotenv } from 'dotenv'
|
import { config as dotenv } from 'dotenv'
|
||||||
|
|
||||||
dotenv()
|
dotenv()
|
||||||
|
|
||||||
|
const pkg = JSON.parse(readFileSync('package.json', 'utf-8')) as { version: string }
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
main: {
|
main: {
|
||||||
plugins: [externalizeDepsPlugin()],
|
plugins: [externalizeDepsPlugin()],
|
||||||
|
|
@ -29,6 +32,9 @@ export default defineConfig({
|
||||||
},
|
},
|
||||||
renderer: {
|
renderer: {
|
||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
|
define: {
|
||||||
|
__APP_VERSION__: JSON.stringify(pkg.version)
|
||||||
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@shared': resolve('src/shared'),
|
'@shared': resolve('src/shared'),
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import { registerAccountHandlers } from './ipc/accounts.handler'
|
||||||
import { registerFolderHandlers } from './ipc/folders.handler'
|
import { registerFolderHandlers } from './ipc/folders.handler'
|
||||||
import { registerMessageHandlers } from './ipc/messages.handler'
|
import { registerMessageHandlers } from './ipc/messages.handler'
|
||||||
import { registerCalendarHandlers } from './ipc/calendar.handler'
|
import { registerCalendarHandlers } from './ipc/calendar.handler'
|
||||||
|
import { registerUpdaterHandlers } from './ipc/updater.handler'
|
||||||
|
import { updater } from './services/updater'
|
||||||
import type { ComposeSession } from '@shared/types/message'
|
import type { ComposeSession } from '@shared/types/message'
|
||||||
|
|
||||||
const accountManager = new AccountManager()
|
const accountManager = new AccountManager()
|
||||||
|
|
@ -148,9 +150,14 @@ app.whenReady().then(async () => {
|
||||||
registerFolderHandlers(accountManager)
|
registerFolderHandlers(accountManager)
|
||||||
registerMessageHandlers(accountManager)
|
registerMessageHandlers(accountManager)
|
||||||
registerCalendarHandlers(accountManager)
|
registerCalendarHandlers(accountManager)
|
||||||
|
registerUpdaterHandlers()
|
||||||
|
|
||||||
createWindow()
|
createWindow()
|
||||||
|
|
||||||
|
if (app.isPackaged) {
|
||||||
|
setTimeout(() => updater.checkForUpdates(), 10_000)
|
||||||
|
}
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
if (BrowserWindow.getAllWindows().length === 0) {
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
createWindow()
|
createWindow()
|
||||||
|
|
|
||||||
14
src/main/ipc/updater.handler.ts
Normal file
14
src/main/ipc/updater.handler.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { registerHandler } from './registry'
|
||||||
|
import { updater } from '../services/updater'
|
||||||
|
|
||||||
|
export function registerUpdaterHandlers(): void {
|
||||||
|
registerHandler('update:check', () => updater.checkForUpdates())
|
||||||
|
|
||||||
|
registerHandler('update:download', async () => {
|
||||||
|
updater.downloadUpdate()
|
||||||
|
})
|
||||||
|
|
||||||
|
registerHandler('update:install', async () => {
|
||||||
|
updater.installUpdate()
|
||||||
|
})
|
||||||
|
}
|
||||||
163
src/main/services/updater.ts
Normal file
163
src/main/services/updater.ts
Normal file
|
|
@ -0,0 +1,163 @@
|
||||||
|
import { app, BrowserWindow } from 'electron'
|
||||||
|
import { createWriteStream, chmodSync, copyFileSync, mkdirSync } from 'fs'
|
||||||
|
import { join } from 'path'
|
||||||
|
import { homedir } from 'os'
|
||||||
|
import https from 'https'
|
||||||
|
import http from 'http'
|
||||||
|
import { URL } from 'url'
|
||||||
|
|
||||||
|
const REPO_API = 'https://git.vodyanoysh.ru/api/v1/repos/vodyanoy/aero-mail/releases/latest'
|
||||||
|
|
||||||
|
interface ReleaseAsset {
|
||||||
|
name: string
|
||||||
|
browser_download_url: string
|
||||||
|
size: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Release {
|
||||||
|
tag_name: string
|
||||||
|
name: string
|
||||||
|
body: string
|
||||||
|
assets: ReleaseAsset[]
|
||||||
|
}
|
||||||
|
|
||||||
|
function compareSemver(a: string, b: string): number {
|
||||||
|
const parse = (v: string): number[] => v.replace(/^v/, '').split('.').map(Number)
|
||||||
|
const [aMaj, aMin, aPat] = parse(a)
|
||||||
|
const [bMaj, bMin, bPat] = parse(b)
|
||||||
|
if (aMaj !== bMaj) return aMaj - bMaj
|
||||||
|
if (aMin !== bMin) return aMin - bMin
|
||||||
|
return aPat - bPat
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchJson<T>(url: string): Promise<T> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const parsed = new URL(url)
|
||||||
|
https.get(
|
||||||
|
{ hostname: parsed.hostname, path: parsed.pathname + parsed.search, headers: { 'User-Agent': `AeroMail/${app.getVersion()}` } },
|
||||||
|
(res) => {
|
||||||
|
if (res.statusCode !== 200) {
|
||||||
|
reject(new Error(`HTTP ${res.statusCode}`))
|
||||||
|
res.resume()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let data = ''
|
||||||
|
res.on('data', (chunk: string) => { data += chunk })
|
||||||
|
res.on('end', () => {
|
||||||
|
try { resolve(JSON.parse(data) as T) } catch (e) { reject(e) }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
).on('error', reject)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadFile(
|
||||||
|
url: string,
|
||||||
|
destPath: string,
|
||||||
|
totalSize: number,
|
||||||
|
onProgress: (percent: number, transferred: number, total: number) => void
|
||||||
|
): Promise<void> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const follow = (currentUrl: string): void => {
|
||||||
|
const parsed = new URL(currentUrl)
|
||||||
|
const proto = parsed.protocol === 'https:' ? https : http
|
||||||
|
proto.get(currentUrl, { headers: { 'User-Agent': `AeroMail/${app.getVersion()}` } }, (res) => {
|
||||||
|
if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) {
|
||||||
|
follow(res.headers.location!)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (res.statusCode !== 200) {
|
||||||
|
reject(new Error(`Download failed: HTTP ${res.statusCode}`))
|
||||||
|
res.resume()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const file = createWriteStream(destPath)
|
||||||
|
let transferred = 0
|
||||||
|
res.on('data', (chunk: Buffer) => {
|
||||||
|
transferred += chunk.length
|
||||||
|
const percent = totalSize > 0 ? Math.round((transferred / totalSize) * 100) : 0
|
||||||
|
onProgress(percent, transferred, totalSize)
|
||||||
|
})
|
||||||
|
res.pipe(file)
|
||||||
|
file.on('finish', () => file.close(() => resolve()))
|
||||||
|
file.on('error', (e) => { reject(e) })
|
||||||
|
res.on('error', (e) => { reject(e) })
|
||||||
|
}).on('error', reject)
|
||||||
|
}
|
||||||
|
follow(url)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export class UpdaterService {
|
||||||
|
private downloadedPath: string | null = null
|
||||||
|
|
||||||
|
private send(channel: string, data: unknown): void {
|
||||||
|
const win = BrowserWindow.getAllWindows()[0]
|
||||||
|
win?.webContents.send(channel, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkForUpdates(): Promise<{ hasUpdate: boolean; version?: string; notes?: string }> {
|
||||||
|
try {
|
||||||
|
const release = await fetchJson<Release>(REPO_API)
|
||||||
|
const currentVersion = app.getVersion()
|
||||||
|
|
||||||
|
if (compareSemver(release.tag_name, currentVersion) > 0) {
|
||||||
|
const version = release.tag_name.replace(/^v/, '')
|
||||||
|
const notes = release.body ?? ''
|
||||||
|
this.send('update:available', { version, notes })
|
||||||
|
return { hasUpdate: true, version, notes }
|
||||||
|
}
|
||||||
|
|
||||||
|
this.send('update:not-available', {})
|
||||||
|
return { hasUpdate: false }
|
||||||
|
} catch (e) {
|
||||||
|
const error = (e as Error).message
|
||||||
|
this.send('update:error', { error })
|
||||||
|
return { hasUpdate: false }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async downloadUpdate(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const release = await fetchJson<Release>(REPO_API)
|
||||||
|
const asset = release.assets.find((a) => a.name.endsWith('.AppImage'))
|
||||||
|
if (!asset) throw new Error('No AppImage asset in release')
|
||||||
|
|
||||||
|
const destDir = join(homedir(), '.cache', 'aero-mail', 'updates')
|
||||||
|
mkdirSync(destDir, { recursive: true })
|
||||||
|
const destPath = join(destDir, asset.name)
|
||||||
|
|
||||||
|
await downloadFile(asset.browser_download_url, destPath, asset.size, (percent, transferred, total) => {
|
||||||
|
this.send('update:progress', { percent, transferred, total })
|
||||||
|
})
|
||||||
|
|
||||||
|
chmodSync(destPath, 0o755)
|
||||||
|
this.downloadedPath = destPath
|
||||||
|
this.send('update:downloaded', {})
|
||||||
|
} catch (e) {
|
||||||
|
const error = (e as Error).message
|
||||||
|
this.send('update:error', { error })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
installUpdate(): void {
|
||||||
|
if (!this.downloadedPath) return
|
||||||
|
|
||||||
|
const appImagePath = process.env['APPIMAGE']
|
||||||
|
if (appImagePath) {
|
||||||
|
try {
|
||||||
|
copyFileSync(this.downloadedPath, appImagePath)
|
||||||
|
chmodSync(appImagePath, 0o755)
|
||||||
|
app.relaunch()
|
||||||
|
} catch {
|
||||||
|
app.relaunch({ execPath: this.downloadedPath })
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
app.relaunch({ execPath: this.downloadedPath })
|
||||||
|
}
|
||||||
|
|
||||||
|
app.exit(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updater = new UpdaterService()
|
||||||
|
|
@ -3,6 +3,7 @@ import { onMounted, onUnmounted, watch } from 'vue'
|
||||||
import { useAccountsStore } from './stores/accounts.store'
|
import { useAccountsStore } from './stores/accounts.store'
|
||||||
import { useSettingsStore } from './stores/settings.store'
|
import { useSettingsStore } from './stores/settings.store'
|
||||||
import { useIpc } from './composables/useIpc'
|
import { useIpc } from './composables/useIpc'
|
||||||
|
import UpdateBanner from './components/UpdateBanner.vue'
|
||||||
|
|
||||||
const accountsStore = useAccountsStore()
|
const accountsStore = useAccountsStore()
|
||||||
const settingsStore = useSettingsStore()
|
const settingsStore = useSettingsStore()
|
||||||
|
|
@ -38,4 +39,5 @@ onUnmounted(() => { if (pollTimer) clearInterval(pollTimer) })
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<router-view />
|
<router-view />
|
||||||
|
<UpdateBanner />
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
178
src/renderer/src/components/UpdateBanner.vue
Normal file
178
src/renderer/src/components/UpdateBanner.vue
Normal file
|
|
@ -0,0 +1,178 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useUpdaterStore } from '../stores/updater.store'
|
||||||
|
|
||||||
|
const updater = useUpdaterStore()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Transition name="banner">
|
||||||
|
<div
|
||||||
|
v-if="updater.available && !updater.dismissed"
|
||||||
|
class="update-banner"
|
||||||
|
>
|
||||||
|
<div class="banner-body">
|
||||||
|
<div class="banner-icon">↑</div>
|
||||||
|
<div class="banner-text">
|
||||||
|
<span class="banner-title">Доступна версия {{ updater.version }}</span>
|
||||||
|
<span v-if="updater.downloading" class="banner-sub">
|
||||||
|
Загрузка… {{ updater.percent }}%
|
||||||
|
</span>
|
||||||
|
<span v-else-if="updater.downloaded" class="banner-sub">Готово к установке</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="banner-progress-wrap" v-if="updater.downloading">
|
||||||
|
<div class="banner-progress-bar" :style="{ width: updater.percent + '%' }" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="banner-actions">
|
||||||
|
<button
|
||||||
|
v-if="!updater.downloading && !updater.downloaded"
|
||||||
|
class="btn-primary"
|
||||||
|
@click="updater.download()"
|
||||||
|
>Скачать</button>
|
||||||
|
<button
|
||||||
|
v-if="updater.downloaded"
|
||||||
|
class="btn-primary"
|
||||||
|
@click="updater.install()"
|
||||||
|
>Установить и перезапустить</button>
|
||||||
|
<button
|
||||||
|
v-if="!updater.downloading"
|
||||||
|
class="btn-dismiss"
|
||||||
|
@click="updater.dismiss()"
|
||||||
|
>✕</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Transition>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.update-banner {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 24px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
z-index: 9000;
|
||||||
|
min-width: 340px;
|
||||||
|
max-width: 480px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-body {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 10px 14px;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: color-mix(in srgb, var(--accent) 12%, rgba(12, 12, 20, 0.92));
|
||||||
|
border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
|
||||||
|
box-shadow:
|
||||||
|
0 8px 32px rgba(0, 0, 0, 0.5),
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.12);
|
||||||
|
backdrop-filter: blur(24px);
|
||||||
|
-webkit-backdrop-filter: blur(24px);
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-icon {
|
||||||
|
font-size: 16px;
|
||||||
|
color: var(--accent);
|
||||||
|
font-weight: 700;
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 24px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-text {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-title {
|
||||||
|
font-size: 12.5px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-sub {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-progress-wrap {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 2px;
|
||||||
|
background: rgba(255, 255, 255, 0.08);
|
||||||
|
border-radius: 0 0 12px 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-progress-bar {
|
||||||
|
height: 100%;
|
||||||
|
background: var(--accent);
|
||||||
|
transition: width 0.3s ease;
|
||||||
|
border-radius: 0 0 12px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
align-items: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
font-size: 11.5px;
|
||||||
|
font-weight: 600;
|
||||||
|
padding: 4px 12px;
|
||||||
|
border-radius: var(--radius-full);
|
||||||
|
background: var(--accent);
|
||||||
|
color: var(--accent-text);
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: opacity var(--transition-fast), transform var(--transition-fast);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
opacity: 0.88;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:active {
|
||||||
|
transform: translateY(1px);
|
||||||
|
opacity: 0.75;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-dismiss {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: color var(--transition-fast), background var(--transition-fast);
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-dismiss:hover {
|
||||||
|
color: var(--text-secondary);
|
||||||
|
background: rgba(255, 255, 255, 0.07);
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-enter-active,
|
||||||
|
.banner-leave-active {
|
||||||
|
transition: opacity 0.25s ease, transform 0.25s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-enter-from,
|
||||||
|
.banner-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(-50%) translateY(12px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
2
src/renderer/src/env.d.ts
vendored
2
src/renderer/src/env.d.ts
vendored
|
|
@ -1,5 +1,7 @@
|
||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
|
declare const __APP_VERSION__: string
|
||||||
|
|
||||||
declare module '*.vue' {
|
declare module '*.vue' {
|
||||||
import type { DefineComponent } from 'vue'
|
import type { DefineComponent } from 'vue'
|
||||||
const component: DefineComponent<object, object, unknown>
|
const component: DefineComponent<object, object, unknown>
|
||||||
|
|
|
||||||
71
src/renderer/src/stores/updater.store.ts
Normal file
71
src/renderer/src/stores/updater.store.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { useIpc } from '../composables/useIpc'
|
||||||
|
|
||||||
|
export const useUpdaterStore = defineStore('updater', () => {
|
||||||
|
const { invoke, on } = useIpc()
|
||||||
|
|
||||||
|
const available = ref(false)
|
||||||
|
const version = ref('')
|
||||||
|
const notes = ref('')
|
||||||
|
const checking = ref(false)
|
||||||
|
const downloading = ref(false)
|
||||||
|
const percent = ref(0)
|
||||||
|
const downloaded = ref(false)
|
||||||
|
const dismissed = ref(false)
|
||||||
|
const error = ref('')
|
||||||
|
|
||||||
|
on('update:available', (data) => {
|
||||||
|
available.value = true
|
||||||
|
version.value = data.version
|
||||||
|
notes.value = data.notes
|
||||||
|
dismissed.value = false
|
||||||
|
})
|
||||||
|
|
||||||
|
on('update:progress', (data) => {
|
||||||
|
downloading.value = true
|
||||||
|
percent.value = data.percent
|
||||||
|
})
|
||||||
|
|
||||||
|
on('update:downloaded', () => {
|
||||||
|
downloading.value = false
|
||||||
|
downloaded.value = true
|
||||||
|
percent.value = 100
|
||||||
|
})
|
||||||
|
|
||||||
|
on('update:error', (data) => {
|
||||||
|
downloading.value = false
|
||||||
|
checking.value = false
|
||||||
|
error.value = data.error
|
||||||
|
})
|
||||||
|
|
||||||
|
on('update:not-available', () => {
|
||||||
|
checking.value = false
|
||||||
|
})
|
||||||
|
|
||||||
|
async function check(): Promise<void> {
|
||||||
|
checking.value = true
|
||||||
|
error.value = ''
|
||||||
|
try {
|
||||||
|
await invoke('update:check')
|
||||||
|
} finally {
|
||||||
|
checking.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function download(): void {
|
||||||
|
downloading.value = true
|
||||||
|
percent.value = 0
|
||||||
|
invoke('update:download')
|
||||||
|
}
|
||||||
|
|
||||||
|
function install(): void {
|
||||||
|
invoke('update:install')
|
||||||
|
}
|
||||||
|
|
||||||
|
function dismiss(): void {
|
||||||
|
dismissed.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return { available, version, notes, checking, downloading, percent, downloaded, dismissed, error, check, download, install, dismiss }
|
||||||
|
})
|
||||||
|
|
@ -7,6 +7,7 @@ import CustomSelect from '../components/CustomSelect.vue'
|
||||||
import ColorPicker from '../components/ColorPicker.vue'
|
import ColorPicker from '../components/ColorPicker.vue'
|
||||||
import AppIcon from '../components/AppIcon.vue'
|
import AppIcon from '../components/AppIcon.vue'
|
||||||
import EditAccountDialog from '../components/accounts/EditAccountDialog.vue'
|
import EditAccountDialog from '../components/accounts/EditAccountDialog.vue'
|
||||||
|
import { useUpdaterStore } from '../stores/updater.store'
|
||||||
import type { AccountConfig } from '@shared/types/account'
|
import type { AccountConfig } from '@shared/types/account'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
@ -14,6 +15,7 @@ const accountsStore = useAccountsStore()
|
||||||
const settingsStore = useSettingsStore()
|
const settingsStore = useSettingsStore()
|
||||||
|
|
||||||
const editingAccount = ref<AccountConfig | null>(null)
|
const editingAccount = ref<AccountConfig | null>(null)
|
||||||
|
const updaterStore = useUpdaterStore()
|
||||||
|
|
||||||
const swipeOptions: { value: SwipeAction; label: string }[] = (
|
const swipeOptions: { value: SwipeAction; label: string }[] = (
|
||||||
['delete', 'toggleRead', 'toggleFlag', 'none'] as SwipeAction[]
|
['delete', 'toggleRead', 'toggleFlag', 'none'] as SwipeAction[]
|
||||||
|
|
@ -186,6 +188,58 @@ function folderDisplayName(path: string): string {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Обновления -->
|
||||||
|
<div class="section">
|
||||||
|
<div class="section-label">Приложение</div>
|
||||||
|
<div class="section-body">
|
||||||
|
<div class="row">
|
||||||
|
<span class="col-label">Версия</span>
|
||||||
|
<div class="col-value update-row-content">
|
||||||
|
<span class="version-badge">v{{ __APP_VERSION__ }}</span>
|
||||||
|
<span v-if="updaterStore.available" class="update-available-dot" v-tooltip="'Доступно обновление'">●</span>
|
||||||
|
<div class="row-actions">
|
||||||
|
<button
|
||||||
|
class="action-btn"
|
||||||
|
:disabled="updaterStore.checking"
|
||||||
|
@click="updaterStore.check()"
|
||||||
|
>{{ updaterStore.checking ? 'Проверка…' : 'Проверить обновления' }}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="updaterStore.error" class="row error-row">
|
||||||
|
<span class="col-label"></span>
|
||||||
|
<span class="col-value update-error">{{ updaterStore.error }}</span>
|
||||||
|
</div>
|
||||||
|
<div v-if="updaterStore.available && !updaterStore.downloaded && !updaterStore.downloading" class="row">
|
||||||
|
<span class="col-label"></span>
|
||||||
|
<div class="col-value">
|
||||||
|
<span class="update-note">Доступна версия {{ updaterStore.version }}</span>
|
||||||
|
<div class="row-actions">
|
||||||
|
<button class="action-btn" @click="updaterStore.download()">Скачать</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="updaterStore.downloading" class="row">
|
||||||
|
<span class="col-label"></span>
|
||||||
|
<div class="col-value update-progress-row">
|
||||||
|
<div class="update-progress-track">
|
||||||
|
<div class="update-progress-fill" :style="{ width: updaterStore.percent + '%' }" />
|
||||||
|
</div>
|
||||||
|
<span class="update-pct">{{ updaterStore.percent }}%</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="updaterStore.downloaded" class="row">
|
||||||
|
<span class="col-label"></span>
|
||||||
|
<div class="col-value">
|
||||||
|
<span class="update-note">Обновление загружено</span>
|
||||||
|
<div class="row-actions">
|
||||||
|
<button class="action-btn" @click="updaterStore.install()">Установить и перезапустить</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -614,4 +668,77 @@ function folderDisplayName(path: string): string {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── Обновления ──────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
.update-row-content {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-badge {
|
||||||
|
font-size: 11.5px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-available-dot {
|
||||||
|
color: var(--accent);
|
||||||
|
font-size: 10px;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-note {
|
||||||
|
font-size: 11.5px;
|
||||||
|
color: var(--accent);
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-error {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--danger);
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-row {
|
||||||
|
background: rgba(255, 85, 85, 0.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-progress-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-progress-track {
|
||||||
|
flex: 1;
|
||||||
|
height: 3px;
|
||||||
|
border-radius: var(--radius-full);
|
||||||
|
background: rgba(255, 255, 255, 0.10);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-progress-fill {
|
||||||
|
height: 100%;
|
||||||
|
background: var(--accent);
|
||||||
|
border-radius: var(--radius-full);
|
||||||
|
transition: width 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-pct {
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-muted);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
min-width: 30px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -59,12 +59,21 @@ export interface IpcChannelMap {
|
||||||
{ accountId: string },
|
{ accountId: string },
|
||||||
{ path: string; status: number; note: string }[]
|
{ path: string; status: number; note: string }[]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
'update:check': [void, { hasUpdate: boolean; version?: string; notes?: string }]
|
||||||
|
'update:download': [void, void]
|
||||||
|
'update:install': [void, void]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IpcEventMap {
|
export interface IpcEventMap {
|
||||||
'mail:new': { accountId: string; folderId: string; envelope: MessageEnvelope }
|
'mail:new': { accountId: string; folderId: string; envelope: MessageEnvelope }
|
||||||
'account:status': { accountId: string; connected: boolean; error?: string }
|
'account:status': { accountId: string; connected: boolean; error?: string }
|
||||||
'attachment:progress': { attachmentId: string; stage: 'downloading' | 'saving' | 'done' | 'error'; progress: number; error?: string }
|
'attachment:progress': { attachmentId: string; stage: 'downloading' | 'saving' | 'done' | 'error'; progress: number; error?: string }
|
||||||
|
'update:available': { version: string; notes: string }
|
||||||
|
'update:not-available': Record<string, never>
|
||||||
|
'update:progress': { percent: number; transferred: number; total: number }
|
||||||
|
'update:downloaded': Record<string, never>
|
||||||
|
'update:error': { error: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IpcChannel = keyof IpcChannelMap
|
export type IpcChannel = keyof IpcChannelMap
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue