2024-10-09 10:45:19 +00:00
|
|
|
import {
|
|
|
|
children,
|
|
|
|
createSignal,
|
|
|
|
For,
|
|
|
|
Show,
|
2024-11-07 08:17:13 +00:00
|
|
|
type JSX,
|
2024-10-09 10:45:19 +00:00
|
|
|
type ParentComponent,
|
|
|
|
} from "solid-js";
|
2024-07-22 13:57:04 +00:00
|
|
|
import Scaffold from "../material/Scaffold.js";
|
|
|
|
import {
|
|
|
|
AppBar,
|
|
|
|
Divider,
|
|
|
|
IconButton,
|
|
|
|
List,
|
|
|
|
ListItem,
|
|
|
|
ListItemButton,
|
2024-09-26 09:23:40 +00:00
|
|
|
ListItemIcon,
|
2024-07-22 13:57:04 +00:00
|
|
|
ListItemSecondaryAction,
|
|
|
|
ListItemText,
|
|
|
|
ListSubheader,
|
2024-11-07 08:17:13 +00:00
|
|
|
NativeSelect,
|
2024-07-22 13:57:04 +00:00
|
|
|
Switch,
|
|
|
|
Toolbar,
|
|
|
|
} from "@suid/material";
|
2024-09-14 11:55:37 +00:00
|
|
|
import {
|
2024-10-09 10:45:19 +00:00
|
|
|
Animation as AnimationIcon,
|
2024-09-14 11:55:37 +00:00
|
|
|
Close as CloseIcon,
|
2024-09-26 11:36:46 +00:00
|
|
|
Logout,
|
2024-09-26 09:23:40 +00:00
|
|
|
Public as PublicIcon,
|
2024-09-14 11:55:37 +00:00
|
|
|
Refresh as RefreshIcon,
|
2024-09-26 09:23:40 +00:00
|
|
|
Translate as TranslateIcon,
|
2024-09-14 11:55:37 +00:00
|
|
|
} from "@suid/icons-material";
|
2024-10-09 10:45:19 +00:00
|
|
|
import { A, useNavigate } from "@solidjs/router";
|
2024-07-22 13:57:04 +00:00
|
|
|
import { Title } from "../material/typography.jsx";
|
|
|
|
import { css } from "solid-styled";
|
|
|
|
import { signOut, type Account } from "../accounts/stores.js";
|
2024-09-26 11:42:44 +00:00
|
|
|
import { format } from "date-fns";
|
2024-07-23 00:28:47 +00:00
|
|
|
import { useStore } from "@nanostores/solid";
|
|
|
|
import { $settings } from "./stores.js";
|
2024-09-26 09:23:40 +00:00
|
|
|
import {
|
|
|
|
autoMatchLangTag,
|
|
|
|
autoMatchRegion,
|
2024-09-26 11:42:44 +00:00
|
|
|
createTranslator,
|
2024-09-26 09:23:40 +00:00
|
|
|
useDateFnLocale,
|
|
|
|
} from "../platform/i18n.jsx";
|
2024-09-26 11:42:44 +00:00
|
|
|
import { type Template } from "@solid-primitives/i18n";
|
2024-09-27 06:15:34 +00:00
|
|
|
import BottomSheet from "../material/BottomSheet.jsx";
|
2024-10-15 12:30:08 +00:00
|
|
|
import { useServiceWorker } from "../platform/host.js";
|
2024-11-04 09:09:20 +00:00
|
|
|
import { useSessions } from "../masto/clients.js";
|
2024-09-26 11:36:46 +00:00
|
|
|
|
2024-11-07 08:17:13 +00:00
|
|
|
type Inset = {
|
|
|
|
top?: number;
|
|
|
|
right?: number;
|
|
|
|
bottom?: number;
|
|
|
|
left?: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
type SafeAreaInsets = {
|
|
|
|
landscape: Inset;
|
|
|
|
protrait: Inset;
|
|
|
|
};
|
|
|
|
|
|
|
|
const safeAreaInsets: Record<string, SafeAreaInsets> = {
|
|
|
|
iphone15: {
|
|
|
|
protrait: {
|
|
|
|
top: 59,
|
|
|
|
bottom: 34,
|
|
|
|
},
|
|
|
|
landscape: {
|
|
|
|
bottom: 21,
|
|
|
|
left: 59,
|
|
|
|
right: 59,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
iphone12: {
|
|
|
|
protrait: {
|
|
|
|
top: 47,
|
|
|
|
bottom: 34,
|
|
|
|
},
|
|
|
|
landscape: {
|
|
|
|
bottom: 21,
|
|
|
|
left: 47,
|
|
|
|
right: 47,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
iphone13mini: {
|
|
|
|
protrait: {
|
|
|
|
top: 50,
|
|
|
|
bottom: 34,
|
|
|
|
},
|
|
|
|
landscape: {
|
|
|
|
bottom: 21,
|
|
|
|
left: 50,
|
|
|
|
right: 50,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let screenOrientationCallback: (() => void) | undefined;
|
|
|
|
|
2024-11-10 13:23:03 +00:00
|
|
|
function removeSafeAreaEmulation(root: HTMLElement) {
|
|
|
|
for (const name of ["top", "right", "bottom", "left"]) {
|
|
|
|
root.style.removeProperty(`--safe-area-inset-${name}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-07 08:17:13 +00:00
|
|
|
function applySafeAreaEmulation(root: HTMLElement, insets: Inset) {
|
2024-11-10 13:23:03 +00:00
|
|
|
removeSafeAreaEmulation(root);
|
2024-11-07 08:17:13 +00:00
|
|
|
for (const key of Object.keys(insets) as (keyof Inset)[]) {
|
|
|
|
const value = insets[key];
|
|
|
|
if (!value || value === 0) continue;
|
|
|
|
root.style.setProperty(`--safe-area-inset-${key}`, `${value}px`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupSafeAreaEmulation(name: string) {
|
|
|
|
const insets = safeAreaInsets[name];
|
|
|
|
const root = document.querySelector(":root")! as HTMLElement;
|
2024-11-10 13:23:03 +00:00
|
|
|
|
|
|
|
if (screenOrientationCallback) {
|
|
|
|
window.screen.orientation.removeEventListener(
|
|
|
|
"change",
|
|
|
|
screenOrientationCallback,
|
|
|
|
);
|
|
|
|
screenOrientationCallback = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
removeSafeAreaEmulation(root);
|
|
|
|
|
|
|
|
if (insets) {
|
2024-11-07 08:17:13 +00:00
|
|
|
screenOrientationCallback = () => {
|
2024-11-10 13:23:03 +00:00
|
|
|
console.debug(
|
|
|
|
`safe area emulation target: ${window.screen.orientation.type}`,
|
|
|
|
);
|
2024-11-07 08:17:13 +00:00
|
|
|
if (window.screen.orientation.type === "portrait-primary") {
|
|
|
|
console.debug("safe area emulation: protrait");
|
|
|
|
applySafeAreaEmulation(root, insets.protrait);
|
|
|
|
} else if (window.screen.orientation.type === "landscape-primary") {
|
|
|
|
console.debug("safe area emulation: landscape");
|
|
|
|
applySafeAreaEmulation(root, insets.landscape);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
window.screen.orientation.addEventListener(
|
|
|
|
"change",
|
|
|
|
screenOrientationCallback,
|
|
|
|
);
|
|
|
|
screenOrientationCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-10 13:23:03 +00:00
|
|
|
if (import.meta.hot) {
|
|
|
|
import.meta.hot.accept((mod) => {
|
|
|
|
if (!mod) return;
|
|
|
|
if (screenOrientationCallback) {
|
|
|
|
mod["screenOrientationCallback"] = screenOrientationCallback;
|
|
|
|
setTimeout(screenOrientationCallback, 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-09-26 11:36:46 +00:00
|
|
|
type Strings = {
|
2024-09-27 06:15:34 +00:00
|
|
|
["lang.auto"]: Template<{ detected: string }>;
|
|
|
|
} & Record<string, string | undefined>;
|
2024-07-22 13:57:04 +00:00
|
|
|
|
2024-10-09 10:45:19 +00:00
|
|
|
const Settings: ParentComponent = (props) => {
|
2024-09-26 11:42:44 +00:00
|
|
|
const [t] = createTranslator(
|
2024-09-26 11:36:46 +00:00
|
|
|
(code) =>
|
|
|
|
import(`./i18n/${code}.json`) as Promise<{
|
|
|
|
default: Strings;
|
|
|
|
}>,
|
2024-09-27 06:15:34 +00:00
|
|
|
() => import(`./i18n/lang-names.json`),
|
2024-09-26 09:23:40 +00:00
|
|
|
);
|
2024-07-22 13:57:04 +00:00
|
|
|
const navigate = useNavigate();
|
2024-07-23 00:28:47 +00:00
|
|
|
const settings$ = useStore($settings);
|
2024-10-15 12:30:08 +00:00
|
|
|
const { needRefresh, offlineReady } = useServiceWorker();
|
2024-09-26 09:23:40 +00:00
|
|
|
const dateFnLocale = useDateFnLocale();
|
2024-07-22 13:57:04 +00:00
|
|
|
|
2024-11-04 09:09:20 +00:00
|
|
|
const profiles = useSessions();
|
2024-07-22 13:57:04 +00:00
|
|
|
|
|
|
|
const doSignOut = (acct: Account) => {
|
|
|
|
signOut((a) => a.site === acct.site && a.accessToken === acct.accessToken);
|
|
|
|
};
|
|
|
|
|
2024-10-09 10:45:19 +00:00
|
|
|
const subpage = children(() => props.children);
|
|
|
|
|
2024-07-22 13:57:04 +00:00
|
|
|
css`
|
|
|
|
ul {
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.setting-list {
|
2024-07-24 06:27:20 +00:00
|
|
|
padding-bottom: calc(var(--safe-area-inset-bottom, 0px) + 16px);
|
2024-07-22 13:57:04 +00:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
return (
|
|
|
|
<Scaffold
|
|
|
|
topbar={
|
|
|
|
<AppBar position="static">
|
2024-09-14 11:55:37 +00:00
|
|
|
<Toolbar
|
|
|
|
variant="dense"
|
|
|
|
sx={{ paddingTop: "var(--safe-area-inset-top, 0px)" }}
|
|
|
|
>
|
2024-08-13 07:08:29 +00:00
|
|
|
<IconButton color="inherit" onClick={[navigate, -1]} disableRipple>
|
2024-07-22 13:57:04 +00:00
|
|
|
<CloseIcon />
|
|
|
|
</IconButton>
|
2024-09-26 09:23:40 +00:00
|
|
|
<Title>{t("Settings")}</Title>
|
2024-07-22 13:57:04 +00:00
|
|
|
</Toolbar>
|
|
|
|
</AppBar>
|
|
|
|
}
|
|
|
|
>
|
2024-10-09 10:45:19 +00:00
|
|
|
<BottomSheet open={!!subpage()} onClose={() => navigate(-1)}>
|
|
|
|
{subpage()}
|
|
|
|
</BottomSheet>
|
|
|
|
|
2024-07-22 13:57:04 +00:00
|
|
|
<List class="setting-list" use:solid-styled>
|
|
|
|
<li>
|
|
|
|
<ul>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListSubheader>{t("Accounts")}</ListSubheader>
|
2024-09-26 11:36:46 +00:00
|
|
|
<ListItemButton disabled>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListItemText>{t("All Notifications")}</ListItemText>
|
2024-07-22 13:57:04 +00:00
|
|
|
<ListItemSecondaryAction>
|
2024-09-27 06:15:34 +00:00
|
|
|
<Switch value={false} disabled />
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemSecondaryAction>
|
2024-09-26 11:36:46 +00:00
|
|
|
</ListItemButton>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-09-26 11:36:46 +00:00
|
|
|
<ListItemButton disabled>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListItemText>{t("Sign in...")}</ListItemText>
|
2024-09-26 11:36:46 +00:00
|
|
|
</ListItemButton>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
</ul>
|
|
|
|
<For each={profiles()}>
|
2024-11-04 09:09:20 +00:00
|
|
|
{({ account: acct }) => (
|
|
|
|
<ul data-site={acct.site} data-username={acct.inf?.username}>
|
|
|
|
<ListSubheader>{`@${acct.inf?.username ?? "..."}@${new URL(acct.site).host}`}</ListSubheader>
|
2024-09-26 11:36:46 +00:00
|
|
|
<ListItemButton disabled>
|
|
|
|
<ListItemText>{t("Notifications")}</ListItemText>
|
2024-07-22 13:57:04 +00:00
|
|
|
<ListItemSecondaryAction>
|
2024-09-27 06:15:34 +00:00
|
|
|
<Switch value={false} disabled />
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemSecondaryAction>
|
2024-09-26 11:36:46 +00:00
|
|
|
</ListItemButton>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
<ListItemButton onClick={[doSignOut, acct]}>
|
2024-09-26 11:36:46 +00:00
|
|
|
<ListItemIcon>
|
2024-09-27 06:15:34 +00:00
|
|
|
<Logout />
|
2024-09-26 11:36:46 +00:00
|
|
|
</ListItemIcon>
|
|
|
|
<ListItemText>{t("Sign out")}</ListItemText>
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemButton>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
</ul>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</li>
|
|
|
|
<li>
|
2024-10-09 10:45:19 +00:00
|
|
|
<ListSubheader>{t("timelines")}</ListSubheader>
|
2024-09-26 11:36:46 +00:00
|
|
|
<ListItemButton
|
2024-09-14 11:55:37 +00:00
|
|
|
onClick={(e) =>
|
|
|
|
$settings.setKey(
|
|
|
|
"prefetchTootsDisabled",
|
|
|
|
!settings$().prefetchTootsDisabled,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListItemText secondary={t("Prefetch Toots.2nd")}>
|
|
|
|
{t("Prefetch Toots")}
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemText>
|
|
|
|
<ListItemSecondaryAction>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Switch checked={!settings$().prefetchTootsDisabled} />
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemSecondaryAction>
|
2024-09-26 11:36:46 +00:00
|
|
|
</ListItemButton>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-10-09 10:45:19 +00:00
|
|
|
<ListItemButton component={A} href="./motions">
|
|
|
|
<ListItemIcon>
|
|
|
|
<AnimationIcon></AnimationIcon>
|
|
|
|
</ListItemIcon>
|
|
|
|
<ListItemText>{t("motions")}</ListItemText>
|
|
|
|
</ListItemButton>
|
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
</li>
|
|
|
|
<li>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListSubheader>{t("This Application")}</ListSubheader>
|
2024-10-09 15:27:20 +00:00
|
|
|
<ListItemButton component={A} href="./language">
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListItemIcon>
|
|
|
|
<TranslateIcon />
|
|
|
|
</ListItemIcon>
|
2024-09-27 06:15:34 +00:00
|
|
|
<ListItemText
|
|
|
|
secondary={
|
|
|
|
settings$().language === undefined
|
|
|
|
? t("lang.auto", {
|
|
|
|
detected:
|
|
|
|
t("lang." + autoMatchLangTag()) ?? autoMatchLangTag(),
|
|
|
|
})
|
|
|
|
: t("lang." + settings$().language)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{t("Language")}
|
|
|
|
</ListItemText>
|
|
|
|
</ListItemButton>
|
2024-09-26 09:23:40 +00:00
|
|
|
<Divider />
|
2024-10-09 15:27:20 +00:00
|
|
|
<ListItemButton component={A} href="./region">
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListItemIcon>
|
|
|
|
<PublicIcon />
|
|
|
|
</ListItemIcon>
|
2024-09-27 06:15:34 +00:00
|
|
|
<ListItemText
|
|
|
|
secondary={
|
|
|
|
settings$().region === undefined
|
|
|
|
? t("region.auto", {
|
|
|
|
detected:
|
|
|
|
t("region." + autoMatchRegion()) ?? autoMatchRegion(),
|
|
|
|
})
|
|
|
|
: t("region." + settings$().region)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{t("Region")}
|
|
|
|
</ListItemText>
|
|
|
|
</ListItemButton>
|
2024-09-26 09:23:40 +00:00
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
<ListItem>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListItemText secondary={t("About Tutu.2nd")}>
|
|
|
|
{t("About Tutu")}
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemText>
|
|
|
|
</ListItem>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
<ListItem>
|
|
|
|
<ListItemText
|
2024-09-26 09:23:40 +00:00
|
|
|
secondary={t("version", {
|
|
|
|
packageVersion: import.meta.env.PACKAGE_VERSION,
|
|
|
|
builtAt: format(
|
|
|
|
import.meta.env.BUILT_AT,
|
|
|
|
t("datefmt") || "yyyy/MM/dd",
|
|
|
|
{ locale: dateFnLocale() },
|
|
|
|
),
|
|
|
|
buildMode: import.meta.env.MODE,
|
|
|
|
})}
|
2024-07-22 13:57:04 +00:00
|
|
|
>
|
2024-09-26 09:23:40 +00:00
|
|
|
{needRefresh() ? t("updates.ready") : t("updates.no")}
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemText>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Show when={needRefresh()}>
|
|
|
|
<ListItemSecondaryAction>
|
2024-09-26 09:23:40 +00:00
|
|
|
<IconButton
|
|
|
|
aria-label="Restart Now"
|
|
|
|
onClick={() => window.location.reload()}
|
|
|
|
>
|
2024-09-14 11:55:37 +00:00
|
|
|
<RefreshIcon />
|
|
|
|
</IconButton>
|
|
|
|
</ListItemSecondaryAction>
|
|
|
|
</Show>
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItem>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
</li>
|
2024-11-07 08:17:13 +00:00
|
|
|
{import.meta.env.DEV ? (
|
|
|
|
<li>
|
|
|
|
<ListSubheader>Developer Tools</ListSubheader>
|
|
|
|
<ListItem
|
|
|
|
secondaryAction={
|
|
|
|
window.screen?.orientation ? (
|
|
|
|
<NativeSelect
|
|
|
|
sx={{ maxWidth: "40vw" }}
|
|
|
|
onChange={(event) => {
|
|
|
|
const k = event.currentTarget.value;
|
|
|
|
setupSafeAreaEmulation(k);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<option>Don't change</option>
|
|
|
|
<option value={"ua"}>User agent</option>
|
|
|
|
<option value={"iphone15"}>
|
|
|
|
iPhone 15 and Plus, Pro, Pro Max
|
|
|
|
</option>
|
|
|
|
<option value={"iphone12"}>iPhone 12, 13 and 14</option>
|
|
|
|
<option value={"iphone13mini"}>iPhone 13 mini</option>
|
|
|
|
</NativeSelect>
|
|
|
|
) : undefined
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<ListItemText
|
|
|
|
secondary={
|
|
|
|
window.screen?.orientation
|
|
|
|
? undefined
|
|
|
|
: "Unsupported on This Platform"
|
|
|
|
}
|
|
|
|
>
|
|
|
|
Safe Area Insets
|
|
|
|
</ListItemText>
|
|
|
|
</ListItem>
|
|
|
|
<Divider />
|
|
|
|
</li>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
)}
|
2024-07-22 13:57:04 +00:00
|
|
|
</List>
|
|
|
|
</Scaffold>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Settings;
|