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

add formatter #1051

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.css
*.html
.github/
fastboot/
package-lock.json
package.json
static-tmp/
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"],
},
},
];
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"terser": "^5.36.0",
"vnu-jar": "^24.10.17"
},
"type": "module"
"type": "module",
"devDependencies": {
"prettier": "3.3.3"
}
}
6 changes: 6 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const config = {
tabWidth: 4,
printWidth: 100,
};

export default config;
1 change: 1 addition & 0 deletions process-static
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ done
stylelint static-tmp/**/*.css
find static-tmp -name '*.css' -exec csso {} -o {} \;

npx prettier . --check
eslint static-tmp/**/!(fastboot.min.m|z-worker-pako.|pako_inflate.min.|)js
find static-tmp -name '*.js' -exec terser --ecma 2022 --module -cmo {} {} \;

Expand Down
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
87 changes: 64 additions & 23 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,22 +270,27 @@ 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 });
Expand All @@ -265,8 +309,7 @@ async function downloadRelease(setProgress) {

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 @@ -308,13 +351,11 @@ async function flashRelease(setProgress) {
setProgress("Flashing release...");
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 Down Expand Up @@ -466,7 +507,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