Skip to content

Commit

Permalink
fix: Wrong update behavior of appx and appImage
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed May 7, 2023
1 parent 5e306ae commit 652211b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
48 changes: 33 additions & 15 deletions xmcl-electron-app/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ async function writeHash(algorithm: string, path: string, destination: string) {
* Use esbuild to build main process
*/
async function buildMain(options: BuildOptions) {
await rm(path.join(__dirname, './dist'), { recursive: true, force: true })
console.log(chalk.bold.underline('Build main process & preload'))
const startTime = Date.now()
await esbuild({
...options,
outdir: resolve(__dirname, './dist'),
entryPoints: [path.join(__dirname, './main/index.ts')],
})
console.log(
`Build completed in ${((Date.now() - startTime) / 1000).toFixed(2)}s.\n`,
)
await copy(path.join(__dirname, '../xmcl-keystone-ui/dist'), path.join(__dirname, './dist/renderer'))
console.log()
}

/**
Expand Down Expand Up @@ -154,22 +162,11 @@ async function installArm64() {
}

async function start() {
await rm(path.join(__dirname, './dist'), { recursive: true, force: true })

console.log(chalk.bold.underline('Build main process & preload'))
const startTime = Date.now()
await buildMain(esbuildConfig)
console.log(
`Build completed in ${((Date.now() - startTime) / 1000).toFixed(2)}s.\n`,
)

await copy(path.join(__dirname, '../xmcl-keystone-ui/dist'), path.join(__dirname, './dist/renderer'))

console.log()
if (process.env.BUILD_TARGET) {
const dir = process.env.BUILD_TARGET === 'dir'

await buildElectron({
const config: Configuration = {
...electronBuilderConfig,
async beforePack(context) {
const asarFile = join(context.appOutDir, 'resources', 'app.asar')
Expand All @@ -188,8 +185,8 @@ async function start() {
if (context.targetPresentableName.toLowerCase() === 'appx') {
const files = await readdir(path.join(__dirname, './icons'))
const storeFiles = files.filter(f => f.endsWith('.png') &&
!f.endsWith('256x256.png') &&
!f.endsWith('tray.png'))
!f.endsWith('256x256.png') &&
!f.endsWith('tray.png'))
.map((f) => [
path.join(__dirname, 'icons', f),
path.join(__dirname, 'build', 'appx', f.substring(f.indexOf('@') + 1)),
Expand All @@ -198,11 +195,32 @@ async function start() {
}
},
async artifactBuildCompleted(context) {
if (!context.arch) return
if (context.target && context.target.name === 'appx') {
await buildAppInstaller(version, path.join(__dirname, './build/output/xmcl.appinstaller'), electronBuilderConfig.appx!.publisher!)
}
},
}, dir)
}

await buildElectron(config, dir)

const currentPlatform = platform()
const runtime = currentPlatform === 'win32'
? 'appx'
: currentPlatform === 'linux'
? 'appimage'
: undefined

if (!dir && runtime) {
// Build appx and appImage additionally
(config.win as any).target = ['appx'];
(config.linux as any).target = [{ target: 'AppImage', arch: ['x64', 'arm64'] }]

esbuildConfig.define['process.env.RUNTIME'] = `"${runtime}"`
await buildMain(esbuildConfig)

await buildElectron(config, dir)
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions xmcl-electron-app/build/electron-builder.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable no-template-curly-in-string */
import { config as dotenv } from 'dotenv'
import { Configuration, TargetConfiguration } from 'electron-builder'
import { Configuration } from 'electron-builder'

dotenv()

type ArchType = TargetConfiguration['arch']
export const config = {
productName: 'X Minecraft Launcher',
appId: 'xmcl',
Expand Down Expand Up @@ -91,7 +90,6 @@ export const config = {
'**/*.worker.js',
],
target: [
'appx',
{
target: 'zip',
arch: [
Expand All @@ -109,7 +107,6 @@ export const config = {
icon: 'icons/dark@256x256.png',
artifactName: 'xmcl-${version}-${arch}.${ext}',
target: [
{ target: 'AppImage', arch: ['x64', 'arm64'] },
{ target: 'deb', arch: ['x64', 'arm64'] },
{ target: 'rpm', arch: ['x64', 'arm64'] },
{ target: 'tar.xz', arch: ['x64', 'arm64'] },
Expand Down
1 change: 1 addition & 0 deletions xmcl-electron-app/esbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const config = {
'process.env.BUILD_NUMBER': JSON.stringify(process.env.BUILD_NUMBER) ?? '0',
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) ?? '"development"',
'process.env.CURSEFORGE_API_KEY': JSON.stringify(process.env.CURSEFORGE_API_KEY),
'process.env.RUNTIME': JSON.stringify(process.env.RUNTIME || 'raw'),
},
platform: 'node',
loader: {
Expand Down
12 changes: 1 addition & 11 deletions xmcl-runtime/lib/app/LauncherApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ export interface LauncherApp {
emit(channel: 'engine-ready'): boolean
}

const loadEnv = () => {
if (IS_DEV) return 'raw'
try {
const env = readFileSync(join(__dirname, 'target'), 'utf8')
return env
} catch {
return 'raw'
}
}

export class LauncherApp extends EventEmitter {
/**
* Launcher %APPDATA%/xmcl path
Expand Down Expand Up @@ -94,7 +84,7 @@ export class LauncherApp extends EventEmitter {

readonly build: number = Number.parseInt(process.env.BUILD_NUMBER ?? '0', 10)

readonly env = loadEnv()
readonly env: 'raw' | 'appx' | 'appimage' = process.env.RUNTIME as any || 'raw'

get version() { return this.host.getVersion() }

Expand Down
2 changes: 1 addition & 1 deletion xmcl-runtime/lib/services/BaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class BaseService extends StatefulService<BaseState> implements IBaseServ
state.version = app.version
state.platform = app.platform
state.build = app.build
state.env = app.env as any
state.env = app.env
state.root = app.gameDataPath
return state
}, async () => {
Expand Down

0 comments on commit 652211b

Please sign in to comment.