diff --git a/commandLine/src/defines.h b/commandLine/src/defines.h index f919214d..58f1b251 100644 --- a/commandLine/src/defines.h +++ b/commandLine/src/defines.h @@ -1,5 +1,5 @@ #define OFPROJECTGENERATOR_MAJOR_VERSION "0" -#define OFPROJECTGENERATOR_MINOR_VERSION "105" +#define OFPROJECTGENERATOR_MINOR_VERSION "106" #define OFPROJECTGENERATOR_PATCH_VERSION "0" #define PG_VERSION (OFPROJECTGENERATOR_MAJOR_VERSION "." OFPROJECTGENERATOR_MINOR_VERSION "." OFPROJECTGENERATOR_PATCH_VERSION) diff --git a/frontend/app.js b/frontend/app.js index f825f0c8..21340748 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -534,7 +534,8 @@ function setup() { if(isSierra) { try { - const runningOnVar = (ofpath.length >= 8 && ofpath.substring(0,8) === '/private'); + // matches Gatekeeper's real AppTranslocation path, not just any /private path + const runningOnVar = /^\/private\/var\/folders\/.*\/AppTranslocation\//.test(ofpath); isFirstTimeSierra = runningOnVar; } catch(e) { isFirstTimeSierra = false; diff --git a/frontend/index.html b/frontend/index.html index dd8e9f5a..654ea123 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -389,12 +389,14 @@ - diff --git a/frontend/index.js b/frontend/index.js index 96053a17..27aa331e 100644 --- a/frontend/index.js +++ b/frontend/index.js @@ -63,6 +63,30 @@ const templateSettings = { +// mirrors isGoodOFPath() in commandLine/src/main.cpp +function isGoodOFPath(p) { + try { + return ['addons', 'libs', 'scripts'].every((folder) => { + const full = path.join(p, folder); + return fs.existsSync(full) && fs.statSync(full).isDirectory(); + }); + } catch (e) { + return false; + } +} + +// mirrors findOFPathUpwards() in commandLine/src/main.cpp +function findOFPathUpwards(startPath) { + let current = path.resolve(startPath); + let previous = null; + while (current !== previous) { + if (isGoodOFPath(current)) return current; + previous = current; + current = path.dirname(current); + } + return null; +} + /** * Determines the current platform based on process information. * @returns {string} The platform identifier. @@ -256,10 +280,18 @@ if (!path.isAbsolute(defaultOfPath)) { // arturo, this may differ on linux, if putting ../ in settings doesn't work for the default path // take a look at this... + let fixedDepthGuess; if (hostplatform == "windows" || hostplatform == "linux" || hostplatform == "linux64" ){ - defaultOfPath = path.resolve(path.join(path.join(__dirname, "../../../"), defaultOfPath)); + fixedDepthGuess = path.resolve(path.join(path.join(__dirname, "../../../"), defaultOfPath)); } else if(hostplatform == "osx"){ - defaultOfPath = path.resolve(path.join(path.join(__dirname, "../../../"), defaultOfPath)); + fixedDepthGuess = path.resolve(path.join(path.join(__dirname, "../../../"), defaultOfPath)); + } + + // validate the fixed-depth guess, else search upward from this app's own location + if (isGoodOFPath(fixedDepthGuess)) { + defaultOfPath = fixedDepthGuess; + } else { + defaultOfPath = findOFPathUpwards(__dirname) || fixedDepthGuess; } settings["defaultOfPath"] = defaultOfPath || ""; @@ -977,11 +1009,35 @@ function getPgPath() { return pgApp; } +// clear error when the cmdLine binary hasn't been built/copied into frontend/app/ yet +function pgMissingError(pgApp) { + return new Error( + `commandLine binary not found at "${pgApp}". Build it first (commandLine/, via make/xcodebuild/MSBuild) ` + + `then copy it into frontend/app/ - see scripts//build_frontend.sh, which does both.` + ); +} + +// wraps execFile(getPgPath(), ...) with the same missing-binary check as runPG() +function execPG(args, callback) { + const pgApp = getPgPath(); + if (!pgApp || !fs.existsSync(pgApp)) { + callback(pgMissingError(pgApp), '', ''); + return; + } + execFile(pgApp, args, { maxBuffer: Infinity }, callback); +} + // runs PG via argv (no shell), streaming stdout/stderr to the console panel as it arrives function runPG(args, event, callback) { const pgApp = getPgPath(); const displayCommand = [pgApp, ...args].join(' '); + if (!pgApp || !fs.existsSync(pgApp)) { + const error = pgMissingError(pgApp); + callback(error, '', error.message); + return; + } + let child; try { child = spawn(pgApp, args, { windowsHide: true }); @@ -1637,7 +1693,7 @@ function resolveEmsdkEnv(emsdkPath, emccDir) { // asks the PG binary to detect emcc via EMSDK / PATH / a Homebrew install (see resolveEmscriptenSDK in Utils.cpp) function detectEmsdk(callback) { - execFile(getPgPath(), ['-e'], { maxBuffer: Infinity }, (error, stdout) => { + execPG(['-e'], (error, stdout) => { if (error) return callback(null); try { const lastLine = stdout.trim().split('\n').pop(); @@ -1784,13 +1840,19 @@ ipcMain.on('openPath', (event, p) => { }); ipcMain.on('getOFPath', (event) => { - execFile(getPgPath(), ['--getofpath'], { maxBuffer: Infinity }, (error, stdout, stderr) => { + execPG(['--getofpath'], (error, stdout, stderr) => { if (error) { - console.log( 'getOFPath error' ); - event.sender.send('ofPathResult', { - success: false, - message: error.message - }); + console.log('getOFPath error:', error.message); + // cmdLine unavailable - fall back to the same search it would have done + const found = findOFPathUpwards(__dirname); + if (found) { + event.sender.send('ofPathResult', { success: true, message: found }); + } else { + event.sender.send('ofPathResult', { + success: false, + message: error.message + }); + } } else { try { // Assuming the JSON object is on the last line @@ -1818,7 +1880,7 @@ ipcMain.on('getOFPath', (event) => { }); ipcMain.on('getHostType', (event) => { - execFile(getPgPath(), ['-i'], { maxBuffer: Infinity }, (error, stdout, stderr) => { + execPG(['-i'], (error, stdout, stderr) => { if (error) { console.log( 'getHostType error' ); event.sender.send('ofPlatformResult', { @@ -1851,7 +1913,7 @@ ipcMain.on('getHostType', (event) => { }); ipcMain.on('getVersion', (event) => { - execFile(getPgPath(), ['-w'], { maxBuffer: Infinity }, (error, stdout, stderr) => { + execPG(['-w'], (error, stdout, stderr) => { if (error) { console.log( 'getVersion error' ); event.sender.send('ofVersionResult', { diff --git a/frontend/package.json b/frontend/package.json index b37a224d..0cf3d41f 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "projectGenerator", "productName": "projectGenerator", - "version": "0.96.0", + "version": "0.97.0", "description": "Build electron GUI openFrameworks projectGenerator", "license": "MIT", "main": "index.js",