Skip to content

Commit

Permalink
fix(app-webpack): (backport from q/app-webpack v4 beta) Capacitor/Cor…
Browse files Browse the repository at this point in the history
…dova on Windows host -> Android Studio not being launched when running "quasar build -m capacitor -T android --ide" #17420
  • Loading branch information
rstoenescu committed Aug 7, 2024
1 parent 744bbc2 commit 9905f03
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
3 changes: 2 additions & 1 deletion app-webpack/lib/capacitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { spawn, spawnSync } = require('../helpers/spawn')
const onShutdown = require('../helpers/on-shutdown')
const appPaths = require('../app-paths')
const openIde = require('../helpers/open-ide')
const { SIGNAL__BUILD_SHOULD_EXIT } = require('../helpers/signals.js')

const { capBin } = require('./cap-cli')

Expand Down Expand Up @@ -61,7 +62,7 @@ class CapacitorRunner {

if (argv.ide === true) {
await openIde('capacitor', cfg.bin, this.target)
process.exit(0)
return SIGNAL__BUILD_SHOULD_EXIT
}

if (this.target === 'ios') {
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 @@ -261,7 +261,12 @@ async function build () {
console.error(err)
fatal('Failed to finalize build (check the log above)', 'FAIL')
})
.then(async () => {
.then(async signal => {
if (signal !== void 0) {
const { SIGNAL__BUILD_SHOULD_EXIT } = await import('../helpers/signals.js')
if (signal === SIGNAL__BUILD_SHOULD_EXIT) return
}

outputFolder = argv.mode === 'cordova'
? path.join(outputFolder, '..')
: outputFolder
Expand Down
3 changes: 2 additions & 1 deletion app-webpack/lib/cordova/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { spawn } = require('../helpers/spawn')
const onShutdown = require('../helpers/on-shutdown')
const appPaths = require('../app-paths')
const openIde = require('../helpers/open-ide')
const { SIGNAL__BUILD_SHOULD_EXIT } = require('../helpers/signals.js')

const cordovaOutputFolders = {
ios: [
Expand Down Expand Up @@ -119,7 +120,7 @@ class CordovaRunner {

if (argv.ide) {
await openIde('cordova', quasarConf.bin, this.target)
process.exit(0)
return SIGNAL__BUILD_SHOULD_EXIT
}

const targetFolder = quasarConf.build.packagedDistDir
Expand Down
37 changes: 15 additions & 22 deletions app-webpack/lib/helpers/open-ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@ function runMacOS (mode, target) {
? 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 @@ -69,12 +68,10 @@ function runLinux (mode, bin, target) {
? 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 @@ -122,16 +119,10 @@ function runWindows (mode, bin, target) {
? appPaths.resolve.cordova('platforms/android')
: appPaths.resolve.capacitor('android')

open(folder, {
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 @@ -144,10 +135,12 @@ function runWindows (mode, bin, target) {
process.exit(1)
}

module.exports = function (mode, bin, target, dev) {
// openIde() returns the result of an open() call (which is a Promise)
// so this function should be treated as async
module.exports = function openIde (mode, bin, target, dev) {
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/helpers/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 9905f03

Please sign in to comment.