diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml new file mode 100644 index 0000000..ffc0048 --- /dev/null +++ b/.forgejo/workflows/release.yml @@ -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}" diff --git a/electron.vite.config.ts b/electron.vite.config.ts index ecb6e72..2732bfe 100644 --- a/electron.vite.config.ts +++ b/electron.vite.config.ts @@ -1,10 +1,13 @@ import { resolve } from 'path' +import { readFileSync } from 'fs' import { defineConfig, externalizeDepsPlugin } from 'electron-vite' import vue from '@vitejs/plugin-vue' import { config as dotenv } from 'dotenv' dotenv() +const pkg = JSON.parse(readFileSync('package.json', 'utf-8')) as { version: string } + export default defineConfig({ main: { plugins: [externalizeDepsPlugin()], @@ -29,6 +32,9 @@ export default defineConfig({ }, renderer: { plugins: [vue()], + define: { + __APP_VERSION__: JSON.stringify(pkg.version) + }, resolve: { alias: { '@shared': resolve('src/shared'), diff --git a/src/main/index.ts b/src/main/index.ts index 779cdf1..d949636 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -6,6 +6,8 @@ import { registerAccountHandlers } from './ipc/accounts.handler' import { registerFolderHandlers } from './ipc/folders.handler' import { registerMessageHandlers } from './ipc/messages.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' const accountManager = new AccountManager() @@ -148,9 +150,14 @@ app.whenReady().then(async () => { registerFolderHandlers(accountManager) registerMessageHandlers(accountManager) registerCalendarHandlers(accountManager) + registerUpdaterHandlers() createWindow() + if (app.isPackaged) { + setTimeout(() => updater.checkForUpdates(), 10_000) + } + app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow() diff --git a/src/main/ipc/updater.handler.ts b/src/main/ipc/updater.handler.ts new file mode 100644 index 0000000..82e4d0b --- /dev/null +++ b/src/main/ipc/updater.handler.ts @@ -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() + }) +} diff --git a/src/main/services/updater.ts b/src/main/services/updater.ts new file mode 100644 index 0000000..9be8100 --- /dev/null +++ b/src/main/services/updater.ts @@ -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(url: string): Promise { + 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 { + 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(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 { + try { + const release = await fetchJson(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() diff --git a/src/renderer/src/App.vue b/src/renderer/src/App.vue index a251bee..c77d11a 100644 --- a/src/renderer/src/App.vue +++ b/src/renderer/src/App.vue @@ -3,6 +3,7 @@ import { onMounted, onUnmounted, watch } from 'vue' import { useAccountsStore } from './stores/accounts.store' import { useSettingsStore } from './stores/settings.store' import { useIpc } from './composables/useIpc' +import UpdateBanner from './components/UpdateBanner.vue' const accountsStore = useAccountsStore() const settingsStore = useSettingsStore() @@ -38,4 +39,5 @@ onUnmounted(() => { if (pollTimer) clearInterval(pollTimer) }) diff --git a/src/renderer/src/components/UpdateBanner.vue b/src/renderer/src/components/UpdateBanner.vue new file mode 100644 index 0000000..b2f88db --- /dev/null +++ b/src/renderer/src/components/UpdateBanner.vue @@ -0,0 +1,178 @@ + + + + + diff --git a/src/renderer/src/env.d.ts b/src/renderer/src/env.d.ts index 65c7311..f7c34c7 100644 --- a/src/renderer/src/env.d.ts +++ b/src/renderer/src/env.d.ts @@ -1,5 +1,7 @@ /// +declare const __APP_VERSION__: string + declare module '*.vue' { import type { DefineComponent } from 'vue' const component: DefineComponent diff --git a/src/renderer/src/stores/updater.store.ts b/src/renderer/src/stores/updater.store.ts new file mode 100644 index 0000000..1b99499 --- /dev/null +++ b/src/renderer/src/stores/updater.store.ts @@ -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 { + 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 } +}) diff --git a/src/renderer/src/views/SettingsView.vue b/src/renderer/src/views/SettingsView.vue index 095952b..bd50451 100644 --- a/src/renderer/src/views/SettingsView.vue +++ b/src/renderer/src/views/SettingsView.vue @@ -7,6 +7,7 @@ import CustomSelect from '../components/CustomSelect.vue' import ColorPicker from '../components/ColorPicker.vue' import AppIcon from '../components/AppIcon.vue' import EditAccountDialog from '../components/accounts/EditAccountDialog.vue' +import { useUpdaterStore } from '../stores/updater.store' import type { AccountConfig } from '@shared/types/account' const router = useRouter() @@ -14,6 +15,7 @@ const accountsStore = useAccountsStore() const settingsStore = useSettingsStore() const editingAccount = ref(null) +const updaterStore = useUpdaterStore() const swipeOptions: { value: SwipeAction; label: string }[] = ( ['delete', 'toggleRead', 'toggleFlag', 'none'] as SwipeAction[] @@ -186,6 +188,58 @@ function folderDisplayName(path: string): string { + +
+ +
+
+ Версия +
+ v{{ __APP_VERSION__ }} + ● +
+ +
+
+
+
+ + {{ updaterStore.error }} +
+
+ +
+ Доступна версия {{ updaterStore.version }} +
+ +
+
+
+
+ +
+
+
+
+ {{ updaterStore.percent }}% +
+
+
+ +
+ Обновление загружено +
+ +
+
+
+
+
+
@@ -614,4 +668,77 @@ function folderDisplayName(path: string): string { overflow: hidden; 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; +} diff --git a/src/shared/types/ipc.ts b/src/shared/types/ipc.ts index 9a462e0..0a53687 100644 --- a/src/shared/types/ipc.ts +++ b/src/shared/types/ipc.ts @@ -59,12 +59,21 @@ export interface IpcChannelMap { { accountId: 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 { 'mail:new': { accountId: string; folderId: string; envelope: MessageEnvelope } 'account:status': { accountId: string; connected: boolean; 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 + 'update:progress': { percent: number; transferred: number; total: number } + 'update:downloaded': Record + 'update:error': { error: string } } export type IpcChannel = keyof IpcChannelMap