Move isAeroGlassEnabled and isDarkMode to systemPreferences

This commit is contained in:
Cheng Zhao 2016-04-25 12:35:09 +09:00
parent d72a0e452f
commit ddd8eae661
8 changed files with 46 additions and 35 deletions

View file

@ -41,7 +41,6 @@
#if defined(OS_WIN) #if defined(OS_WIN)
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "ui/base/win/shell.h"
#endif #endif
using atom::Browser; using atom::Browser;
@ -382,12 +381,6 @@ std::string App::GetLocale() {
return l10n_util::GetApplicationLocale(""); return l10n_util::GetApplicationLocale("");
} }
#if defined(OS_WIN)
bool App::IsAeroGlassEnabled() {
return ui::win::IsAeroGlassEnabled();
}
#endif
bool App::MakeSingleInstance( bool App::MakeSingleInstance(
const ProcessSingleton::NotificationCallback& callback) { const ProcessSingleton::NotificationCallback& callback) {
if (process_singleton_.get()) if (process_singleton_.get())
@ -471,13 +464,10 @@ void App::BuildPrototype(
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
.SetMethod("hide", base::Bind(&Browser::Hide, browser)) .SetMethod("hide", base::Bind(&Browser::Hide, browser))
.SetMethod("show", base::Bind(&Browser::Show, browser)) .SetMethod("show", base::Bind(&Browser::Show, browser))
.SetMethod("isDarkMode",
base::Bind(&Browser::IsDarkMode, browser))
#endif #endif
#if defined(OS_WIN) #if defined(OS_WIN)
.SetMethod("setUserTasks", .SetMethod("setUserTasks",
base::Bind(&Browser::SetUserTasks, browser)) base::Bind(&Browser::SetUserTasks, browser))
.SetMethod("isAeroGlassEnabled", &App::IsAeroGlassEnabled)
#endif #endif
.SetMethod("setPath", &App::SetPath) .SetMethod("setPath", &App::SetPath)
.SetMethod("getPath", &App::GetPath) .SetMethod("getPath", &App::GetPath)

View file

@ -114,10 +114,6 @@ class App : public AtomBrowserClient::Delegate,
const net::CompletionCallback& callback); const net::CompletionCallback& callback);
#endif #endif
#if defined(OS_WIN)
bool IsAeroGlassEnabled();
#endif
scoped_ptr<ProcessSingleton> process_singleton_; scoped_ptr<ProcessSingleton> process_singleton_;
#if defined(USE_NSS_CERTS) #if defined(USE_NSS_CERTS)

View file

@ -7,6 +7,10 @@
#include "atom/common/node_includes.h" #include "atom/common/node_includes.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#if defined(OS_WIN)
#include "ui/base/win/shell.h"
#endif
namespace atom { namespace atom {
namespace api { namespace api {
@ -18,6 +22,18 @@ SystemPreferences::SystemPreferences(v8::Isolate* isolate) {
SystemPreferences::~SystemPreferences() { SystemPreferences::~SystemPreferences() {
} }
#if defined(OS_WIN)
bool SystemPreferences::IsAeroGlassEnabled() {
return ui::win::IsAeroGlassEnabled();
}
#endif
#if !defined(OS_MACOSX)
bool SystemPreferences::IsDarkMode() {
return false;
}
#endif
// static // static
mate::Handle<SystemPreferences> SystemPreferences::Create( mate::Handle<SystemPreferences> SystemPreferences::Create(
v8::Isolate* isolate) { v8::Isolate* isolate) {
@ -27,7 +43,11 @@ mate::Handle<SystemPreferences> SystemPreferences::Create(
// static // static
void SystemPreferences::BuildPrototype( void SystemPreferences::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) { v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype); mate::ObjectTemplateBuilder(isolate, prototype)
#if defined(OS_WIN)
.SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
#endif
.SetMethod("isDarkMode", &SystemPreferences::IsDarkMode);
} }
} // namespace api } // namespace api

View file

@ -19,6 +19,11 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences> {
static void BuildPrototype(v8::Isolate* isolate, static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype); v8::Local<v8::ObjectTemplate> prototype);
#if defined(OS_WIN)
bool IsAeroGlassEnabled();
#endif
bool IsDarkMode();
protected: protected:
explicit SystemPreferences(v8::Isolate* isolate); explicit SystemPreferences(v8::Isolate* isolate);
~SystemPreferences() override; ~SystemPreferences() override;

View file

@ -4,11 +4,19 @@
#include "atom/browser/api/atom_api_system_preferences.h" #include "atom/browser/api/atom_api_system_preferences.h"
#import <Cocoa/Cocoa.h>
namespace atom { namespace atom {
namespace api { namespace api {
#if defined(OS_MACOSX)
bool SystemPreferences::IsDarkMode() {
NSString* mode = [[NSUserDefaults standardUserDefaults]
stringForKey:@"AppleInterfaceStyle"];
return [mode isEqualToString:@"Dark"];
}
#endif
} // namespace api } // namespace api

View file

@ -89,9 +89,6 @@ class Browser : public WindowListObserver {
// Show the application. // Show the application.
void Show(); void Show();
// Check if the system is in Dark Mode.
bool IsDarkMode();
// Bounce the dock icon. // Bounce the dock icon.
enum BounceType { enum BounceType {
BOUNCE_CRITICAL = 0, BOUNCE_CRITICAL = 0,

View file

@ -27,11 +27,6 @@ void Browser::Show() {
[[AtomApplication sharedApplication] unhide:nil]; [[AtomApplication sharedApplication] unhide:nil];
} }
bool Browser::IsDarkMode() {
NSString *mode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
return [mode isEqualToString: @"Dark"];
}
void Browser::AddRecentDocument(const base::FilePath& path) { void Browser::AddRecentDocument(const base::FilePath& path) {
NSString* path_string = base::mac::FilePathToNSString(path); NSString* path_string = base::mac::FilePathToNSString(path);
if (!path_string) if (!path_string)

View file

@ -1,8 +1,7 @@
'use strict' 'use strict'
const deprecate = require('electron').deprecate const electron = require('electron')
const session = require('electron').session const {deprecate, session, Menu} = electron
const Menu = require('electron').Menu
const EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
const bindings = process.atomBinding('app') const bindings = process.atomBinding('app')
@ -65,39 +64,40 @@ for (i = 0, len = ref1.length; i < len; i++) {
} }
// Deprecated. // Deprecated.
app.getHomeDir = deprecate('app.getHomeDir', 'app.getPath', function () { app.getHomeDir = deprecate('app.getHomeDir', 'app.getPath', function () {
return this.getPath('home') return this.getPath('home')
}) })
app.getDataPath = deprecate('app.getDataPath', 'app.getPath', function () { app.getDataPath = deprecate('app.getDataPath', 'app.getPath', function () {
return this.getPath('userData') return this.getPath('userData')
}) })
app.setDataPath = deprecate('app.setDataPath', 'app.setPath', function (path) { app.setDataPath = deprecate('app.setDataPath', 'app.setPath', function (path) {
return this.setPath('userData', path) return this.setPath('userData', path)
}) })
app.resolveProxy = deprecate('app.resolveProxy', 'session.defaultSession.resolveProxy', function (url, callback) { app.resolveProxy = deprecate('app.resolveProxy', 'session.defaultSession.resolveProxy', function (url, callback) {
return session.defaultSession.resolveProxy(url, callback) return session.defaultSession.resolveProxy(url, callback)
}) })
deprecate.rename(app, 'terminate', 'quit') deprecate.rename(app, 'terminate', 'quit')
deprecate.event(app, 'finish-launching', 'ready', function () { deprecate.event(app, 'finish-launching', 'ready', function () {
// give default app a chance to setup default menu. // give default app a chance to setup default menu.
setImmediate(() => { setImmediate(() => {
this.emit('finish-launching') this.emit('finish-launching')
}) })
}) })
deprecate.event(app, 'activate-with-no-open-windows', 'activate', function (event, hasVisibleWindows) { deprecate.event(app, 'activate-with-no-open-windows', 'activate', function (event, hasVisibleWindows) {
if (!hasVisibleWindows) { if (!hasVisibleWindows) {
return this.emit('activate-with-no-open-windows', event) return this.emit('activate-with-no-open-windows', event)
} }
}) })
deprecate.event(app, 'select-certificate', 'select-client-certificate') deprecate.event(app, 'select-certificate', 'select-client-certificate')
if (process.platform === 'win32') {
app.isAeroGlassEnabled = deprecate('app.isAeroGlassEnabled', 'systemPreferences.isAeroGlassEnabled', function () {
return electron.systemPreferences.isAeroGlassEnabled();
})
} else if (process.platform === 'darwin') {
app.isDarkMode = deprecate('app.isDarkMode', 'systemPreferences.isDarkMode', function () {
return electron.systemPreferences.isDarkMode();
})
}
// Wrappers for native classes. // Wrappers for native classes.
var wrapDownloadItem = function (downloadItem) { var wrapDownloadItem = function (downloadItem) {