forked from obsproject/obs-browser
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbrowser-mac.mm
113 lines (93 loc) · 2.61 KB
/
browser-mac.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/******************************************************************************
Copyright (C) 2016-2019 by Streamlabs (General Workings Inc)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include "browser-mac.h"
#include <mach-o/dyld.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#import "Foundation/Foundation.h"
#import <Cocoa/Cocoa.h>
std::mutex browserTaskMutex;
std::deque<Task> browserTasks;
bool ExecuteNextBrowserTask()
{
Task nextTask;
{
std::lock_guard<std::mutex> lock(browserTaskMutex);
if (!browserTasks.size())
return false;
nextTask = browserTasks[0];
browserTasks.pop_front();
}
nextTask.func(nextTask.browser);
return true;
}
void ExecuteTask(MessageTask task)
{
dispatch_async(dispatch_get_main_queue(), ^{
task();
});
}
void ExecuteSyncTask(MessageTask task)
{
dispatch_sync(dispatch_get_main_queue(), ^{
task();
});
}
void DoCefMessageLoop(int)
{
dispatch_async(dispatch_get_main_queue(), ^{
CefDoMessageLoopWork();
});
}
void Process()
{
dispatch_async(dispatch_get_main_queue(), ^{
CefDoMessageLoopWork();
});
}
#if 0 // REMOVE_DUPLICATE
void QueueBrowserTask(CefRefPtr<CefBrowser> browser, BrowserFunc func)
{
std::lock_guard<std::mutex> lock(browserTaskMutex);
browserTasks.emplace_back(browser, func);
dispatch_async(dispatch_get_main_queue(), ^{
ExecuteNextBrowserTask();
});
}
#endif
bool isMainThread()
{
return [NSThread isMainThread];
}
std::string getExecutablePath()
{
char path[1024];
uint32_t size = sizeof(path);
_NSGetExecutablePath(path, &size);
return path;
}
bool isHighThanBigSur()
{
char buf[100];
size_t buflen = 100;
if (sysctlbyname("machdep.cpu.brand_string", &buf, &buflen, NULL, 0) <
0)
return false;
NSOperatingSystemVersion OSversion =
[NSProcessInfo processInfo].operatingSystemVersion;
return ((OSversion.majorVersion >= 10 &&
OSversion.minorVersion >= 16) ||
OSversion.majorVersion >= 11) &&
strcmp("Apple M1", buf) != 0;
}