Skip to content

Commit

Permalink
format automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
cookiell546 committed Nov 7, 2024
1 parent b60622c commit 1c32e26
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 61 deletions.
12 changes: 6 additions & 6 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ export default [
{
languageOptions: {
globals: {
...globals.browser
...globals.browser,
},
ecmaVersion: 2022,
sourceType: "module"
sourceType: "module",
},
rules: {
indent: ["error", 4],
"linebreak-style": ["error", "unix"],
quotes: ["error", "double"],
semi: ["error", "always"],
"no-unused-vars": ["error", {caughtErrors: "none"}],
"no-var": ["error"]
}
}
"no-unused-vars": ["error", { caughtErrors: "none" }],
"no-var": ["error"],
},
},
];
16 changes: 12 additions & 4 deletions static/js/redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const redirects = new Map([
["/faq#dns", "/faq#custom-dns"],
["/faq#when-devices", "/faq#future-devices"],


["/features#usb-c-port-control", "/features#usb-c-port-and-pogo-pins-control"],

["/hiring#qualitifations", "/hiring#qualifications"],
Expand Down Expand Up @@ -55,8 +54,14 @@ const redirects = new Map([
["/releases#blueline-beta", "/faq#legacy-devices"],

// legacy servers
["/articles/grapheneos-servers#apps.grapheneos.org", "/articles/grapheneos-servers#releases.grapheneos.org"],
["/articles/grapheneos-servers#time.grapheneos.org", "/articles/grapheneos-servers#grapheneos.network"],
[
"/articles/grapheneos-servers#apps.grapheneos.org",
"/articles/grapheneos-servers#releases.grapheneos.org",
],
[
"/articles/grapheneos-servers#time.grapheneos.org",
"/articles/grapheneos-servers#grapheneos.network",
],

// preserve links to CLI install guide from when it was /install
["/install/#prerequisites", "/install/cli#prerequisites"],
Expand All @@ -76,7 +81,10 @@ const redirects = new Map([
["/install/#post-installation", "/install/cli#post-installation"],
["/install/#booting", "/install/cli#booting"],
["/install/#disabling-oem-unlocking", "/install/cli#disabling-oem-unlocking"],
["/install/#replacing-grapheneos-with-the-stock-os", "/install/cli#replacing-grapheneos-with-the-stock-os"],
[
"/install/#replacing-grapheneos-with-the-stock-os",
"/install/cli#replacing-grapheneos-with-the-stock-os",
],
["/install/#further-information", "/install/cli#further-information"],
["/install/web#connecting-phone", "/install/web#connecting-device"],
["/install/cli#connecting-phone", "/install/cli#connecting-device"],
Expand Down
76 changes: 52 additions & 24 deletions static/js/releases.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT

const baseUrl = "https://releases.grapheneos.org/";
const devices = ["comet", "komodo", "caiman", "tokay", "akita", "husky", "shiba", "felix", "tangorpro", "lynx", "cheetah", "panther", "bluejay", "raven", "oriole", "barbet", "redfin", "bramble", "sunfish", "coral", "flame"];
const devices = [
"comet",
"komodo",
"caiman",
"tokay",
"akita",
"husky",
"shiba",
"felix",
"tangorpro",
"lynx",
"cheetah",
"panther",
"bluejay",
"raven",
"oriole",
"barbet",
"redfin",
"bramble",
"sunfish",
"coral",
"flame",
];
const legacyFactoryDevices = new Set(["sunfish", "coral", "flame"]);
const channels = ["stable", "beta", "alpha"];
const delayMs = 1000 * 60 * 5;
Expand All @@ -11,29 +33,35 @@ async function updateReleases() {

for (const channel of channels) {
for (const device of devices) {
requests.push(fetch(`${baseUrl}${device}-${channel}`).then(response => {
if (!response.ok) {
return Promise.reject();
}
return response.text();
}).then(text => {
const metadata = text.trim().split(" ");

const factoryFormat = legacyFactoryDevices.has(device) ? "factory" : "install";
const factoryFilename = `${device}-${factoryFormat}-${metadata[0]}.zip`;
const factoryUrl = baseUrl + factoryFilename;

const updateFilename = `${device}-ota_update-${metadata[0]}.zip`;
const updateUrl = baseUrl + updateFilename;

const release = document.getElementById(`${device}-${channel}`);
const links = release.getElementsByTagName("a");

links[0].setAttribute("href", "#" + metadata[0]);
links[1].setAttribute("href", factoryUrl);
links[2].setAttribute("href", factoryUrl + ".sig");
links[3].setAttribute("href", updateUrl);
}));
requests.push(
fetch(`${baseUrl}${device}-${channel}`)
.then((response) => {
if (!response.ok) {
return Promise.reject();
}
return response.text();
})
.then((text) => {
const metadata = text.trim().split(" ");

const factoryFormat = legacyFactoryDevices.has(device)
? "factory"
: "install";
const factoryFilename = `${device}-${factoryFormat}-${metadata[0]}.zip`;
const factoryUrl = baseUrl + factoryFilename;

const updateFilename = `${device}-ota_update-${metadata[0]}.zip`;
const updateUrl = baseUrl + updateFilename;

const release = document.getElementById(`${device}-${channel}`);
const links = release.getElementsByTagName("a");

links[0].setAttribute("href", "#" + metadata[0]);
links[1].setAttribute("href", factoryUrl);
links[2].setAttribute("href", factoryUrl + ".sig");
links[3].setAttribute("href", updateUrl);
}),
);
}
}

Expand Down
107 changes: 80 additions & 27 deletions static/js/web-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const Buttons = {
DOWNLOAD_RELEASE: "download-release",
FLASH_RELEASE: "flash-release",
LOCK_BOOTLOADER: "lock-bootloader",
REMOVE_CUSTOM_KEY: "remove-custom-key"
REMOVE_CUSTOM_KEY: "remove-custom-key",
};

const InstallerState = {
DOWNLOADING_RELEASE: 0x1,
INSTALLING_RELEASE: 0x2
INSTALLING_RELEASE: 0x2,
};

let wakeLock = null;
Expand Down Expand Up @@ -107,7 +107,7 @@ class BlobStore {
let db = event.target.result;
db.createObjectStore("files", { keyPath: "name" });
/* no index needed for such a small database */
}
},
);
}
}
Expand All @@ -122,7 +122,7 @@ class BlobStore {
async loadFile(name) {
try {
let obj = await this._wrapReq(
this.db.transaction("files").objectStore("files").get(name)
this.db.transaction("files").objectStore("files").get(name),
);
return obj.blob;
} catch (error) {
Expand All @@ -144,9 +144,7 @@ class BlobStore {
await this.saveFile(filename, blob);
console.log("File saved");
} else {
console.log(
`Loaded ${filename} from blob store, skipping download`
);
console.log(`Loaded ${filename} from blob store, skipping download`);
}

return blob;
Expand Down Expand Up @@ -199,7 +197,7 @@ async function unlockBootloader(setProgress) {

// Trying to unlock when the bootloader is already unlocked results in a FAIL,
// so don't try to do it.
if (await device.getVariable("unlocked") === "yes") {
if ((await device.getVariable("unlocked")) === "yes") {
return "Bootloader is already unlocked.";
}

Expand All @@ -218,11 +216,52 @@ async function unlockBootloader(setProgress) {
return "Bootloader unlocked.";
}

const supportedDevices = ["comet", "komodo", "caiman", "tokay", "akita", "husky", "shiba", "felix", "tangorpro", "lynx", "cheetah", "panther", "bluejay", "raven", "oriole", "barbet", "redfin", "bramble", "sunfish", "coral", "flame"];
const supportedDevices = [
"comet",
"komodo",
"caiman",
"tokay",
"akita",
"husky",
"shiba",
"felix",
"tangorpro",
"lynx",
"cheetah",
"panther",
"bluejay",
"raven",
"oriole",
"barbet",
"redfin",
"bramble",
"sunfish",
"coral",
"flame",
];

const legacyQualcommDevices = ["sunfish", "coral", "flame"];

const day1SnapshotCancelDevices = ["comet", "komodo", "caiman", "tokay", "akita", "husky", "shiba", "felix", "tangorpro", "lynx", "cheetah", "panther", "bluejay", "raven", "oriole", "barbet", "redfin", "bramble"];
const day1SnapshotCancelDevices = [
"comet",
"komodo",
"caiman",
"tokay",
"akita",
"husky",
"shiba",
"felix",
"tangorpro",
"lynx",
"cheetah",
"panther",
"bluejay",
"raven",
"oriole",
"barbet",
"redfin",
"bramble",
];

function hasOptimizedFactoryImage(product) {
return !legacyQualcommDevices.includes(product);
Expand All @@ -231,42 +270,52 @@ function hasOptimizedFactoryImage(product) {
async function getLatestRelease() {
let product = await device.getVariable("product");
if (!supportedDevices.includes(product)) {
throw new Error(`device model (${product}) is not supported by the GrapheneOS web installer`);
throw new Error(
`device model (${product}) is not supported by the GrapheneOS web installer`,
);
}

let metadataResp = await fetch(`${RELEASES_URL}/${product}-stable`);
let metadata = await metadataResp.text();
let releaseId = metadata.split(" ")[0];

return [`${product}-${hasOptimizedFactoryImage(product) ? "install" : "factory"}-${releaseId}.zip`, product];
return [
`${product}-${hasOptimizedFactoryImage(product) ? "install" : "factory"}-${releaseId}.zip`,
product,
];
}

async function downloadRelease(setProgress) {
await requestWakeLock();
await ensureConnected(setProgress);

setProgress("Finding latest release...");
let [latestZip,] = await getLatestRelease();
let [latestZip] = await getLatestRelease();

// Download and cache the zip as a blob
setInstallerState({ state: InstallerState.DOWNLOADING_RELEASE, active: true });
setInstallerState({
state: InstallerState.DOWNLOADING_RELEASE,
active: true,
});
setProgress(`Downloading ${latestZip}...`);
await blobStore.init();
try {
await blobStore.download(`${RELEASES_URL}/${latestZip}`, (progress) => {
setProgress(`Downloading ${latestZip}...`, progress);
});
} finally {
setInstallerState({ state: InstallerState.DOWNLOADING_RELEASE, active: false });
setInstallerState({
state: InstallerState.DOWNLOADING_RELEASE,
active: false,
});
await releaseWakeLock();
}
setProgress(`Downloaded ${latestZip} release.`, 1.0);
}

async function reconnectCallback() {
let statusField = document.getElementById("flash-release-status");
statusField.textContent =
"To continue flashing, reconnect the device by tapping here:";
statusField.textContent = "To continue flashing, reconnect the device by tapping here:";

let reconnectButton = document.getElementById("flash-reconnect-button");
let progressBar = document.getElementById("flash-release-progress");
Expand Down Expand Up @@ -306,15 +355,16 @@ async function flashRelease(setProgress) {
}

setProgress("Flashing release...");
setInstallerState({ state: InstallerState.INSTALLING_RELEASE, active: true });
setInstallerState({
state: InstallerState.INSTALLING_RELEASE,
active: true,
});
try {
await device.flashFactoryZip(blob, true, reconnectCallback,
(action, item, progress) => {
let userAction = fastboot.USER_ACTION_MAP[action];
let userItem = item === "avb_custom_key" ? "verified boot key" : item;
setProgress(`${userAction} ${userItem}...`, progress);
}
);
await device.flashFactoryZip(blob, true, reconnectCallback, (action, item, progress) => {
let userAction = fastboot.USER_ACTION_MAP[action];
let userItem = item === "avb_custom_key" ? "verified boot key" : item;
setProgress(`${userAction} ${userItem}...`, progress);
});
if (legacyQualcommDevices.includes(product)) {
setProgress("Disabling UART...");
// See https://android.googlesource.com/platform/system/core/+/eclair-release/fastboot/fastboot.c#532
Expand All @@ -329,7 +379,10 @@ async function flashRelease(setProgress) {
await device.runCommand("erase:msadp_b");
}
} finally {
setInstallerState({ state: InstallerState.INSTALLING_RELEASE, active: false });
setInstallerState({
state: InstallerState.INSTALLING_RELEASE,
active: false,
});
await releaseWakeLock();
}

Expand Down Expand Up @@ -466,7 +519,7 @@ if ("usb" in navigator) {
}

// This will create an alert box to stop the user from leaving the page during actions
window.addEventListener("beforeunload", event => {
window.addEventListener("beforeunload", (event) => {
if (!safeToLeave()) {
console.log("User tried to leave the page whilst unsafe to leave!");
event.returnValue = "";
Expand Down

0 comments on commit 1c32e26

Please sign in to comment.