Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not quite working: Posix TZ hotswap #110

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 19 additions & 3 deletions stores/firmwareStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { saveAs } from 'file-saver';
import { mande } from 'mande';
import { defineStore } from 'pinia';
import type { Terminal } from 'xterm';
import { timezones } from '~/types/resources';

import { track } from '@vercel/analytics';
import { useSessionStorage } from '@vueuse/core';
Expand Down Expand Up @@ -178,7 +179,18 @@ export const useFirmwareStore = defineStore('firmware', {
};
const transport = new Transport(this.port, true);
const espLoader = await this.connectEsp32(transport, terminal);
const appContent = await this.fetchBinaryContent(fileName);
let appContent = await this.fetchBinaryContent(fileName, true);
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
// get posix timezone string based on browser locale
const posixTz = timezones[tz as keyof typeof timezones] || 'CST6CDT,M3.2.0,M11.1.0';
appContent.replace('tzplaceholder ', posixTz);
thebentern marked this conversation as resolved.
Show resolved Hide resolved
const sha256 = new Uint8Array(32);
const sha256sum = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(appContent));
new Uint8Array(sha256sum).forEach((byte, index) => {
sha256[index] = byte;
});
appContent += convertToBinaryString(sha256);

const otaContent = await this.fetchBinaryContent(otaFileName);
const littleFsContent = await this.fetchBinaryContent(littleFsFileName);
this.isFlashing = true;
Expand All @@ -201,12 +213,16 @@ export const useFirmwareStore = defineStore('firmware', {
};
await this.startWrite(terminal, espLoader, transport, flashOptions);
},
async fetchBinaryContent(fileName: string): Promise<string> {
async fetchBinaryContent(fileName: string, truncateLast32 = false): Promise<string> {
if (this.selectedFirmware?.zip_url) {
const baseUrl = getCorsFriendyReleaseUrl(this.selectedFirmware.zip_url);
const response = await fetch(`${baseUrl}/${fileName}`);
const blob = await response.blob();
const data = await blob.arrayBuffer();
let data = await blob.arrayBuffer();
debugger
if (truncateLast32)
data = new Uint8Array(data).slice(0, -32);

return convertToBinaryString(new Uint8Array(data));
}
if (this.selectedFile && this.isZipFile) {
Expand Down
Loading