Skip to content

Commit 97ef782

Browse files
authored
Fixed Safari live view bugs
Fixed Safari live view
2 parents 370eba1 + c09eb39 commit 97ef782

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

live-view/live-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ if (isMobile) {
599599
// share live view link
600600

601601
const link = createLink({
602-
dir: treeLoc,
602+
dir: selectedFile.dir.split(','),
603603
file: selectedFile,
604604
openLive: true
605605
});

utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const body = document.body,
6868

6969

7070
// version
71-
const version = '3.0.0';
71+
const version = '3.0.1';
7272
versionEl.innerText = version;
7373

7474
let logVersion = () => {

worker/client-channel.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
// update worker name when updating worker
7-
const WORKER_NAME = 'codeit-worker-v506';
7+
const WORKER_NAME = 'codeit-worker-v518';
88

99

1010
// internal paths
@@ -24,6 +24,9 @@ const INTERNAL_PATHS = {
2424
}
2525

2626

27+
const isSafari = self.navigator.userAgent.toLowerCase().includes('safari');
28+
29+
2730
// key : value
2831
// live view client ID: codeit client ID
2932
let liveViewClients = {};
@@ -196,7 +199,7 @@ function handleFetchRequest(request, event) {
196199
|| (getPathType(request.referrer) === 'run')) { // if fetch originated in live view
197200

198201
if (enableDevLogs) {
199-
console.debug('[ServiceWorker] Intercepted live fetch', request.url, request);
202+
console.debug('[ServiceWorker] Intercepted live fetch', event);
200203
}
201204

202205

@@ -206,17 +209,29 @@ function handleFetchRequest(request, event) {
206209

207210
const liveFramePath = INTERNAL_PATHS.relLivePath;
208211

212+
let liveViewClientId = event.resultingClientId ?? event.targetClientId;
213+
209214
// if codeit client is creating a new live view
210215
if (url.endsWith(liveFramePath)
211-
&& event.resultingClientId) {
216+
&& liveViewClientId) {
212217

213218
// add live view to client array
214-
215-
const liveViewClientId = event.resultingClientId;
216219

217220
parentClientId = parentClientId.slice(0, -1);
218221
clientId = parentClientId;
219222

223+
// if on safari
224+
if (isSafari && event.targetClientId) {
225+
226+
// add 1 to live view client id
227+
let splitId = liveViewClientId.split('-');
228+
229+
splitId[1] = Number(splitId[1]) + 1;
230+
231+
liveViewClientId = splitId.join('-');
232+
233+
}
234+
220235
// pair live view client ID
221236
// with codeit client ID
222237
// in client array

worker/worker-channel.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ async function setupWorkerChannel() {
1919
await workerInstallPromise;
2020

2121

22+
let numOfRequests = 0;
23+
2224
async function pingWorkerForClientId() {
2325

2426
// get client ID from worker
@@ -30,14 +32,23 @@ async function setupWorkerChannel() {
3032
resp = '';
3133
console.log('%c[Client] Pinged ServiceWorker for installation', 'color: #80868b');
3234
}
33-
34-
if (!resp || !resp.clientId) {
35+
36+
if (numOfRequests < 500) {
3537

36-
return await pingWorkerForClientId();
38+
if (!resp || !resp.clientId) {
39+
40+
numOfRequests++;
41+
return await pingWorkerForClientId();
42+
43+
} else {
44+
45+
return resp.clientId;
46+
47+
}
3748

3849
} else {
3950

40-
return resp.clientId;
51+
return null;
4152

4253
}
4354

@@ -48,7 +59,7 @@ async function setupWorkerChannel() {
4859
workerInstallPromise = pingWorkerForClientId();
4960

5061
workerClientId = await workerInstallPromise;
51-
62+
5263
workerInstallPromise = null;
5364

5465

@@ -58,7 +69,7 @@ async function setupWorkerChannel() {
5869

5970
// add worker channel listener
6071
workerChannel.addEventListener('message', async (event) => {
61-
72+
6273
// if message is for current client
6374
if (event.data.toClient === workerClientId) {
6475

0 commit comments

Comments
 (0)