fix: disable toggle during deploy, SSR guard for matchMedia, reactive isDesktop, safe deployBinary guard
This commit is contained in:
parent
185fed636e
commit
01f68d354a
|
|
@ -51,9 +51,18 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (typeof window === 'undefined') return;
|
||||||
|
const mq = window.matchMedia('(min-width: 1024px)');
|
||||||
|
isDesktop = mq.matches;
|
||||||
|
const handler = (e: MediaQueryListEvent) => { isDesktop = e.matches; };
|
||||||
|
mq.addEventListener('change', handler);
|
||||||
|
return () => mq.removeEventListener('change', handler);
|
||||||
|
});
|
||||||
|
|
||||||
function detectMode() {
|
function detectMode() {
|
||||||
usbSupported = typeof navigator !== 'undefined' && 'serial' in navigator;
|
usbSupported = typeof navigator !== 'undefined' && 'serial' in navigator;
|
||||||
isDesktop = window.matchMedia('(min-width: 1024px)').matches;
|
isDesktop = typeof window !== 'undefined' && window.matchMedia('(min-width: 1024px)').matches;
|
||||||
if (usbSupported && isDesktop) {
|
if (usbSupported && isDesktop) {
|
||||||
deployMode = 'usb';
|
deployMode = 'usb';
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -189,8 +198,8 @@
|
||||||
completedChunks = p.completedChunks;
|
completedChunks = p.completedChunks;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (deployMode === 'usb' && res.binary_content) {
|
if (deployMode === 'usb' && res.binary_content && typeof deployer.deployBinary === 'function') {
|
||||||
await deployer.deployBinary!(res.binary_content, onProgress);
|
await deployer.deployBinary(res.binary_content, onProgress);
|
||||||
} else {
|
} else {
|
||||||
await deployer.deployHex(res.hex_content, onProgress);
|
await deployer.deployHex(res.hex_content, onProgress);
|
||||||
}
|
}
|
||||||
|
|
@ -293,11 +302,15 @@
|
||||||
class="mode-btn"
|
class="mode-btn"
|
||||||
class:active={deployMode === 'ble'}
|
class:active={deployMode === 'ble'}
|
||||||
onclick={() => handleModeChange('ble')}
|
onclick={() => handleModeChange('ble')}
|
||||||
|
disabled={deployState !== 'idle' && deployState !== 'error' && deployState !== 'success'}
|
||||||
|
aria-pressed={deployMode === 'ble'}
|
||||||
>BLE</button>
|
>BLE</button>
|
||||||
<button
|
<button
|
||||||
class="mode-btn"
|
class="mode-btn"
|
||||||
class:active={deployMode === 'usb'}
|
class:active={deployMode === 'usb'}
|
||||||
onclick={() => handleModeChange('usb')}
|
onclick={() => handleModeChange('usb')}
|
||||||
|
disabled={deployState !== 'idle' && deployState !== 'error' && deployState !== 'success'}
|
||||||
|
aria-pressed={deployMode === 'usb'}
|
||||||
>USB</button>
|
>USB</button>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue