Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/calm-bees-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@lynx-js/web-worker-runtime": patch
"@lynx-js/web-core": patch
---

feat: add pixelRatio of SystemInfo, now you can use `SystemInfo.pixelRatio`.
2 changes: 2 additions & 0 deletions packages/web-platform/web-core/src/uiThread/bootWorkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function createMainWorker() {
mode: 'main',
toUIThread: channelToMainThread.port2,
toPeerThread: channelMainThreadWithBackground.port1,
pixelRatio: window.devicePixelRatio,
};

mainThreadWorker.postMessage(mainThreadMessage, [
Expand Down Expand Up @@ -73,6 +74,7 @@ function createBackgroundWorker(
mode: 'background',
toUIThread: channelToBackground.port2,
toPeerThread: channelMainThreadWithBackground.port2,
pixelRatio: window.devicePixelRatio,
};
backgroundThreadWorker.postMessage(backgroundThreadMessage, [
channelToBackground.port2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { root, useEffect, useState } from '@lynx-js/react';
function App() {
const [color, setColor] = useState('pink');
useEffect(() => {
if (SystemInfo.platform === 'web') {
if (
SystemInfo.platform === 'web' && typeof SystemInfo.pixelRatio === 'number'
) {
setColor('green');
}
}, []);
Expand Down
5 changes: 4 additions & 1 deletion packages/web-platform/web-worker-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ export interface WorkerStartMessage {
mode: 'main' | 'background';
toPeerThread: MessagePort;
toUIThread: MessagePort;
pixelRatio: number;
}

self.onmessage = (ev) => {
const { mode, toPeerThread, toUIThread } = ev.data as WorkerStartMessage;
const { mode, toPeerThread, toUIThread, pixelRatio } = ev
.data as WorkerStartMessage;
(globalThis as any).SystemInfo.pixelRatio = pixelRatio;
Comment thread
PupilTong marked this conversation as resolved.
if (mode === 'main') {
startMainThread(toUIThread, toPeerThread);
} else {
Expand Down