Skip to content

Commit

Permalink
fix(window): get actual background color of window, not webview
Browse files Browse the repository at this point in the history
  • Loading branch information
heapwolf committed Mar 22, 2024
1 parent 8020d31 commit d1435c7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
5 changes: 2 additions & 3 deletions api/stream-relay/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ class PeerWorkerProxy {
constructor (options, port, fn) {
if (!options.isWorkerThread) {
this.#channel = new MessageChannel()
const p = path.join(path.dirname(pathname), 'worker.js')
this.#worker = new window.Worker(p)
this.#worker = new window.Worker(path.join(path.dirname(pathname), 'worker.js'))

this.#worker.addEventListener('error', err => {
throw err
Expand Down Expand Up @@ -251,7 +250,7 @@ class PeerWorkerProxy {
callMainThread (prop, args) {
for (const i in args) {
const arg = args[i]
if (!arg.peerId) continue
if (!arg?.peerId) continue
args[i] = { ...arg }
delete args[i].localPeer // don't copy this over
}
Expand Down
1 change: 1 addition & 0 deletions src/cli/templates.hh
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ constexpr auto gHelloWorld = R"HTML(
justify-content: center;
align-content: center;
font-family: helvetica;
overflow: hidden;
}
</style>
</head>
Expand Down
23 changes: 6 additions & 17 deletions src/window/apple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1068,10 +1068,10 @@ - (void) webView: (WKWebView*) webView
webview.wantsLayer = YES;
webview.layer.backgroundColor = [NSColor clearColor].CGColor;

/* [webview
[webview
setValue: [NSNumber numberWithBool: YES]
forKey: @"drawsTransparentBackground"
]; */
];

// [webview registerForDraggedTypes:
// [NSArray arrayWithObject:NSPasteboardTypeFileURL]];
Expand Down Expand Up @@ -1541,24 +1541,13 @@ - (void) webView: (WKWebView*) webView
String Window::getBackgroundColor () {
if (!this->window) return std::string("");

CALayer *contentLayer = this->window.contentView.layer;
CGColorRef backgroundColorRef = contentLayer.backgroundColor;
NSColor *backgroundColor = [NSColor colorWithCGColor:backgroundColorRef];

NSColor *backgroundColor = [this->window backgroundColor];
NSColor *rgbColor = [backgroundColor colorUsingColorSpace:[NSColorSpace sRGBColorSpace]];

CGFloat red, green, blue, alpha;
[rgbColor getRed:&red green:&green blue:&blue alpha:&alpha];

NSString *colorString = [NSString
stringWithFormat:
@"rgba(%d, %d, %d, %f)",
(int)(red * 255),
(int)(green * 255),
(int)(blue * 255),
alpha
];
CGFloat r, g, b, a;
[rgbColor getRed:&r green:&g blue:&b alpha:&a];

NSString *colorString = [NSString stringWithFormat: @"rgba(%.0f,%.0f,%.0f,%.1f)", r * 255, g * 255, b * 255, a];
return [colorString UTF8String];
}

Expand Down

0 comments on commit d1435c7

Please sign in to comment.