mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
feat(phone/icon-sets): Add icon sets configurable in settings
This commit is contained in:
1 parent
2c9f260417
commit
e76e6c5296
60 files changed
+292
-30
No files matched your search
@@ -6,7 +6,7 @@ import { useContextMenu, MapSettingItem, SettingOption } from '../../../ui/hooks
|
||||
import { usePhoneConfig } from '../../../config/hooks/usePhoneConfig';
|
||||
import { List } from '../../../ui/components/List';
|
||||
import { useSimcard } from '../../../os/simcard/hooks/useSimcard';
|
||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||
import { IconSetObject, useApp } from '../../../os/apps/hooks/useApps';
|
||||
import {
|
||||
SettingItem,
|
||||
SettingItemIconAction,
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
FileCopy,
|
||||
Book,
|
||||
DeleteForever,
|
||||
Apps,
|
||||
} from '@material-ui/icons';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { ListSubheader } from '@material-ui/core';
|
||||
@@ -71,6 +72,12 @@ export const SettingsApp = () => {
|
||||
setSettings({ ...settings, [key]: value });
|
||||
};
|
||||
|
||||
const iconSets = config.iconSet.map(
|
||||
MapSettingItem(settings.iconSet, (val: SettingOption<IconSetObject>) =>
|
||||
handleSettingChange('iconSet', val),
|
||||
),
|
||||
);
|
||||
|
||||
const wallpapers = config.wallpapers.map(
|
||||
MapSettingItem(settings.wallpaper, (val: SettingOption) => {
|
||||
handleSettingChange('wallpaper', val);
|
||||
@@ -212,6 +219,13 @@ export const SettingsApp = () => {
|
||||
onClick={openMenu}
|
||||
icon={<Brush />}
|
||||
/>
|
||||
<SettingItem
|
||||
label={t('SETTINGS.OPTIONS.ICONSET')}
|
||||
value={settings.iconSet.label}
|
||||
options={iconSets}
|
||||
onClick={openMenu}
|
||||
icon={<Apps />}
|
||||
/>
|
||||
<SettingItem
|
||||
label={t('APPS_SETTINGS_OPTION_WALLPAPER')}
|
||||
value={t(settings.wallpaper.label)}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { atom, DefaultValue, useRecoilState, useResetRecoilState } from 'recoil';
|
||||
import { atom, DefaultValue, useRecoilState, useRecoilValue, useResetRecoilState } from 'recoil';
|
||||
import { SETTINGS_ALL_TWEETS, SETTING_MENTIONS } from '../../../../../typings/twitter';
|
||||
import config from '../../../config/default.json';
|
||||
import { SettingOption } from '../../../ui/hooks/useContextMenu';
|
||||
import { Schema, Validator } from 'jsonschema';
|
||||
import { IconSetObject } from '../../../os/apps/hooks/useApps';
|
||||
|
||||
const NPWD_STORAGE_KEY = 'npwd_settings';
|
||||
|
||||
@@ -18,9 +19,33 @@ const settingOptionSchema: Schema = {
|
||||
required: true,
|
||||
};
|
||||
|
||||
const iconSetValueSchema: Schema = {
|
||||
id: '/IconSetValue',
|
||||
type: 'object',
|
||||
properties: {
|
||||
name: { type: 'string' },
|
||||
custom: { type: 'boolean' },
|
||||
},
|
||||
required: true,
|
||||
};
|
||||
|
||||
const settingOptionIconSet: Schema = {
|
||||
id: '/SettingOptionIconSet',
|
||||
type: 'object',
|
||||
properties: {
|
||||
label: { type: 'string' },
|
||||
val: { $ref: '/IconSetValue' },
|
||||
},
|
||||
required: true,
|
||||
};
|
||||
|
||||
v.addSchema(iconSetValueSchema, '/IconSetValue');
|
||||
v.addSchema(settingOptionIconSet, '/SettingOptionIconSet');
|
||||
|
||||
const settingsSchema: Schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
iconSet: { $ref: '/SettingOptionIconSet' },
|
||||
language: { $ref: '/SettingOption' },
|
||||
wallpaper: { $ref: '/SettingOption' },
|
||||
frame: { $ref: '/SettingOption' },
|
||||
@@ -62,6 +87,7 @@ export function isSettingsSchemaValid(): boolean {
|
||||
|
||||
export interface IPhoneSettings {
|
||||
language: SettingOption;
|
||||
iconSet: SettingOption<IconSetObject>;
|
||||
wallpaper: SettingOption;
|
||||
frame: SettingOption;
|
||||
theme: SettingOption;
|
||||
@@ -115,13 +141,10 @@ const customWallpaperState = atom({
|
||||
default: false,
|
||||
});
|
||||
|
||||
export const useSettings = () => {
|
||||
return useRecoilState(settingsState);
|
||||
};
|
||||
export const useSettings = () => useRecoilState(settingsState);
|
||||
export const useSettingsValue = () => useRecoilValue(settingsState);
|
||||
|
||||
export const useResetSettings = () => {
|
||||
return useResetRecoilState(settingsState);
|
||||
};
|
||||
export const useResetSettings = () => useResetRecoilState(settingsState);
|
||||
|
||||
export const useCustomWallpaperModal = () => {
|
||||
const [customWallpaperModal, setCustomWallpaperModal] = useRecoilState(customWallpaperState);
|
||||
|
||||
@@ -148,6 +148,13 @@
|
||||
"label": "English",
|
||||
"value": "en"
|
||||
},
|
||||
"iconSet": {
|
||||
"label": "NPWD Icons",
|
||||
"value": {
|
||||
"custom": true,
|
||||
"name": "npwd_icons"
|
||||
}
|
||||
},
|
||||
"wallpaper": {
|
||||
"label": "Default",
|
||||
"value": "default.jpg"
|
||||
@@ -187,6 +194,22 @@
|
||||
"TWITTER_notiSoundVol": 50,
|
||||
"TWITTER_notifyNewFeedTweet": true
|
||||
},
|
||||
"iconSet": [
|
||||
{
|
||||
"label": "NPWD Icons",
|
||||
"value": {
|
||||
"custom": true,
|
||||
"name": "npwd_icons"
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Material",
|
||||
"value": {
|
||||
"custom": false,
|
||||
"name": "material"
|
||||
}
|
||||
}
|
||||
],
|
||||
"themes": [
|
||||
{
|
||||
"label": "Taso Dark",
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"ACTIONS": "Actions"
|
||||
},
|
||||
"OPTIONS": {
|
||||
"ICONSET": "Icon Set",
|
||||
"LANGUAGE": "Language",
|
||||
"RESET_SETTINGS": "Reset Settings",
|
||||
"RESET_SETTINGS_DESC": "This will clear your locally stored data",
|
||||
|
||||
@@ -49,7 +49,7 @@ export type IApp = IAppConfig & {
|
||||
icon: JSX.Element;
|
||||
notificationIcon: JSX.Element;
|
||||
NotificationIcon: React.FC<SvgIconProps>;
|
||||
Icon: React.FC<SvgIconProps>;
|
||||
Icon?: React.FC<SvgIconProps>;
|
||||
};
|
||||
|
||||
export const APPS: IAppConfig[] = [
|
||||
|
||||
@@ -4,27 +4,31 @@ import { createLazyAppIcon } from '../utils/createLazyAppIcon';
|
||||
import { APPS, IApp } from '../config/apps';
|
||||
import { SvgIconComponent } from '@material-ui/icons';
|
||||
import { useTheme } from '@material-ui/core';
|
||||
import { useSettings, useSettingsValue } from '../../../apps/settings/hooks/useSettings';
|
||||
|
||||
const DEFAULT_ICONSET = 'default';
|
||||
export interface IconSetObject {
|
||||
custom: boolean;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const useApps = () => {
|
||||
const { icons } = useNotifications();
|
||||
const theme = useTheme();
|
||||
const iconset = DEFAULT_ICONSET;
|
||||
const apps: IApp[] = useMemo(
|
||||
() =>
|
||||
APPS.map((app) => {
|
||||
|
||||
const SvgIcon = React.lazy<SvgIconComponent>(
|
||||
() => import(`${__dirname}/../icons/${iconset}/svg/${app.id}`),
|
||||
);
|
||||
const AppIcon = React.lazy<SvgIconComponent>(
|
||||
() => import(`${__dirname}/../icons/${iconset}/app/${app.id}`),
|
||||
);
|
||||
const curIconSet = useSettingsValue().iconSet.value as IconSetObject;
|
||||
|
||||
const NotificationIcon = createLazyAppIcon(SvgIcon);
|
||||
const Icon = createLazyAppIcon(AppIcon);
|
||||
const apps: IApp[] = useMemo(() => {
|
||||
return APPS.map((app) => {
|
||||
const SvgIcon = React.lazy<SvgIconComponent>(
|
||||
() => import(`${__dirname}/../icons/${curIconSet.name}/svg/${app.id}`),
|
||||
);
|
||||
const AppIcon = React.lazy<SvgIconComponent>(
|
||||
() => import(`${__dirname}/../icons/${curIconSet.name}/app/${app.id}`),
|
||||
);
|
||||
|
||||
const NotificationIcon = createLazyAppIcon(SvgIcon);
|
||||
const Icon = createLazyAppIcon(AppIcon);
|
||||
|
||||
if (curIconSet.custom) {
|
||||
return {
|
||||
...app,
|
||||
notification: icons.find((i) => i.key === app.id),
|
||||
@@ -35,9 +39,18 @@ export const useApps = () => {
|
||||
),
|
||||
icon: <Icon />,
|
||||
};
|
||||
}),
|
||||
[icons, iconset, theme],
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
...app,
|
||||
notification: icons.find((i) => i.key === app.id),
|
||||
NotificationIcon,
|
||||
notificationIcon: <NotificationIcon htmlColor={app.color} fontSize="small" />,
|
||||
icon: <Icon />,
|
||||
};
|
||||
});
|
||||
}, [icons, curIconSet, theme]);
|
||||
|
||||
const getApp = useCallback((id: string): IApp => apps.find((a) => a.id === id) || null, [apps]);
|
||||
return { apps, getApp };
|
||||
};
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Money } from '@material-ui/icons';
|
||||
import React from 'react';
|
||||
|
||||
const BankIcon: React.FC = () => <Money fontSize="large" />;
|
||||
|
||||
export default BankIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { CalculatorIcon } from '../../../../../apps/calculator/components/CalculatorIcon';
|
||||
|
||||
const Calculator: React.FC = () => <CalculatorIcon fontSize="large" />;
|
||||
|
||||
export default Calculator;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { CameraAlt } from '@material-ui/icons';
|
||||
|
||||
const Camera: React.FC = () => <CameraAlt fontSize="large" />;
|
||||
|
||||
export default Camera;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Contacts } from '@material-ui/icons';
|
||||
|
||||
const ContactIcon: React.FC = () => <Contacts fontSize="large" />;
|
||||
|
||||
export default ContactIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Phone } from '@material-ui/icons';
|
||||
|
||||
const DialerIcon: React.FC = () => <Phone fontSize="large" />;
|
||||
|
||||
export default DialerIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Email } from '@material-ui/icons';
|
||||
|
||||
const EmailIcon: React.FC = () => <Email fontSize="large" />;
|
||||
|
||||
export default EmailIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Help } from '@material-ui/icons';
|
||||
|
||||
const ExampleIcon: React.FC = () => <Help fontSize="large" />;
|
||||
|
||||
export default ExampleIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { MonetizationOn } from '@material-ui/icons';
|
||||
|
||||
const MarketplaceIcon: React.FC = () => <MonetizationOn fontSize="large" />;
|
||||
|
||||
export default MarketplaceIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Favorite } from '@material-ui/icons';
|
||||
|
||||
const MatchIcon: React.FC = () => <Favorite fontSize="large" />;
|
||||
|
||||
export default MatchIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Message } from '@material-ui/icons';
|
||||
|
||||
const MessagesIcon: React.FC = () => <Message fontSize="large" />;
|
||||
|
||||
export default MessagesIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import StickyNote from '../misc/StickyNote';
|
||||
|
||||
const NotesIcon: React.FC = () => <StickyNote fontSize="large" />;
|
||||
|
||||
export default NotesIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Settings } from '@material-ui/icons';
|
||||
|
||||
const SettingsIcon: React.FC = () => <Settings fontSize="large" />;
|
||||
|
||||
export default SettingsIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Twitter } from '@material-ui/icons';
|
||||
|
||||
const TwitterIcon: React.FC = () => <Twitter fontSize="large" />;
|
||||
|
||||
export default TwitterIcon;
|
||||
@@ -0,0 +1,14 @@
|
||||
import { SvgIconProps } from '@material-ui/core/SvgIcon';
|
||||
import React from 'react';
|
||||
import { SvgIcon } from '@material-ui/core';
|
||||
|
||||
const StickyNote: React.FC<SvgIconProps> = (props) => (
|
||||
<SvgIcon {...props}>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<rect fill="none" />
|
||||
<path d="M19,3H4.99C3.89,3,3,3.9,3,5l0.01,14c0,1.1,0.89,2,1.99,2h10l6-6V5C21,3.9,20.1,3,19,3z M7,8h10v2H7V8z M12,14H7v-2h5V14z M14,19.5V14h5.5L14,19.5z" />
|
||||
</svg>
|
||||
</SvgIcon>
|
||||
);
|
||||
|
||||
export default StickyNote;
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Money } from '@material-ui/icons';
|
||||
import React from 'react';
|
||||
|
||||
const BankIcon: React.FC = () => <Money fontSize="small" />;
|
||||
|
||||
export default BankIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { CalculatorIcon } from '../../../../../apps/calculator/components/CalculatorIcon';
|
||||
|
||||
const Calculator: React.FC = () => <CalculatorIcon fontSize="small" />;
|
||||
|
||||
export default Calculator;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { CameraAlt } from '@material-ui/icons';
|
||||
|
||||
const Camera: React.FC = () => <CameraAlt fontSize="small" />;
|
||||
|
||||
export default Camera;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Contacts } from '@material-ui/icons';
|
||||
|
||||
const ContactIcon: React.FC = () => <Contacts fontSize="small" />;
|
||||
|
||||
export default ContactIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Phone } from '@material-ui/icons';
|
||||
|
||||
const DialerIcon: React.FC = () => <Phone fontSize="small" />;
|
||||
|
||||
export default DialerIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Email } from '@material-ui/icons';
|
||||
|
||||
const EmailIcon: React.FC = () => <Email fontSize="small" />;
|
||||
|
||||
export default EmailIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Help } from '@material-ui/icons';
|
||||
|
||||
const ExampleIcon: React.FC = () => <Help fontSize="small" />;
|
||||
|
||||
export default ExampleIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { MonetizationOn } from '@material-ui/icons';
|
||||
|
||||
const MarketplaceIcon: React.FC = () => <MonetizationOn fontSize="small" />;
|
||||
|
||||
export default MarketplaceIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Favorite } from '@material-ui/icons';
|
||||
|
||||
const MatchIcon: React.FC = () => <Favorite fontSize="small" />;
|
||||
|
||||
export default MatchIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Message } from '@material-ui/icons';
|
||||
|
||||
const MessagesIcon: React.FC = () => <Message fontSize="small" />;
|
||||
|
||||
export default MessagesIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import StickyNote from '../misc/StickyNote';
|
||||
|
||||
const NotesIcon: React.FC = () => <StickyNote fontSize="small" />;
|
||||
|
||||
export default NotesIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Settings } from '@material-ui/icons';
|
||||
|
||||
const SettingsIcon: React.FC = () => <Settings fontSize="small" />;
|
||||
|
||||
export default SettingsIcon;
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Twitter } from '@material-ui/icons';
|
||||
|
||||
const TwitterIcon: React.FC = () => <Twitter fontSize="small" />;
|
||||
|
||||
export default TwitterIcon;
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,9 +1,9 @@
|
||||
import React from 'react';
|
||||
import { darken, makeStyles, Theme } from '@material-ui/core/styles';
|
||||
import Avatar from '@material-ui/core/Avatar';
|
||||
import { green } from '@material-ui/core/colors';
|
||||
import { Badge, Button, Tooltip, Zoom } from '@material-ui/core';
|
||||
import { Avatar, Badge, Button, Tooltip, Zoom } from '@material-ui/core';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { INotificationIcon } from '../../os/notifications/providers/NotificationsProvider';
|
||||
|
||||
const useStyles = makeStyles<Theme, { color: string; backgroundColor: string }>((theme) => ({
|
||||
root: {
|
||||
@@ -31,7 +31,25 @@ const useStyles = makeStyles<Theme, { color: string; backgroundColor: string }>(
|
||||
},
|
||||
}));
|
||||
|
||||
export const AppIcon = ({ id, nameLocale, name, Icon, backgroundColor, color, notification }) => {
|
||||
export interface AppIconProps {
|
||||
id: string;
|
||||
nameLocale: string;
|
||||
Icon: React.ElementType;
|
||||
icon: React.ElementType;
|
||||
backgroundColor: string;
|
||||
color: string;
|
||||
notification: INotificationIcon;
|
||||
}
|
||||
|
||||
export const AppIcon: React.FC<AppIconProps> = ({
|
||||
id,
|
||||
nameLocale,
|
||||
Icon,
|
||||
backgroundColor,
|
||||
color,
|
||||
icon,
|
||||
notification,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const classes = useStyles({
|
||||
backgroundColor: backgroundColor || green[50],
|
||||
@@ -56,7 +74,7 @@ export const AppIcon = ({ id, nameLocale, name, Icon, backgroundColor, color, no
|
||||
{Icon ? (
|
||||
<Icon className={classes.icon} fontSize="large" />
|
||||
) : (
|
||||
<Avatar className={classes.avatar}>{name[0].toUpperCase()}</Avatar>
|
||||
<Avatar className={classes.avatar}>{icon || t(nameLocale)}</Avatar>
|
||||
)}
|
||||
</Badge>
|
||||
</Button>
|
||||
|
||||
Reference in new issue
Block a user