From e2d191304359532274ad8ceaa22bc76303cf84cc Mon Sep 17 00:00:00 2001 From: wukko Date: Sat, 11 May 2024 01:05:24 +0600 Subject: [PATCH] web: more ipad accommodations and clean up - moved all user agent toggles to (legacy) frontend, like it should have always been - removed unnecessary building --- src/core/web.js | 4 ++-- src/front/cobalt.js | 10 +++++++++- src/modules/build.js | 14 ++------------ src/modules/pageRender/findRendered.js | 9 ++------- src/modules/pageRender/page.js | 22 +++++++++------------- 5 files changed, 24 insertions(+), 35 deletions(-) diff --git a/src/core/web.js b/src/core/web.js index 626574a3..4c1b1999 100644 --- a/src/core/web.js +++ b/src/core/web.js @@ -1,4 +1,4 @@ -import { genericUserAgent, version, env } from "../modules/config.js"; +import { version, env } from "../modules/config.js"; import { apiJSON, languageCode } from "../modules/sub/utils.js"; import { Bright, Cyan } from "../modules/sub/consoleText.js"; @@ -67,7 +67,7 @@ export async function runWeb(express, app, gitCommit, gitBranch, __dirname) { return res.status(200).end() }); app.get("/", (req, res) => { - return res.sendFile(`${__dirname}/${findRendered(languageCode(req), req.header('user-agent') ? req.header('user-agent') : genericUserAgent)}`) + return res.sendFile(`${__dirname}/${findRendered(languageCode(req))}`) }); app.get("/favicon.ico", (req, res) => { return res.sendFile(`${__dirname}/src/front/icons/favicon.ico`) diff --git a/src/front/cobalt.js b/src/front/cobalt.js index be79ea27..30125421 100644 --- a/src/front/cobalt.js +++ b/src/front/cobalt.js @@ -1,6 +1,6 @@ const ua = navigator.userAgent.toLowerCase(); const isIOS = ua.includes("iphone os") || (ua.includes("mac os") && navigator.maxTouchPoints > 0); -const isMobile = ua.includes("android") || ua.includes("iphone os"); +const isMobile = ua.includes("android") || isIOS; const isSafari = ua.includes("safari/"); const isFirefox = ua.includes("firefox/"); const isOldFirefox = ua.includes("firefox/") && ua.split("firefox/")[1].split('.')[0] < 103; @@ -576,6 +576,14 @@ const loadSettings = () => { if (sGet("disableAnimations") === "true") { eid("cobalt-body").classList.add('no-animation'); } + if (!isMobile) { + eid("cobalt-body").classList.add('desktop'); + } + if (isIOS) { + eid("download-switcher") + .querySelector(".explanation") + .innerHTML = loc.DownloadPopupDescriptionIOS; + } for (let i = 0; i < checkboxes.length; i++) { try { if (sGet(checkboxes[i]) === "true") eid(checkboxes[i]).checked = true; diff --git a/src/modules/build.js b/src/modules/build.js index 887ffb50..a4c4aa6b 100644 --- a/src/modules/build.js +++ b/src/modules/build.js @@ -13,9 +13,6 @@ export async function buildFront(commitHash, branch) { // build html if (!fs.existsSync('./build/')){ fs.mkdirSync('./build/'); - fs.mkdirSync('./build/ios/'); - fs.mkdirSync('./build/pc/'); - fs.mkdirSync('./build/mob/'); } // get rid of old build path if (fs.existsSync('./min')) { @@ -26,16 +23,9 @@ export async function buildFront(commitHash, branch) { let params = { "hash": commitHash, "lang": i, - "useragent": "pc", "branch": branch } - fs.writeFileSync(`./build/pc/${i}.html`, cleanHTML(page(params))); - - params["useragent"] = "iphone os"; - fs.writeFileSync(`./build/ios/${i}.html`, cleanHTML(page(params))); - - params["useragent"] = "android"; - fs.writeFileSync(`./build/mob/${i}.html`, cleanHTML(page(params))); + fs.writeFileSync(`./build/${i}.html`, cleanHTML(page(params))); } // build js & css await esbuild.build({ @@ -45,7 +35,7 @@ export async function buildFront(commitHash, branch) { loader: { '.js': 'js', '.css': 'css', }, charset: 'utf8' }) - } catch (e) { + } catch { return; } } diff --git a/src/modules/pageRender/findRendered.js b/src/modules/pageRender/findRendered.js index 92986480..1cbb01aa 100644 --- a/src/modules/pageRender/findRendered.js +++ b/src/modules/pageRender/findRendered.js @@ -1,11 +1,6 @@ import { languageList } from "../../localization/manager.js"; -export default function(lang, userAgent) { +export default function(lang) { let language = languageList.includes(lang) ? lang : "en"; - - let ua = userAgent.toLowerCase(); - let platform = (ua.match("android") || ua.match("iphone os")) ? "mob" : "pc"; - if (platform === "mob" && ua.match("iphone os")) platform = "ios"; - - return `/build/${platform}/${language}.html`; + return `/build/${language}.html`; } diff --git a/src/modules/pageRender/page.js b/src/modules/pageRender/page.js index d4a68cd9..7666f206 100644 --- a/src/modules/pageRender/page.js +++ b/src/modules/pageRender/page.js @@ -47,14 +47,9 @@ for (let i in donations["crypto"]) { } export default function(obj) { - const t = (str, replace) => { return loc(obj.lang, str, replace) }; - - let ua = obj.useragent.toLowerCase(); - let isIOS = ua.match("iphone os"); - let isMobile = ua.match("android") || ua.match("iphone os"); - - let platform = isMobile ? "m" : "d"; - if (isMobile && isIOS) platform = "i"; + const t = (str, replace) => { + return loc(obj.lang, str, replace) + } audioFormats[0]["text"] = t('SettingsAudioFormatBest'); @@ -64,7 +59,7 @@ export default function(obj) { - + ${t("AppTitleCobalt")} @@ -103,7 +98,7 @@ export default function(obj) { >` : ''} - + @@ -314,7 +309,7 @@ export default function(obj) { closeAria: t('AccessibilityGoBack'), header: { aboveTitle: { - text: `v.${version}-${obj.hash}${platform} (${obj.branch})`, + text: `v.${version}-${obj.hash} (${obj.branch})`, url: `${repo}/commit/${obj.hash}` }, title: `${emoji("⚙️", 30)} ${t('TitlePopupSettings')}` @@ -562,7 +557,7 @@ export default function(obj) { }, body: switcher({ name: "download", - explanation: `${!isIOS ? t('DownloadPopupDescription') : t('DownloadPopupDescriptionIOS')}`, + explanation: t('DownloadPopupDescription'), items: `${t('Download')}
${t('ShareURL')}
${t('CopyURL')}
` @@ -656,7 +651,8 @@ export default function(obj) { 'DataTransferError', 'FilenamePreviewVideoTitle', 'FilenamePreviewAudioTitle', - 'FilenamePreviewAudioAuthor' + 'FilenamePreviewAudioAuthor', + 'DownloadPopupDescriptionIOS' ])}