Skip to content

Commit

Permalink
fix(app-webpack): Capacitor/Cordova on Windows host -> Android Studio…
Browse files Browse the repository at this point in the history
… not being launched when running "quasar build -m capacitor -T android --ide" #17420
  • Loading branch information
rstoenescu committed Aug 7, 2024
1 parent f7cdb4f commit 4d0bd02
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app-vite/lib/utils/open-ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function runWindows (mode, bin, target, appPaths) {
export function openIDE ({ mode, bin, target, dev, appPaths }) {
console.log()
console.log(' ⚠️ ')
console.log(` ⚠️ Opening ${ target === 'ios' ? 'XCode' : 'Android Studio' } IDE...`)
console.log(` ⚠️ Opening ${ target === 'ios' ? 'XCode' : 'Android Studio' } IDE. It might take a few seconds...`)

if (dev) {
console.log(' ⚠️ From there, use the IDE to run the app.')
Expand Down
7 changes: 6 additions & 1 deletion app-webpack/lib/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ async function runBuild () {
console.error(err)
fatal('App build failed (check the log above)', 'FAIL')
})
.then(async () => {
.then(async signal => {
if (signal !== void 0) {
const { SIGNAL__BUILD_SHOULD_EXIT } = await import('../utils/signals.js')
if (signal === SIGNAL__BUILD_SHOULD_EXIT) return
}

outputFolder = argv.mode === 'cordova'
? path.join(outputFolder, '..')
: outputFolder
Expand Down
5 changes: 3 additions & 2 deletions app-webpack/lib/modes/capacitor/capacitor-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { spawn, spawnSync } = require('../../utils/spawn.js')
const { openIDE } = require('../../utils/open-ide.js')
const { onShutdown } = require('../../utils/on-shutdown.js')
const { fixAndroidCleartext } = require('../../utils/fix-android-cleartext.js')
const { SIGNAL__BUILD_SHOULD_EXIT } = require('../../utils/signals.js')

module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder {
#capacitorConfigFile = new CapacitorConfigFile()
Expand All @@ -19,7 +20,7 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder {
this.#packagedDir = join(this.quasarConf.build.distDir, this.ctx.targetName)

await this.#buildFiles()
await this.#packageFiles()
return this.#packageFiles()
}

async #buildFiles () {
Expand Down Expand Up @@ -58,7 +59,7 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder {
appPaths
})

process.exit(0)
return SIGNAL__BUILD_SHOULD_EXIT
}

if (target === 'ios') {
Expand Down
6 changes: 4 additions & 2 deletions app-webpack/lib/modes/cordova/cordova-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { spawn } = require('../../utils/spawn.js')
const { openIDE } = require('../../utils/open-ide.js')
const { onShutdown } = require('../../utils/on-shutdown.js')
const { fixAndroidCleartext } = require('../../utils/fix-android-cleartext.js')
const { SIGNAL__BUILD_SHOULD_EXIT } = require('../../utils/signals.js')

const cordovaOutputFolders = {
ios: [
Expand All @@ -35,7 +36,7 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder {

async build () {
await this.#buildFiles()
await this.#packageFiles()
return this.#packageFiles()
}

async #buildFiles () {
Expand Down Expand Up @@ -95,7 +96,8 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder {
target,
appPaths
})
process.exit(0)

return SIGNAL__BUILD_SHOULD_EXIT
}

const targetFolder = join(this.quasarConf.build.distDir, this.quasarConf.ctx.targetName)
Expand Down
41 changes: 20 additions & 21 deletions app-webpack/lib/utils/open-ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ function runMacOS ({ mode, target, appPaths, open }) {
? appPaths.resolve.cordova('platforms/ios')
: appPaths.resolve.capacitor('ios/App')

open(findXcodeWorkspace(folder), {
return open(findXcodeWorkspace(folder), {
wait: false
})
}
else {
const folder = mode === 'cordova'
? appPaths.resolve.cordova('platforms/android')
: appPaths.resolve.capacitor('android')

open(folder, {
app: { name: 'android studio' },
wait: false
})
}
const folder = mode === 'cordova'
? appPaths.resolve.cordova('platforms/android')
: appPaths.resolve.capacitor('android')

return open(folder, {
app: { name: 'android studio' },
wait: false
})
}

function getLinuxPath (bin) {
Expand Down Expand Up @@ -67,12 +66,10 @@ function runLinux ({ mode, bin, target, appPaths, open }) {
? appPaths.resolve.cordova('platforms/android')
: appPaths.resolve.capacitor('android')

open(folder, {
return open(folder, {
app: { name: studioPath },
wait: false
})

return
}
}
else if (target === 'ios') {
Expand Down Expand Up @@ -120,16 +117,18 @@ function runWindows ({ mode, bin, target, appPaths, open }) {
? appPaths.resolve.cordova('platforms/android')
: appPaths.resolve.capacitor('android')

open(folder, {
/**
* On Windows, after calling the below function, the Node.js process
* should NOT exit by calling process.exit(_any_code_) under any form, otherwise the
* IDE will not get a chance to be opened.
*
* However, if process.exit() must still be called, a significant delay
* (30-60 seconds, the more the better) is needed before calling it.
*/
return open(folder, {
app: { name: studioPath },
wait: false
})

// pause required, otherwise Windows fails
// to open the process
return new Promise(resolve => {
setTimeout(resolve, 300)
})
}
}
else if (target === 'ios') {
Expand All @@ -145,7 +144,7 @@ function runWindows ({ mode, bin, target, appPaths, open }) {
module.exports.openIDE = async function openIDE ({ mode, bin, target, dev, appPaths }) {
console.log()
console.log(' ⚠️ ')
console.log(` ⚠️ Opening ${ target === 'ios' ? 'XCode' : 'Android Studio' } IDE...`)
console.log(` ⚠️ Opening ${ target === 'ios' ? 'XCode' : 'Android Studio' } IDE. It might take a few seconds...`)

if (dev) {
console.log(' ⚠️ From there, use the IDE to run the app.')
Expand Down
1 change: 1 addition & 0 deletions app-webpack/lib/utils/signals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports.SIGNAL__BUILD_SHOULD_EXIT = 'SIGNAL__BUILD_SHOULD_EXIT'

0 comments on commit 4d0bd02

Please sign in to comment.