Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
fix macOS updater
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Sep 23, 2024
1 parent 526282c commit 937da8f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ jobs:
npm_config_target_arch: ${{ matrix.arch }}
run: pnpm build:mac --${{ matrix.arch }}
- name: Generate checksums
run: pnpm checksum .dmg .zip
run: pnpm checksum .dmg
- name: Upload Artifacts
if: startsWith(github.ref, 'refs/heads/')
uses: actions/upload-artifact@v4
Expand All @@ -207,7 +207,6 @@ jobs:
path: |
dist/*.sha256
dist/*.dmg
dist/*.zip
if-no-files-found: error
- name: Publish Release
if: startsWith(github.ref, 'refs/tags/v')
Expand All @@ -216,7 +215,6 @@ jobs:
files: |
dist/*.sha256
dist/*.dmg
dist/*.zip
body_path: changelog.md
token: ${{ secrets.GITHUB_TOKEN }}

Expand Down
1 change: 0 additions & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ nsis:
mac:
target:
- dmg
- zip
entitlementsInherit: build/entitlements.mac.plist
extendInfo:
- NSCameraUsageDescription: Application requests access to the device's camera.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mihomo-party",
"version": "1.3.1",
"version": "1.3.0",
"description": "Mihomo Party",
"main": "./out/main/index.js",
"author": "mihomo-party",
Expand Down
23 changes: 18 additions & 5 deletions src/main/resolve/autoUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'
import yaml from 'yaml'
import { app } from 'electron'
import { getControledMihomoConfig } from '../config'
import { dataDir, exeDir, isPortable, resourcesFilesDir } from '../utils/dirs'
import { dataDir, exeDir, exePath, isPortable, resourcesFilesDir } from '../utils/dirs'
import { rm, writeFile } from 'fs/promises'
import path from 'path'
import { existsSync } from 'fs'
Expand Down Expand Up @@ -39,8 +39,8 @@ export async function downloadAndInstallUpdate(version: string): Promise<void> {
'win32-x64': `mihomo-party-windows-${version}-x64-setup.exe`,
'win32-ia32': `mihomo-party-windows-${version}-ia32-setup.exe`,
'win32-arm64': `mihomo-party-windows-${version}-arm64-setup.exe`,
'darwin-x64': `mihomo-party-macos-${version}-x64.zip`,
'darwin-arm64': `mihomo-party-macos-${version}-arm64.zip`
'darwin-x64': `mihomo-party-macos-${version}-x64.dmg`,
'darwin-arm64': `mihomo-party-macos-${version}-arm64.dmg`
}
let file = fileMap[`${process.platform}-${process.arch}`]
if (isPortable()) {
Expand Down Expand Up @@ -84,9 +84,22 @@ export async function downloadAndInstallUpdate(version: string): Promise<void> {
).unref()
app.quit()
}
if (file.endsWith('.zip')) {
if (file.endsWith('.dmg')) {
const execPromise = promisify(exec)
await execPromise(`unzip -o -K '${path.join(dataDir(), file)}' -d /Applications`)
const name = exePath().split('.app')[0].replace('/Applications/', '')
try {
await execPromise(
`hdiutil attach "${path.join(dataDir(), file)}" -mountpoint "/Volumes/mihomo-party" -nobrowse`
)
await execPromise(`mv /Applications/${name}.app /tmp`)
await execPromise('cp -R "/Volumes/mihomo-party/mihomo-party.app" /Applications/')
await execPromise(`rm -rf /tmp/${name}.app`)
} catch (e) {
await execPromise(`mv /tmp/${name}.app /Applications`)
throw e
} finally {
await execPromise('hdiutil detach "/Volumes/mihomo-party"')
}
app.relaunch()
app.quit()
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async function cleanup(): Promise<void> {
// update cache
const files = await readdir(dataDir())
for (const file of files) {
if (file.endsWith('.exe') || file.endsWith('.dmg') || file.endsWith('.zip')) {
if (file.endsWith('.exe') || file.endsWith('.dmg')) {
try {
await rm(path.join(dataDir(), file))
} catch {
Expand Down

0 comments on commit 937da8f

Please sign in to comment.