Pass app path as command line argument

This commit is contained in:
Ryohei Ikegami 2017-04-04 09:36:01 +09:00
parent 9cb6bc098d
commit 4a7eec8f2d
7 changed files with 31 additions and 7 deletions

View file

@ -655,6 +655,14 @@ void App::OnGpuProcessCrashed(base::TerminationStatus status) {
status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
}
std::string App::GetAppPath() {
return app_path_;
}
void App::SetAppPath(const std::string& app_path) {
app_path_ = app_path;
}
base::FilePath App::GetPath(mate::Arguments* args, const std::string& name) {
bool succeed = false;
base::FilePath path;
@ -959,6 +967,8 @@ void App::BuildPrototype(
.SetMethod("isUnityRunning",
base::Bind(&Browser::IsUnityRunning, browser))
#endif
.SetMethod("setAppPath", &App::SetAppPath)
.SetMethod("getAppPath", &App::GetAppPath)
.SetMethod("setPath", &App::SetPath)
.SetMethod("getPath", &App::GetPath)
.SetMethod("setDesktopName", &App::SetDesktopName)

View file

@ -70,6 +70,8 @@ class App : public AtomBrowserClient::Delegate,
std::unique_ptr<CertificateManagerModel> model);
#endif
std::string GetAppPath();
protected:
explicit App(v8::Isolate* isolate);
~App() override;
@ -115,6 +117,8 @@ class App : public AtomBrowserClient::Delegate,
void OnGpuProcessCrashed(base::TerminationStatus status) override;
private:
void SetAppPath(const std::string& app_path);
// Get/Set the pre-defined path in PathService.
base::FilePath GetPath(mate::Arguments* args, const std::string& name);
void SetPath(mate::Arguments* args,
@ -154,6 +158,8 @@ class App : public AtomBrowserClient::Delegate,
// Tracks tasks requesting file icons.
base::CancelableTaskTracker cancelable_task_tracker_;
std::string app_path_;
DISALLOW_COPY_AND_ASSIGN(App);
};

View file

@ -234,6 +234,12 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
}
#endif
if (delegate_) {
auto app_path = static_cast<api::App*>(delegate_)->GetAppPath();
command_line->AppendSwitchASCII(switches::kAppPath,
app_path);
}
content::WebContents* web_contents = GetWebContentsFromProcessID(process_id);
if (!web_contents)
return;

View file

@ -159,6 +159,9 @@ const char kSecureSchemes[] = "secure-schemes";
// The browser process app model ID
const char kAppUserModelId[] = "app-user-model-id";
// The application path
const char kAppPath[] = "app-path";
// The command line switch versions of the options.
const char kBackgroundColor[] = "background-color";
const char kPreloadScript[] = "preload";

View file

@ -81,6 +81,7 @@ extern const char kStandardSchemes[];
extern const char kRegisterServiceWorkerSchemes[];
extern const char kSecureSchemes[];
extern const char kAppUserModelId[];
extern const char kAppPath[];
extern const char kBackgroundColor[];
extern const char kPreloadScript[];

View file

@ -12,11 +12,7 @@ const {EventEmitter} = require('events')
Object.setPrototypeOf(App.prototype, EventEmitter.prototype)
let appPath = null
Object.assign(app, {
getAppPath () { return appPath },
setAppPath (path) { appPath = path },
setApplicationMenu (menu) {
return Menu.setApplicationMenu(menu)
},

View file

@ -56,6 +56,7 @@ electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (ev
let nodeIntegration = 'false'
let preloadScript = null
let isBackgroundPage = false
let appPath = null
for (let arg of process.argv) {
if (arg.indexOf('--guest-instance-id=') === 0) {
// This is a guest web view.
@ -69,6 +70,8 @@ for (let arg of process.argv) {
preloadScript = arg.substr(arg.indexOf('=') + 1)
} else if (arg === '--background-page') {
isBackgroundPage = true
} else if (arg.indexOf('--app-path=') === 0) {
appPath = arg.substr(arg.indexOf('=') + 1)
}
}
@ -117,10 +120,9 @@ if (nodeIntegration === 'true') {
global.__filename = __filename
global.__dirname = __dirname
if (window.location.protocol !== 'chrome-devtools:') {
if (appPath) {
// Search for module under the app directory
// (remote.app doesn't work in devtools)
module.paths = module.paths.concat(Module._nodeModulePaths(electron.remote.app.getAppPath()))
module.paths = module.paths.concat(Module._nodeModulePaths(appPath))
}
}