Pass app path as command line argument
This commit is contained in:
parent
9cb6bc098d
commit
4a7eec8f2d
7 changed files with 31 additions and 7 deletions
|
@ -655,6 +655,14 @@ void App::OnGpuProcessCrashed(base::TerminationStatus status) {
|
||||||
status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
|
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) {
|
base::FilePath App::GetPath(mate::Arguments* args, const std::string& name) {
|
||||||
bool succeed = false;
|
bool succeed = false;
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
|
@ -959,6 +967,8 @@ void App::BuildPrototype(
|
||||||
.SetMethod("isUnityRunning",
|
.SetMethod("isUnityRunning",
|
||||||
base::Bind(&Browser::IsUnityRunning, browser))
|
base::Bind(&Browser::IsUnityRunning, browser))
|
||||||
#endif
|
#endif
|
||||||
|
.SetMethod("setAppPath", &App::SetAppPath)
|
||||||
|
.SetMethod("getAppPath", &App::GetAppPath)
|
||||||
.SetMethod("setPath", &App::SetPath)
|
.SetMethod("setPath", &App::SetPath)
|
||||||
.SetMethod("getPath", &App::GetPath)
|
.SetMethod("getPath", &App::GetPath)
|
||||||
.SetMethod("setDesktopName", &App::SetDesktopName)
|
.SetMethod("setDesktopName", &App::SetDesktopName)
|
||||||
|
|
|
@ -70,6 +70,8 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
std::unique_ptr<CertificateManagerModel> model);
|
std::unique_ptr<CertificateManagerModel> model);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::string GetAppPath();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit App(v8::Isolate* isolate);
|
explicit App(v8::Isolate* isolate);
|
||||||
~App() override;
|
~App() override;
|
||||||
|
@ -115,6 +117,8 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
void OnGpuProcessCrashed(base::TerminationStatus status) override;
|
void OnGpuProcessCrashed(base::TerminationStatus status) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void SetAppPath(const std::string& app_path);
|
||||||
|
|
||||||
// Get/Set the pre-defined path in PathService.
|
// Get/Set the pre-defined path in PathService.
|
||||||
base::FilePath GetPath(mate::Arguments* args, const std::string& name);
|
base::FilePath GetPath(mate::Arguments* args, const std::string& name);
|
||||||
void SetPath(mate::Arguments* args,
|
void SetPath(mate::Arguments* args,
|
||||||
|
@ -154,6 +158,8 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
// Tracks tasks requesting file icons.
|
// Tracks tasks requesting file icons.
|
||||||
base::CancelableTaskTracker cancelable_task_tracker_;
|
base::CancelableTaskTracker cancelable_task_tracker_;
|
||||||
|
|
||||||
|
std::string app_path_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(App);
|
DISALLOW_COPY_AND_ASSIGN(App);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -234,6 +234,12 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
}
|
}
|
||||||
#endif
|
#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);
|
content::WebContents* web_contents = GetWebContentsFromProcessID(process_id);
|
||||||
if (!web_contents)
|
if (!web_contents)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -159,6 +159,9 @@ const char kSecureSchemes[] = "secure-schemes";
|
||||||
// The browser process app model ID
|
// The browser process app model ID
|
||||||
const char kAppUserModelId[] = "app-user-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.
|
// The command line switch versions of the options.
|
||||||
const char kBackgroundColor[] = "background-color";
|
const char kBackgroundColor[] = "background-color";
|
||||||
const char kPreloadScript[] = "preload";
|
const char kPreloadScript[] = "preload";
|
||||||
|
|
|
@ -81,6 +81,7 @@ extern const char kStandardSchemes[];
|
||||||
extern const char kRegisterServiceWorkerSchemes[];
|
extern const char kRegisterServiceWorkerSchemes[];
|
||||||
extern const char kSecureSchemes[];
|
extern const char kSecureSchemes[];
|
||||||
extern const char kAppUserModelId[];
|
extern const char kAppUserModelId[];
|
||||||
|
extern const char kAppPath[];
|
||||||
|
|
||||||
extern const char kBackgroundColor[];
|
extern const char kBackgroundColor[];
|
||||||
extern const char kPreloadScript[];
|
extern const char kPreloadScript[];
|
||||||
|
|
|
@ -12,11 +12,7 @@ const {EventEmitter} = require('events')
|
||||||
|
|
||||||
Object.setPrototypeOf(App.prototype, EventEmitter.prototype)
|
Object.setPrototypeOf(App.prototype, EventEmitter.prototype)
|
||||||
|
|
||||||
let appPath = null
|
|
||||||
|
|
||||||
Object.assign(app, {
|
Object.assign(app, {
|
||||||
getAppPath () { return appPath },
|
|
||||||
setAppPath (path) { appPath = path },
|
|
||||||
setApplicationMenu (menu) {
|
setApplicationMenu (menu) {
|
||||||
return Menu.setApplicationMenu(menu)
|
return Menu.setApplicationMenu(menu)
|
||||||
},
|
},
|
||||||
|
|
|
@ -56,6 +56,7 @@ electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (ev
|
||||||
let nodeIntegration = 'false'
|
let nodeIntegration = 'false'
|
||||||
let preloadScript = null
|
let preloadScript = null
|
||||||
let isBackgroundPage = false
|
let isBackgroundPage = false
|
||||||
|
let appPath = null
|
||||||
for (let arg of process.argv) {
|
for (let arg of process.argv) {
|
||||||
if (arg.indexOf('--guest-instance-id=') === 0) {
|
if (arg.indexOf('--guest-instance-id=') === 0) {
|
||||||
// This is a guest web view.
|
// This is a guest web view.
|
||||||
|
@ -69,6 +70,8 @@ for (let arg of process.argv) {
|
||||||
preloadScript = arg.substr(arg.indexOf('=') + 1)
|
preloadScript = arg.substr(arg.indexOf('=') + 1)
|
||||||
} else if (arg === '--background-page') {
|
} else if (arg === '--background-page') {
|
||||||
isBackgroundPage = true
|
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.__filename = __filename
|
||||||
global.__dirname = __dirname
|
global.__dirname = __dirname
|
||||||
|
|
||||||
if (window.location.protocol !== 'chrome-devtools:') {
|
if (appPath) {
|
||||||
// Search for module under the app directory
|
// Search for module under the app directory
|
||||||
// (remote.app doesn't work in devtools)
|
module.paths = module.paths.concat(Module._nodeModulePaths(appPath))
|
||||||
module.paths = module.paths.concat(Module._nodeModulePaths(electron.remote.app.getAppPath()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue