Dark mode implemented
This commit is contained in:
@@ -13,18 +13,23 @@
|
||||
#import <WebKit/_WKRemoteObjectInterface.h>
|
||||
#import <WebKit/_WKRemoteObjectRegistry.h>
|
||||
#import <WebKit/_WKProcessPoolConfiguration.h>
|
||||
#import <WebKit/_WKUserStyleSheet.h>
|
||||
|
||||
#import <WebKit/WKProcessPoolPrivate.h>
|
||||
#import <WebKit/WKWebViewPrivate.h>
|
||||
#import <WebKit/WKWebViewConfigurationPrivate.h>
|
||||
#import <WebKit/WKUserContentControllerPrivate.h>
|
||||
|
||||
@interface SBRProcessBundleBridge () <SBRWebProcessDelegate>
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBRProcessBundleBridge {
|
||||
WKWebView *_webView;
|
||||
WKWebView *_webView;
|
||||
WKWebViewConfiguration *_webViewConfiguration;
|
||||
id<SBRWebProcessProxy> _webProcessProxy;
|
||||
|
||||
_WKUserStyleSheet *_darkModeStyleSheet;
|
||||
}
|
||||
|
||||
- (WKWebView *)webView
|
||||
@@ -58,6 +63,7 @@
|
||||
[[webView _remoteObjectRegistry] registerExportedObject:self interface:delegateInterface];
|
||||
|
||||
_webView = webView;
|
||||
_webViewConfiguration = configuration;
|
||||
}
|
||||
|
||||
return _webView;
|
||||
@@ -90,4 +96,23 @@
|
||||
[_webProcessProxy setAllScriptsAllowed:allowAllScripts];
|
||||
}
|
||||
|
||||
- (void)setDarkModeEnabled:(BOOL)darkModeEnabled
|
||||
{
|
||||
_darkModeEnabled = darkModeEnabled;
|
||||
|
||||
WKUserContentController *userContentController = [_webViewConfiguration userContentController];
|
||||
|
||||
if (darkModeEnabled) {
|
||||
if (!_darkModeStyleSheet) {
|
||||
NSURL *styleSheetURL = [[NSBundle mainBundle] URLForResource:@"darkmode" withExtension:@"css"];
|
||||
NSString *styleSheetSource = [NSString stringWithContentsOfURL:styleSheetURL encoding:NSUTF8StringEncoding error:nil];
|
||||
_darkModeStyleSheet = [[_WKUserStyleSheet alloc] initWithSource:styleSheetSource forMainFrameOnly:NO];
|
||||
}
|
||||
|
||||
[userContentController _addUserStyleSheet:_darkModeStyleSheet];
|
||||
} else if (_darkModeStyleSheet) {
|
||||
[userContentController _removeUserStyleSheet:_darkModeStyleSheet];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user