2016-04-24 12:13:46 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/api/atom_api_system_preferences.h"
|
|
|
|
|
2016-04-25 05:25:14 +00:00
|
|
|
#include <map>
|
|
|
|
|
2016-04-25 03:35:09 +00:00
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2016-04-25 05:25:14 +00:00
|
|
|
#include "base/strings/sys_string_conversions.h"
|
|
|
|
|
2016-04-24 12:13:46 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2016-04-25 05:25:14 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
int g_next_id = 0;
|
|
|
|
|
|
|
|
// The map to convert |id| to |int|.
|
|
|
|
std::map<int, id> g_id_map;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
int SystemPreferences::SubscribeNotification(const std::string& name,
|
|
|
|
const base::Closure& callback) {
|
|
|
|
int request_id = g_next_id++;
|
|
|
|
__block base::Closure copied_callback = callback;
|
|
|
|
g_id_map[request_id] = [[NSDistributedNotificationCenter defaultCenter]
|
|
|
|
addObserverForName:base::SysUTF8ToNSString(name)
|
|
|
|
object:nil
|
|
|
|
queue:nil
|
|
|
|
usingBlock:^(NSNotification* notification) {
|
|
|
|
copied_callback.Run();
|
|
|
|
}
|
|
|
|
];
|
|
|
|
return request_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemPreferences::UnsubscribeNotification(int request_id) {
|
|
|
|
auto iter = g_id_map.find(request_id);
|
|
|
|
if (iter != g_id_map.end()) {
|
|
|
|
id observer = iter->second;
|
|
|
|
[[NSDistributedNotificationCenter defaultCenter] removeObserver:observer];
|
|
|
|
g_id_map.erase(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-25 03:35:09 +00:00
|
|
|
bool SystemPreferences::IsDarkMode() {
|
|
|
|
NSString* mode = [[NSUserDefaults standardUserDefaults]
|
|
|
|
stringForKey:@"AppleInterfaceStyle"];
|
|
|
|
return [mode isEqualToString:@"Dark"];
|
|
|
|
}
|
2016-04-24 12:13:46 +00:00
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|