From 113ad3d9170d2e1f1b7c9a6b8c5e03a04cd9ccbc Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Sun, 30 Sep 2018 13:11:15 -0700 Subject: [PATCH] Fixes for OSX App Translocation makes it nearly impossible to find the interface executable from the running server-console, specifically in downloaded builds launched from the Finder. To enable OSX detection and and launch of the interface, the code has been changed to: * Assume interface is installed on OSX as we don't produce a server-only build. * Launch the interface by using 'open' with the appid. NOTE: This may launch the wrong version of the app if multiple instances of the app are installed, but this is the best we can do for now. For most users, the behavior should be as expected. Second, polling was happening even if interface couldn't be detected if it was previously enabled. --- cmake/macros/SetPackagingParameters.cmake | 1 + cmake/modules/MacOSXBundleInfo.plist.in | 8 ++++ cmake/templates/CPackProperties.cmake.in | 1 + server-console/src/main.js | 16 +++++++- server-console/src/modules/hf-app.js | 37 ++++++++++++++----- .../src/modules/hf-notifications.js | 4 +- 6 files changed, 55 insertions(+), 12 deletions(-) diff --git a/cmake/macros/SetPackagingParameters.cmake b/cmake/macros/SetPackagingParameters.cmake index dce419a0e4..297382b4e5 100644 --- a/cmake/macros/SetPackagingParameters.cmake +++ b/cmake/macros/SetPackagingParameters.cmake @@ -37,6 +37,7 @@ macro(SET_PACKAGING_PARAMETERS) set(BUILD_VERSION ${RELEASE_NUMBER}) set(BUILD_ORGANIZATION "High Fidelity") set(HIGH_FIDELITY_PROTOCOL "hifi") + set(HIGH_FIDELITY_APP_PROTOCOL "hifiapp") set(INTERFACE_BUNDLE_NAME "Interface") set(INTERFACE_ICON_PREFIX "interface") diff --git a/cmake/modules/MacOSXBundleInfo.plist.in b/cmake/modules/MacOSXBundleInfo.plist.in index a06fac092f..b9558cf361 100644 --- a/cmake/modules/MacOSXBundleInfo.plist.in +++ b/cmake/modules/MacOSXBundleInfo.plist.in @@ -42,6 +42,14 @@ hifi + + CFBundleURLName + ${MACOSX_BUNDLE_BUNDLE_NAME} APP URL + CFBundleURLSchemes + + hifiapp + + NSHighResolutionCapable diff --git a/cmake/templates/CPackProperties.cmake.in b/cmake/templates/CPackProperties.cmake.in index a38c3d5361..cb6474b010 100644 --- a/cmake/templates/CPackProperties.cmake.in +++ b/cmake/templates/CPackProperties.cmake.in @@ -27,6 +27,7 @@ set(DS_EXEC_NAME "@DS_EXEC_NAME@") set(AC_DISPLAY_NAME "Assignment Client") set(AC_EXEC_NAME "@AC_EXEC_NAME@") set(HIGH_FIDELITY_PROTOCOL "@HIGH_FIDELITY_PROTOCOL@") +set(HIGH_FIDELITY_APP_PROTOCOL "@HIGH_FIDELITY_APP_PROTOCOL@") set(PRODUCTION_BUILD "@PRODUCTION_BUILD@") set(PR_BUILD "@PR_BUILD@") set(BUILD_ORGANIZATION "@BUILD_ORGANIZATION@") diff --git a/server-console/src/main.js b/server-console/src/main.js index d1b3dd2dd3..04e77315bc 100644 --- a/server-console/src/main.js +++ b/server-console/src/main.js @@ -108,7 +108,16 @@ const ipcMain = electron.ipcMain; function isInterfaceInstalled() { - return interfacePath; + if (osType == "Darwin") { + // In OSX Sierra, the app translocation process moves + // the executable to a random location before starting it + // which makes finding the interface near impossible using + // relative paths. For now, as there are no server-only + // installs, we just assume the interface is installed here + return true; + } else { + return interfacePath; + } } function isServerInstalled() { @@ -377,7 +386,7 @@ LogWindow.prototype = { }; function visitSandboxClicked() { - if (interfacePath) { + if (isInterfaceInstalled()) { StartInterface('hifi://localhost'); } else { // show an error to say that we can't go home without an interface instance @@ -906,6 +915,9 @@ app.on('ready', function() { tray.popUpContextMenu(tray.menu); }); + if (isInterfaceInstalled()) { + trayNotifications.startPolling(); + } updateTrayMenu(ProcessGroupStates.STOPPED); maybeInstallDefaultContentSet(onContentLoaded); diff --git a/server-console/src/modules/hf-app.js b/server-console/src/modules/hf-app.js index 3db48bd9c4..af6c38cdb3 100644 --- a/server-console/src/modules/hf-app.js +++ b/server-console/src/modules/hf-app.js @@ -7,6 +7,7 @@ const path = require('path'); const argv = require('yargs').argv; const hfprocess = require('./hf-process'); const osHomeDir = require('os-homedir'); +const childProcess = require('child_process'); const Process = hfprocess.Process; const binaryType = argv.binaryType; @@ -53,17 +54,35 @@ const buildInfo = exports.getBuildInfo(); const interfacePath = pathFinder.discoveredPath("interface", binaryType, buildInfo.releaseType); exports.startInterface = function(url) { - var argArray = []; - // check if we have a url parameter to include - if (url) { - argArray = ["--url", url]; + if (osType === 'Darwin') { + if (!url) { + log.debug("No URL given for startInterface"); + return; + } + + // do this as a workaround for app translocation on osx, which makes + // it nearly impossible to find the interface executable + var bundle_id = 'com.highfidelity.interface-dev'; + if (buildInfo.releaseType == 'PR') { + bundle_id = 'com.highfidelity.interface-pr'; + } else if (buildInfo.releaseType == 'PRODUCTION') { + bundle_id = 'com.highfidelity.interface'; + } + childProcess.exec('open -b ' + bundle_id + ' --args --url ' + url); + } else { + var argArray = []; + + // check if we have a url parameter to include + if (url) { + argArray = ["--url", url]; + } + console.log("Starting with " + url); + // create a new Interface instance - Interface makes sure only one is running at a time + var pInterface = new Process('Interface', interfacePath, argArray); + pInterface.detached = true; + pInterface.start(); } - console.log("Starting with " + url); - // create a new Interface instance - Interface makes sure only one is running at a time - var pInterface = new Process('Interface', interfacePath, argArray); - pInterface.detached = true; - pInterface.start(); } exports.isInterfaceRunning = function(done) { diff --git a/server-console/src/modules/hf-notifications.js b/server-console/src/modules/hf-notifications.js index c69c81aff2..13c5a6d8fa 100644 --- a/server-console/src/modules/hf-notifications.js +++ b/server-console/src/modules/hf-notifications.js @@ -143,7 +143,6 @@ function HifiNotifications(config, menuNotificationCallback) { this.walletSince = new Date(this.config.get("walletNotifySince", "1970-01-01T00:00:00.000Z")); this.marketplaceSince = new Date(this.config.get("marketplaceNotifySince", "1970-01-01T00:00:00.000Z")); - this.enable(this.enabled()); this.pendingNotifications = []; @@ -193,6 +192,9 @@ HifiNotifications.prototype = { enabled: function () { return !this.config.get("disableTrayNotifications", false); }, + startPolling: function () { + this.enable(this.enabled()); + }, stopPolling: function () { this.config.set("storiesNotifySince", this.storiesSince.toISOString()); this.config.set("peopleNotifySince", this.peopleSince.toISOString());