Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Make sure to read latest app build on desktop (#2392)
Browse files Browse the repository at this point in the history
* Delete appDataPath on new entire electron app

* Use newest build dir

* Enable build

* Add codesign

* Add publish step

* Actually register build dir

* Remove leading slash

* Fix up

* Speed up startup

* Undo CSC changes
  • Loading branch information
raymondjacobson authored and dylanjeffers committed Dec 14, 2022
1 parent 878c64a commit 42e0e94
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"start:stage": "npm run write-sha && npm run publish-scripts && env-cmd --no-override ./.env/.env.stage npm start",
"start:prod": "npm run write-sha && npm run publish-scripts && env-cmd --no-override ./.env/.env.prod npm start",
"prebuild": "npm run publish-scripts",
"build": "craco --max-old-space-size=8076 build",
"build": "craco --max-old-space-size=8076 build && cp package.json build/package.json",
"build:dev": "npm run write-sha && env-cmd ./.env/.env.dev npm run build && rm -rf build-development && mv build build-development",
"build:stage": "npm run write-sha && env-cmd ./.env/.env.stage npm run build && rm -rf build-staging && mv build build-staging",
"build:prod": "npm run write-sha && env-cmd ./.env/.env.prod npm run build && rm -rf build-production && mv build build-production",
Expand Down
25 changes: 15 additions & 10 deletions packages/web/scripts/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const notarizeFn = async (appId, params) => {
try {
await notarize({
appBundleId: appId,
appPath: appPath,
appPath,
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_ID_PASSWORD,
ascProvider: process.env.ASC_PROVIDER
Expand All @@ -79,7 +79,7 @@ const notarizeFn = async (appId, params) => {
* Write a json file indicating what environment the application is running in
* @param {boolean} isProduction
*/
const writeEnv = isProduction => {
const writeEnv = (isProduction) => {
if (isProduction) {
return fse.writeFile(
'electronConfig.json',
Expand All @@ -96,7 +96,7 @@ const writeEnv = isProduction => {
* Generates the correct application info/build config based on the environment
* @param {boolean} isProduction
*/
const makeBuildParams = isProduction => {
const makeBuildParams = (isProduction) => {
const appId = isProduction ? PRODUCTION_APP_ID : STAGING_APP_ID
const productName = isProduction ? PRODUCTION_NAME : STAGING_NAME
const packageJsonName = isProduction
Expand All @@ -113,17 +113,17 @@ const makeBuildParams = isProduction => {

return {
config: {
appId: appId,
appId,
npmRebuild: false,
productName: productName,
productName,
// Inject data into package.json
// https://www.electron.build/configuration/configuration
extraMetadata: {
// We set prod & stage to separate values to ensure that
// the app's app-data does not collide (in addition to a different `scheme`).
// `productName` controls the app-data location on most platforms.
// https://github.com/electron-userland/electron-builder/issues/3429#issuecomment-434024379
productName: productName,
productName,
// `name` controls the app-data location on some linux platforms.
// https://github.com/electron/electron/blob/main/docs/api/app.md#appgetname
name: packageJsonName
Expand All @@ -132,7 +132,12 @@ const makeBuildParams = isProduction => {
directories: {
buildResources: buildDir
},
files: [`${buildDir}/**/*`, 'electronConfig.json', 'src/electron.js'],
files: [
`${buildDir}/**/*`,
'electronConfig.json',
'src/electron.js',
'package.json'
],
protocols: {
// Scheme controls deep links as well as local-storage prefix
name: scheme,
Expand Down Expand Up @@ -170,7 +175,7 @@ const makeBuildParams = isProduction => {
},
win: {
target: 'nsis',
icon: icon,
icon,
publisherName: 'Audius, Inc.'
},
linux: {
Expand All @@ -187,7 +192,7 @@ const makeBuildParams = isProduction => {
url: 'https://audius.co'
}
},
afterSign: async params => notarizeFn(appId, params),
afterSign: async (params) => notarizeFn(appId, params),
publish: {
provider: 's3',
bucket,
Expand Down Expand Up @@ -217,7 +222,7 @@ console.log('Creating distribution with the following build params:')
console.log(buildParams)

writeEnv(program.env === 'production').then(() => {
builder.build(buildParams).catch(e => {
builder.build(buildParams).catch((e) => {
console.error(e)
process.exit(1)
})
Expand Down
34 changes: 23 additions & 11 deletions packages/web/src/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ switch (env) {
s3Bucket = ''
break
case 'staging':
console.log('in staging')
appEnvironment = Environment.STAGING
scheme = 'audius-staging'
buildName = 'build-staging'
Expand Down Expand Up @@ -144,6 +145,22 @@ const registerBuild = (directory) => {
)
}

const getNewestBuildDirectory = () => {
const buildDirectory = path.resolve(app.getAppPath(), buildName)
const updateBuildDirectory = appDataPath(buildName)
try {
const updatePackageJsonPath = appDataPath(`${buildName}/package.json`)
const updatePackageJson = JSON.parse(fs.readFileSync(updatePackageJsonPath))
const updateVersion = updatePackageJson.version
if (semver.gt(updateVersion, appVersion)) {
return updateBuildDirectory
}
} catch (e) {
// do nothing
}
return buildDirectory
}

const downloadWebUpdateAndNotify = async (newVersion) => {
const newBuildPath = appDataPath(`${buildName}.tar.gz`)
const webUpdateDir = appDataPath('web-update')
Expand Down Expand Up @@ -182,13 +199,16 @@ const checkForWebUpdate = () => {
const newVersion = packageJson.version

let currentVersion = appVersion

const packageJsonPath = appDataPath(`${buildName}/package.json`)

// Additional check for the version from the build package.json
// Needed after web updates because the local package.json version is not updated
if (fs.existsSync(packageJsonPath)) {
const buildPackageJson = JSON.parse(fs.readFileSync(packageJsonPath))
currentVersion = buildPackageJson.version
if (semver.gt(buildPackageJson.version, currentVersion)) {
currentVersion = buildPackageJson.version
}
}

// If there is a patch version update, download it and notify the user
Expand Down Expand Up @@ -255,15 +275,8 @@ const createWindow = () => {
if (appEnvironment === Environment.LOCALHOST) {
mainWindow.loadURL(`http://localhost:${localhostPort}`)
} else {
const buildDirectory = path.resolve(app.getAppPath(), buildName)
const updateBuildDirectory = appDataPath(buildName)

// Register the updated build if it exists, otherwise use the default build found via `getAppPath`
registerBuild(
fs.existsSync(updateBuildDirectory)
? updateBuildDirectory
: buildDirectory
)
const buildDir = getNewestBuildDirectory()
registerBuild(buildDir)
checkForWebUpdate()

// Win protocol handler
Expand Down Expand Up @@ -429,7 +442,6 @@ let canUpdate = false
ipcMain.on('update', async (event, arg) => {
// eslint-disable-next-line
while (!canUpdate) {
console.log('cannot update')
await new Promise((resolve) => setTimeout(resolve, 100))
}
autoUpdater.quitAndInstall()
Expand Down

0 comments on commit 42e0e94

Please sign in to comment.