b994ae8174
OS X's application termination doesn't work very well with C++ message loops. Especially when we return NSTerminateLater for shouldTerminate, it would be impossible for the C++ message loop to quit, because unless we explictly let NSApp terminate the application, the message loop would think the application is not terminated and will run forever. The fix is to simply ignore the Cocoa's application termination request and let the C++ message loop deal with it compeletey. But we had the side effect that atom-shell would always cancel OS X's shutdown request, this is also the approach chosen by Chromium. Fixes #229. Fixes atom/atom#1864.
64 lines
1.7 KiB
C++
64 lines
1.7 KiB
C++
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "atom/browser/browser.h"
|
|
|
|
#include <windows.h>
|
|
|
|
#include "base/base_paths.h"
|
|
#include "base/file_version_info.h"
|
|
#include "base/files/file_path.h"
|
|
#include "base/memory/scoped_ptr.h"
|
|
#include "base/path_service.h"
|
|
#include "base/strings/utf_string_conversions.h"
|
|
#include "atom/common/atom_version.h"
|
|
|
|
namespace atom {
|
|
|
|
namespace {
|
|
|
|
BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
|
|
DWORD target_process_id = *reinterpret_cast<DWORD*>(param);
|
|
DWORD process_id = 0;
|
|
|
|
GetWindowThreadProcessId(hwnd, &process_id);
|
|
if (process_id == target_process_id) {
|
|
SetFocus(hwnd);
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void Browser::Focus() {
|
|
// On Windows we just focus on the first window found for this process.
|
|
DWORD pid = GetCurrentProcessId();
|
|
EnumWindows(&WindowsEnumerationHandler, reinterpret_cast<LPARAM>(&pid));
|
|
}
|
|
|
|
std::string Browser::GetExecutableFileVersion() const {
|
|
base::FilePath path;
|
|
if (PathService::Get(base::FILE_EXE, &path)) {
|
|
scoped_ptr<FileVersionInfo> version_info(
|
|
FileVersionInfo::CreateFileVersionInfo(path));
|
|
return UTF16ToUTF8(version_info->product_version());
|
|
}
|
|
|
|
return ATOM_VERSION_STRING;
|
|
}
|
|
|
|
std::string Browser::GetExecutableFileProductName() const {
|
|
base::FilePath path;
|
|
if (PathService::Get(base::FILE_EXE, &path)) {
|
|
scoped_ptr<FileVersionInfo> version_info(
|
|
FileVersionInfo::CreateFileVersionInfo(path));
|
|
return UTF16ToUTF8(version_info->product_name());
|
|
}
|
|
|
|
return "Atom-Shell";
|
|
}
|
|
|
|
} // namespace atom
|