Added mobile support in Svelte

This commit is contained in:
ManeraKai 2024-07-26 17:39:22 +03:00
parent f047a1d02d
commit 2cb60e91cd
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
17 changed files with 157 additions and 217 deletions

View File

@ -9,7 +9,7 @@
"scripts": { "scripts": {
"start": "web-ext run", "start": "web-ext run",
"nightly": "web-ext run --firefox=/home/esmail/software/firefox_nightly/firefox", "nightly": "web-ext run --firefox=/home/esmail/software/firefox_nightly/firefox",
"android": "web-ext run -t firefox-android --adb-device emulator-5554 --firefox-apk org.mozilla.fenix", "android": "web-ext run -t firefox-android --adb-device emulator-5554 --firefox-apk org.mozilla.fenix ",
"build": "web-ext build", "build": "web-ext build",
"test": "web-ext lint", "test": "web-ext lint",
"html": "rollup -c --config-popup && rollup -c --config-options" "html": "rollup -c --config-popup && rollup -c --config-options"

View File

@ -20,13 +20,6 @@ function getNextInstance(currentInstanceUrl, instances) {
return instances[nextInstanceIndex] return instances[nextInstanceIndex]
} }
/**
* @param {string} str
*/
function camelCase(str) {
return str.charAt(0).toUpperCase() + str.slice(1)
}
/** /**
* @param {URL} url * @param {URL} url
*/ */
@ -178,7 +171,6 @@ export default {
protocolHost, protocolHost,
getList, getList,
getBlacklist, getBlacklist,
camelCase,
getConfig, getConfig,
getOptions, getOptions,
getPingCache, getPingCache,

View File

@ -38,4 +38,9 @@
input:focus { input:focus {
outline-color: var(--active); outline-color: var(--active);
} }
@media (max-width: 715px) {
input {
width: 200px;
}
}
</style> </style>

View File

@ -1,14 +0,0 @@
<script>
import Row from "./Row.svelte"
import Checkbox from "./Checkbox.svelte"
import Label from "./Label.svelte"
export let label
export let checked
export let onChange
</script>
<Row>
<Label>{label}</Label>
<Checkbox bind:checked {onChange} />
</Row>

View File

@ -1,19 +0,0 @@
<script>
import Row from "./Row.svelte"
import Select from "./Select.svelte"
import Label from "./Label.svelte"
export let label
export let values
export let value
export let onChange
export let ariaLabel
</script>
<Row>
<Label>{label}</Label>
<Select {value} {values} {onChange} {ariaLabel} />
</Row>
<style>
</style>

View File

@ -0,0 +1,13 @@
@font-face {
font-family: "Inter";
src: url("Inter-VariableFont_slnt,wght.ttf");
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: "Vazirmatn";
src: url("Vazirmatn-VariableFont_wght.ttf");
font-weight: normal;
font-style: normal;
}

View File

@ -7,6 +7,7 @@
<link rel="icon" type="image/x-icon" href="../../../assets/images/libredirect.svg"> <link rel="icon" type="image/x-icon" href="../../../assets/images/libredirect.svg">
<title>Settings</title> <title>Settings</title>
<link rel='stylesheet' href='build/bundle.css'> <link rel='stylesheet' href='build/bundle.css'>
<link rel='stylesheet' href='../fonts/styles.css'>
<script defer src='build/bundle.js'></script> <script defer src='build/bundle.js'></script>
</head> </head>

View File

@ -93,7 +93,6 @@
{/if} {/if}
<style> <style>
:global(body) { :global(body) {
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
@ -115,4 +114,23 @@
color: var(--text); color: var(--text);
overflow: scroll; overflow: scroll;
} }
@media (max-width: 1250px) {
div {
grid-template-columns: auto;
grid-template-rows: min-content auto;
padding-left: 5vw;
padding-right: 5vw;
}
}
@media (max-width: 715px) {
div {
font-size: 14px;
grid-template-columns: auto;
grid-template-rows: min-content auto;
padding-left: 5vw;
padding-right: 5vw;
}
}
</style> </style>

View File

@ -3,10 +3,12 @@
import Exceptions from "./Exceptions.svelte" import Exceptions from "./Exceptions.svelte"
import SettingsButtons from "./SettingsButtons.svelte" import SettingsButtons from "./SettingsButtons.svelte"
import RowSelect from "../../components/RowSelect.svelte"
import Checkbox from "../../components/RowCheckbox.svelte"
import { options } from "../stores" import { options } from "../stores"
import { onDestroy } from "svelte" import { onDestroy } from "svelte"
import Row from "../../components/Row.svelte"
import Label from "../../components/Label.svelte"
import Select from "../../components/Select.svelte"
import Checkbox from "../../components/Checkbox.svelte"
let _options let _options
const unsubscribe = options.subscribe(val => (_options = val)) const unsubscribe = options.subscribe(val => (_options = val))
@ -23,8 +25,9 @@
</script> </script>
<div> <div>
<RowSelect <Row>
label="Theme" <Label>Theme</Label>
<Select
values={[ values={[
{ value: "detect", name: "Auto" }, { value: "detect", name: "Auto" },
{ value: "light", name: "Light" }, { value: "light", name: "Light" },
@ -32,37 +35,45 @@
]} ]}
value={_options.theme} value={_options.theme}
onChange={e => { onChange={e => {
_options["theme"] = e.target.options[e.target.options.selectedIndex].value _options.theme = e.target.options[e.target.options.selectedIndex].value
options.set(_options) options.set(_options)
}} }}
ariaLabel="select theme" ariaLabel="select theme"
/> />
</Row>
<RowSelect <Row>
label="Fetch public instances" <Label>Fetch public instances</Label>
<Select
value={_options.fetchInstances} value={_options.fetchInstances}
onChange={e => {
_options["fetchInstances"] = e.target.options[e.target.options.selectedIndex].value
options.set(_options)
}}
ariaLabel="Select fetch public instances"
values={[ values={[
{ value: "github", name: "GitHub" }, { value: "github", name: "GitHub" },
{ value: "codeberg", name: "Codeberg" }, { value: "codeberg", name: "Codeberg" },
{ value: "disable", name: "Disable" }, { value: "disable", name: "Disable" },
]} ]}
onChange={e => {
_options.fetchInstances = e.target.options[e.target.options.selectedIndex].value
options.set(_options)
}}
ariaLabel={"Select fetch public instances"}
/> />
</Row>
<Row>
<Label>Redirect Only in Incognito</Label>
<Checkbox <Checkbox
label="Redirect Only in Incognito"
checked={_options.redirectOnlyInIncognito} checked={_options.redirectOnlyInIncognito}
onChange={e => { onChange={e => {
_options["redirectOnlyInIncognito"] = e.target.checked _options.redirectOnlyInIncognito = e.target.checked
options.set(_options) options.set(_options)
}} }}
/> />
</Row>
<Checkbox label="Bookmarks menu" bind:checked={bookmarksPermission} /> <Row>
<Label>Bookmarks menu</Label>
<Checkbox bind:checked={bookmarksPermission} />
</Row>
<Exceptions opts={_options} /> <Exceptions opts={_options} />

View File

@ -63,10 +63,10 @@
console.log("pinging...", instance) console.log("pinging...", instance)
pingCache[instance] = { color: "lightblue", value: "pinging..." } pingCache[instance] = { color: "lightblue", value: "pinging..." }
const time = await utils.ping(instance) const time = await utils.ping(instance)
pingCache[instance] = processTime(time) pingCache[instance] = colorTime(time)
} }
} }
function processTime(time) { function colorTime(time) {
let value let value
let color let color
if (time < 5000) { if (time < 5000) {
@ -225,6 +225,7 @@
a { a {
color: var(--text); color: var(--text);
text-decoration: none; text-decoration: none;
word-wrap: anywhere;
} }
a:hover { a:hover {

View File

@ -1,12 +1,11 @@
<script> <script>
import { onDestroy } from "svelte" import { onDestroy } from "svelte"
import RowSelect from "../../components/RowSelect.svelte"
import SvelteSelect from "svelte-select" import SvelteSelect from "svelte-select"
import { options, config } from "../stores" import { options, config } from "../stores"
import Row from "../../components/Row.svelte" import Row from "../../components/Row.svelte"
import Label from "../../components/Label.svelte" import Label from "../../components/Label.svelte"
import FrontendIcon from "./FrontendIcon.svelte" import FrontendIcon from "./FrontendIcon.svelte"
import Select from "../../components/Select.svelte"
let _options let _options
let _config let _config
@ -63,15 +62,17 @@
} }
</script> </script>
<RowSelect <Row>
label="Redirect Type" <Label>Redirect Type</Label>
<Select
value={serviceOptions.redirectType} value={serviceOptions.redirectType}
onChange={e => { onChange={e => {
serviceOptions.redirectType = e.target.options[e.target.options.selectedIndex].value serviceOptions.redirectType = e.target.options[e.target.options.selectedIndex].value
options.set(_options) options.set(_options)
}} }}
{values} {values}
/> />
</Row>
{#if serviceConf.frontends[frontendName].desktopApp && serviceOptions.redirectType != "main_frame"} {#if serviceConf.frontends[frontendName].desktopApp && serviceOptions.redirectType != "main_frame"}
<Row> <Row>

View File

@ -1,6 +1,4 @@
<script> <script>
import Checkbox from "../../components/RowCheckbox.svelte"
import RowSelect from "../../components/RowSelect.svelte"
import Row from "../../components/Row.svelte" import Row from "../../components/Row.svelte"
import Label from "../../components/Label.svelte" import Label from "../../components/Label.svelte"
import Select from "../../components/Select.svelte" import Select from "../../components/Select.svelte"
@ -11,6 +9,7 @@
import SvelteSelect from "svelte-select" import SvelteSelect from "svelte-select"
import ServiceIcon from "./ServiceIcon.svelte" import ServiceIcon from "./ServiceIcon.svelte"
import FrontendIcon from "./FrontendIcon.svelte" import FrontendIcon from "./FrontendIcon.svelte"
import Checkbox from "../../components/Checkbox.svelte"
let _options let _options
let _config let _config
@ -58,18 +57,21 @@
<hr /> <hr />
<Row>
<Label>Enable</Label>
<Checkbox <Checkbox
label="Enable"
checked={serviceOptions.enabled} checked={serviceOptions.enabled}
onChange={e => { onChange={e => {
serviceOptions.enabled = e.target.checked serviceOptions.enabled = e.target.checked
options.set(_options) options.set(_options)
}} }}
/> />
</Row>
<div style={!serviceOptions.enabled && "pointer-events: none;opacity: 0.4;user-select: none;"}> <div style={!serviceOptions.enabled && "pointer-events: none;opacity: 0.4;user-select: none;"}>
<Row>
<Label>Show in popup</Label>
<Checkbox <Checkbox
label="Show in popup"
checked={_options.popupServices.includes(selectedService)} checked={_options.popupServices.includes(selectedService)}
onChange={e => { onChange={e => {
if (e.target.checked && !_options.popupServices.includes(selectedService)) { if (e.target.checked && !_options.popupServices.includes(selectedService)) {
@ -81,6 +83,7 @@
options.set(_options) options.set(_options)
}} }}
/> />
</Row>
<Row> <Row>
<Label> <Label>
@ -118,8 +121,9 @@
<RedirectType {selectedService} /> <RedirectType {selectedService} />
<RowSelect <Row>
label="Unsupported embeds handling" <Label>Unsupported embeds handling</Label>
<Select
value={serviceOptions.unsupportedUrls} value={serviceOptions.unsupportedUrls}
onChange={e => { onChange={e => {
serviceOptions.unsupportedUrls = e.target.options[e.target.options.selectedIndex].value serviceOptions.unsupportedUrls = e.target.options[e.target.options.selectedIndex].value
@ -130,6 +134,7 @@
{ value: "block", name: "Block" }, { value: "block", name: "Block" },
]} ]}
/> />
</Row>
{#if selectedService == "search"} {#if selectedService == "search"}
<Row> <Row>
@ -163,6 +168,7 @@
--item-padding: 0 10px; --item-padding: 0 10px;
--border: none; --border: none;
--border-hover: none; --border-hover: none;
--border-focused: none;
--width: 210px; --width: 210px;
--background: var(--bg-secondary); --background: var(--bg-secondary);
--list-background: var(--bg-secondary); --list-background: var(--bg-secondary);
@ -178,7 +184,6 @@
justify-content: start; justify-content: start;
align-items: center; align-items: center;
} }
:global(.svelte_select img, .svelte_select svg) { :global(.svelte_select img, .svelte_select svg) {
margin-right: 10px; margin-right: 10px;
height: 26px; height: 26px;

View File

@ -40,4 +40,18 @@
a:hover { a:hover {
color: var(--active); color: var(--active);
} }
@media (max-width: 1250px) {
div {
flex-direction: row;
justify-content: center;
margin: 0;
}
}
@media (max-width: 715px) {
a {
margin: 5px;
}
}
</style> </style>

View File

@ -7,7 +7,7 @@
<link rel="icon" type="image/x-icon" href="../../../assets/images/libredirect.svg"> <link rel="icon" type="image/x-icon" href="../../../assets/images/libredirect.svg">
<title>Settings</title> <title>Settings</title>
<link rel='stylesheet' href='build/bundle.css'> <link rel='stylesheet' href='build/bundle.css'>
<link rel='stylesheet' href='../stylesheets/styles.css'> <link rel='stylesheet' href='../fonts/styles.css'>
<script defer src='build/bundle.js'></script> <script defer src='build/bundle.js'></script>
</head> </head>

View File

@ -1,88 +0,0 @@
@font-face {
font-family: "Inter";
src: url("Inter-VariableFont_slnt,wght.ttf");
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: "Vazirmatn";
src: url("Vazirmatn-VariableFont_wght.ttf");
font-weight: normal;
font-style: normal;
}
/*
@media (max-width: 1250px) {
body.option {
flex-direction: column;
width: 95vw;
align-items: center;
padding: 40px 0px;
}
section.links {
flex-direction: row;
width: 95vw;
padding: 0 55px;
}
section.block-option {
width: 95vw;
}
div.checklist div x {
overflow: hidden;
}
}
html.mobile img,
html.mobile svg {
margin-right: 10px;
height: 30px;
width: 30px;
color: var(--text);
}
html.mobile div.block {
padding: 0 15px;
justify-content: space-between;
display: flex;
align-items: center;
margin-top: 20px;
margin-bottom: 20px;
}
html.mobile div.block input[type="checkbox"] {
width: 58px;
height: 30px;
}
html.mobile div.block input[type="checkbox"]::before {
width: 24px;
height: 24px;
top: 3px;
left: 3.5px;
}
html.mobile div.block input[type="checkbox"]:checked::before {
left: 30px;
}
html.mobile body.option {
flex-direction: column;
width: 100%;
padding: 0;
align-items: center;
}
html.mobile section.links {
flex-direction: row;
width: 100%;
padding: 0 55px;
}
html.mobile section.block-option {
width: 100%;
} */