Return boolean instead of empty string when error occurs. Update docs

This commit is contained in:
Samuel Attard 2016-08-18 18:02:13 +10:00
parent 88bf089504
commit ca971e978e
No known key found for this signature in database
GPG key ID: 273DC1869D8F13EF
2 changed files with 24 additions and 18 deletions

View file

@ -125,7 +125,7 @@ bool Browser::SetUserTasks(const std::vector<UserTask>& tasks) {
return SUCCEEDED(destinations->CommitList()); return SUCCEEDED(destinations->CommitList());
} }
std::wstring protocolLaunchPath(std::string protocol, mate::Arguments* args) { bool GetProtocolLaunchPath(std::string protocol, mate::Arguments* args, std::wstring* exe) {
// Read in optional exe path arg // Read in optional exe path arg
std::wstring exePath; std::wstring exePath;
std::string rawExePath; std::string rawExePath;
@ -135,7 +135,7 @@ std::wstring protocolLaunchPath(std::string protocol, mate::Arguments* args) {
if (!args->GetNext(&rawExePath)) { if (!args->GetNext(&rawExePath)) {
if (!PathService::Get(base::FILE_EXE, &path)) { if (!PathService::Get(base::FILE_EXE, &path)) {
LOG(ERROR) << "Error getting app exe path"; LOG(ERROR) << "Error getting app exe path";
return L""; return false;
} }
// Executable Path // Executable Path
exePath = path.value(); exePath = path.value();
@ -147,19 +147,17 @@ std::wstring protocolLaunchPath(std::string protocol, mate::Arguments* args) {
std::vector<std::string> launchArgs; std::vector<std::string> launchArgs;
args->GetNext(&launchArgs); args->GetNext(&launchArgs);
std::wstring exe = L"\"" + exePath + L"\" "; *exe = L"\"" + exePath + L"\" ";
// Parse launch args into a string of space spearated args // Parse launch args into a string of space spearated args
if (launchArgs.size() != 0) { if (launchArgs.size() != 0) {
std::string launchArgString = ""; std::string launchArgString = base::JoinString(launchArgs, " ");
for (std::string launchArg : launchArgs) {
launchArgString = launchArgString + launchArg + " ";
}
std::wstring wLaunchArgString; std::wstring wLaunchArgString;
wLaunchArgString.assign(launchArgString.begin(), launchArgString.end()); wLaunchArgString.assign(launchArgString.begin(), launchArgString.end());
exe = exe + L"\"" + wLaunchArgString + L"\""; *exe = *exe + L"\"" + wLaunchArgString + L"\"";
} }
return exe + L"\"%1\""; *exe = *exe + L"\"%1\"";
return true;
} }
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol, bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
@ -191,7 +189,10 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
// Default value not set, we can confirm that it is not set // Default value not set, we can confirm that it is not set
return true; return true;
std::wstring exe = protocolLaunchPath(protocol, args); std::wstring exe;
if (!GetProtocolLaunchPath(protocol, args, &exe)) {
return false;
}
if (exe == L"") if (exe == L"")
return false; return false;
if (keyVal == exe) { if (keyVal == exe) {
@ -224,8 +225,8 @@ bool Browser::SetAsDefaultProtocolClient(const std::string& protocol,
if (protocol.empty()) if (protocol.empty())
return false; return false;
std::wstring exe = protocolLaunchPath(protocol, args); std::wstring exe;
if (exe == L"") { if (!GetProtocolLaunchPath(protocol, args, &exe)) {
return false; return false;
} }
@ -258,9 +259,10 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol,
if (protocol.empty()) if (protocol.empty())
return false; return false;
std::wstring exe = protocolLaunchPath(protocol, args); std::wstring exe;
if (exe == L"") if (!GetProtocolLaunchPath(protocol, args, &exe)) {
return false; return false;
}
// Main Registry Key // Main Registry Key
HKEY root = HKEY_CURRENT_USER; HKEY root = HKEY_CURRENT_USER;

View file

@ -454,7 +454,7 @@ Clears the recent documents list.
app to handle `electron://` links, call this method with `electron` as the app to handle `electron://` links, call this method with `electron` as the
parameter. parameter.
* `path` String (optional) _Windows_ - Defaults to `process.execPath` * `path` String (optional) _Windows_ - Defaults to `process.execPath`
* `args` Array (options) _Windows_ - Defaults to an empty array * `args` Array (optional) _Windows_ - Defaults to an empty array
This method sets the current executable as the default handler for a protocol This method sets the current executable as the default handler for a protocol
(aka URI scheme). It allows you to integrate your app deeper into the operating (aka URI scheme). It allows you to integrate your app deeper into the operating
@ -462,7 +462,7 @@ system. Once registered, all links with `your-protocol://` will be opened with
the current executable. The whole link, including protocol, will be passed to the current executable. The whole link, including protocol, will be passed to
your application as a parameter. your application as a parameter.
On windows you can provide optional parameters path, the path to your executable, On Windows you can provide optional parameters path, the path to your executable,
and args, an array of arguments to be passed to your executable when it launches. and args, an array of arguments to be passed to your executable when it launches.
Returns `true` when the call succeeded, otherwise returns `false`. Returns `true` when the call succeeded, otherwise returns `false`.
@ -474,18 +474,22 @@ Please refer to [Apple's documentation][CFBundleURLTypes] for details.
The API uses the Windows Registry and LSSetDefaultHandlerForURLScheme internally. The API uses the Windows Registry and LSSetDefaultHandlerForURLScheme internally.
### `app.removeAsDefaultProtocolClient(protocol)` _macOS_ _Windows_ ### `app.removeAsDefaultProtocolClient(protocol[, path, args])` _macOS_ _Windows_
* `protocol` String - The name of your protocol, without `://`. * `protocol` String - The name of your protocol, without `://`.
* `path` String (optional) _Windows_ - Defaults to `process.execPath`
* `args` Array (optional) _Windows_ - Defaults to an empty array
This method checks if the current executable as the default handler for a This method checks if the current executable as the default handler for a
protocol (aka URI scheme). If so, it will remove the app as the default handler. protocol (aka URI scheme). If so, it will remove the app as the default handler.
Returns `true` when the call succeeded, otherwise returns `false`. Returns `true` when the call succeeded, otherwise returns `false`.
### `app.isDefaultProtocolClient(protocol)` _macOS_ _Windows_ ### `app.isDefaultProtocolClient(protocol[, path, args])` _macOS_ _Windows_
* `protocol` String - The name of your protocol, without `://`. * `protocol` String - The name of your protocol, without `://`.
* `path` String (optional) _Windows_ - Defaults to `process.execPath`
* `args` Array (optional) _Windows_ - Defaults to an empty array
This method checks if the current executable is the default handler for a protocol This method checks if the current executable is the default handler for a protocol
(aka URI scheme). If so, it will return true. Otherwise, it will return false. (aka URI scheme). If so, it will return true. Otherwise, it will return false.