Commit 546101a5 authored by jackhou's avatar jackhou Committed by Commit bot

[Mac] Localize app shims with the OS preferred language.

Previously this created an english localization folder and assumed OSX
would use it since it's the only one available. However, when english is
not one of the preferred languages, the metadata for the shim bundle
would report its filename as the display name. The metadata is used by
Spotlight, so the user would be unable to search for the app.
See the bug for more details.

With this CL, we still only create one localization folder, but use the
most preferred language reported by the OS.

This also deletes any existing shims before creating new ones.

BUG=482658

Review URL: https://codereview.chromium.org/1137373003

Cr-Commit-Position: refs/heads/master@{#330038}
parent 23b8fad5
......@@ -700,6 +700,9 @@ size_t WebAppShortcutCreator::CreateShortcutsIn(
return succeeded;
}
// Ensure the copy does not merge with stale info.
base::DeleteFile(dst_path.Append(app_name), true);
if (!base::CopyDirectory(staging_path, dst_path, true)) {
LOG(ERROR) << "Copying app to dst path: " << dst_path.value()
<< " failed";
......@@ -798,7 +801,6 @@ void WebAppShortcutCreator::DeleteShortcuts() {
bool WebAppShortcutCreator::UpdateShortcuts() {
std::vector<base::FilePath> paths;
base::DeleteFile(GetInternalShortcutPath(), true);
paths.push_back(app_data_dir_);
// Try to update the copy under /Applications. If that does not exist, check
......@@ -807,10 +809,8 @@ bool WebAppShortcutCreator::UpdateShortcuts() {
if (app_path.empty() || !base::PathExists(app_path))
app_path = GetAppBundleById(GetBundleIdentifier());
if (!app_path.empty()) {
base::DeleteFile(app_path, true);
if (!app_path.empty())
paths.push_back(app_path.DirName());
}
size_t success_count = CreateShortcutsIn(paths);
if (success_count == 0)
......@@ -897,9 +897,13 @@ bool WebAppShortcutCreator::UpdatePlist(const base::FilePath& app_path) const {
bool WebAppShortcutCreator::UpdateDisplayName(
const base::FilePath& app_path) const {
// OSX searches for the best language in the order of preferred languages.
// Since we only have one localization directory, it will choose this one.
base::FilePath localized_dir = GetResourcesPath(app_path).Append("en.lproj");
// Localization is used to display the app name (rather than the bundle
// filename). OSX searches for the best language in the order of preferred
// languages, but one of them must be found otherwise it will default to
// the filename.
NSString* language = [[NSLocale preferredLanguages] objectAtIndex:0];
base::FilePath localized_dir = GetResourcesPath(app_path).Append(
base::SysNSStringToUTF8(language) + ".lproj");
if (!base::CreateDirectory(localized_dir))
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment