{
icon={}
/>
+
}
+ >
+ }
+ />
+
+
+
+
+
+
+
+
+
+ handleSettingChange('TWITTER_notificationVol', sliders[2])
+ }
+ />
+
+
+
+
diff --git a/phone/src/apps/settings/hooks/useSettings.ts b/phone/src/apps/settings/hooks/useSettings.ts
index 86eae75..c2dc1c6 100644
--- a/phone/src/apps/settings/hooks/useSettings.ts
+++ b/phone/src/apps/settings/hooks/useSettings.ts
@@ -22,13 +22,18 @@ export const settingsState = atom({
effects_UNSTABLE: [localStorageEffect('settings')],
});
-interface IPhoneSettings {
+export interface IPhoneSettings {
wallpaper: string;
frame: string;
theme: string;
zoom: number;
ringtone: string;
ringtoneVol: number;
+ notification: string;
+ notificationVol: number;
+ TWITTER_notification: string;
+ TWITTER_notificationVol: number;
+ TWITTER_notifyNewFeedTweet: boolean;
}
export const useSettings = () => {
diff --git a/phone/src/apps/settings/utils/getRingtonePath.ts b/phone/src/apps/settings/utils/getRingtonePath.ts
new file mode 100644
index 0000000..2bf991c
--- /dev/null
+++ b/phone/src/apps/settings/utils/getRingtonePath.ts
@@ -0,0 +1,5 @@
+export const getRingtonePath = (name?: string) =>
+ `./media/ringtones/${name || 'pixel'}.ogg`;
+
+export const getNotificationPath = (name?: string) =>
+ `./media/notifications/${name || 'online'}.ogg`;
diff --git a/phone/src/apps/twitter/components/TwitterApp.tsx b/phone/src/apps/twitter/components/TwitterApp.tsx
index d86a8cd..583a89a 100644
--- a/phone/src/apps/twitter/components/TwitterApp.tsx
+++ b/phone/src/apps/twitter/components/TwitterApp.tsx
@@ -190,5 +190,5 @@ InjectDebugData(
},
},
],
- 2000
+ 3000
);
diff --git a/phone/src/apps/twitter/components/tweet/Tweet.tsx b/phone/src/apps/twitter/components/tweet/Tweet.tsx
index d382a36..cf1255d 100644
--- a/phone/src/apps/twitter/components/tweet/Tweet.tsx
+++ b/phone/src/apps/twitter/components/tweet/Tweet.tsx
@@ -48,6 +48,7 @@ const useStyles = makeStyles(() => ({
},
message: {
fontSize: '18px',
+ wordBreak: 'break-all',
},
buttonContainer: {
display: 'flex',
diff --git a/phone/src/apps/twitter/hooks/useTwitterNotifications.ts b/phone/src/apps/twitter/hooks/useTwitterNotifications.ts
index d6cb625..977b350 100644
--- a/phone/src/apps/twitter/hooks/useTwitterNotifications.ts
+++ b/phone/src/apps/twitter/hooks/useTwitterNotifications.ts
@@ -1,17 +1,23 @@
-import { useCallback } from "react";
-import { useTranslation } from "react-i18next";
-import { useHistory } from "react-router-dom";
-import { useRecoilState } from "recoil";
-import { useApp } from "../../../os/apps/hooks/useApps";
-import { useNotifications } from "../../../os/notifications/hooks/useNotifications";
-import { twitterState } from "./state";
+import { useCallback } from 'react';
+import { useTranslation } from 'react-i18next';
+import { useHistory } from 'react-router-dom';
+import { useRecoilState } from 'recoil';
+import { useApp } from '../../../os/apps/hooks/useApps';
+import { useNotifications } from '../../../os/notifications/hooks/useNotifications';
+import { twitterState } from './state';
export const useTwitterNotifications = () => {
const { t } = useTranslation();
const history = useHistory();
+
const { addNotificationAlert } = useNotifications();
+
const { icon, notificationIcon } = useApp('TWITTER');
- const [unreadCount, setUnreadCount] = useRecoilState(twitterState.unreadTweetsCount);
+
+ const [unreadCount, setUnreadCount] = useRecoilState(
+ twitterState.unreadTweetsCount
+ );
+
const setNotification = useCallback(
({ profile_name, message }) => {
setUnreadCount((curr) => {
@@ -19,6 +25,7 @@ export const useTwitterNotifications = () => {
addNotificationAlert(
{
app: 'TWITTER',
+ sound: true,
title: t('APPS_TWITTER_NEW_BROADCAST', { profile_name }),
onClick: () => history.push('/twitter'),
content: message,
@@ -39,5 +46,5 @@ export const useTwitterNotifications = () => {
[setUnreadCount, addNotificationAlert, t, icon, notificationIcon, history]
);
- return { setNotification, setUnreadCount, unreadCount }
+ return { setNotification, setUnreadCount, unreadCount };
};
diff --git a/phone/src/common/utils/usePreviousState.ts b/phone/src/common/utils/usePreviousState.ts
new file mode 100644
index 0000000..11584dd
--- /dev/null
+++ b/phone/src/common/utils/usePreviousState.ts
@@ -0,0 +1,13 @@
+import { useEffect, useRef } from 'react';
+
+export function usePreviousState(value) {
+ // The ref object is a generic container whose current property is mutable ...
+ // ... and can hold any value, similar to an instance property on a class
+ const ref = useRef();
+ // Store current value in ref
+ useEffect(() => {
+ ref.current = value;
+ }, [value]); // Only re-run if value changes
+ // Return previous value (happens before update in useEffect above)
+ return ref.current;
+}
diff --git a/phone/src/config/default.json b/phone/src/config/default.json
index 17eb8bb..7dd1144 100644
--- a/phone/src/config/default.json
+++ b/phone/src/config/default.json
@@ -1,14 +1,25 @@
{
"cellProvider": "AT&T",
"language": "en",
- "wallpapers": ["beach.jpg", "minimal.jpg", "surf.jpg", "waves.jpg", "projecterror.jpg"],
+ "wallpapers": [
+ "beach.jpg",
+ "minimal.jpg",
+ "surf.jpg",
+ "waves.jpg",
+ "projecterror.jpg"
+ ],
"defaultSettings": {
"wallpaper": "projecterror.jpg",
"frame": "default.png",
"theme": "taso-dark",
"zoom": 1,
"ringtone": "pixel",
- "ringtoneVol": 100
+ "ringtoneVol": 50,
+ "notification": "online",
+ "notificationVol": 50,
+ "TWITTER_notification": "online",
+ "TWITTER_notificationVol": 100,
+ "TWITTER_notifyNewFeedTweet": true
},
"debug": {
"printDebugLogs": true,
@@ -25,6 +36,7 @@
],
"zoomOptions": [1, 0.9, 0.8],
"ringtones": ["marimba", "pixel"],
+ "notifications": ["online", "99kr"],
"themes": {
"default-dark": {
"palette": {
@@ -44,7 +56,7 @@
"palette": {
"type": "dark",
"primary": {
- "main": "#a6d4fa"
+ "main": "#a6d4fa"
},
"background": {
"paper": "#1c1c1c",
diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json
index b1872dc..aaa5a68 100644
--- a/phone/src/locale/en.json
+++ b/phone/src/locale/en.json
@@ -103,9 +103,6 @@
"APPS_CALCULATOR_COPIED": "Result was copied to clipboard!",
- "APPS_MARKETPLACE_CREATE_LISTING_SUCCESS": "Successfully created a new listing",
- "APPS_MARKETPALCE_CREATE_LISTING_FAILED": "Failed to create a new listing",
-
"APPS_SETTINGS_PHONE_NUMBER": "Phone Number",
"APPS_SETTINGS_OPTION_WALLPAPER": "Wallpaper",
"APPS_SETTINGS_OPTION_FRAME": "Frame",
@@ -113,10 +110,12 @@
"APPS_SETTINGS_OPTION_ZOOM": "Zoom",
"APPS_SETTINGS_OPTION_RINGTONE": "Ringtone",
"APPS_SETTINGS_OPTION_RINGTONEVOL": "Ringtone Volume",
-
"APPS_SETTINGS_OPTION_NOTIFICATION": "Notification",
"APPS_SETTINGS_OPTION_NOTIFICATIONVOL": "Notification Volume",
+ "APPS_MARKETPLACE_CREATE_LISTING_SUCCESS": "Successfully created a new listing",
+ "APPS_MARKETPALCE_CREATE_LISTING_FAILED": "Failed to create a new listing",
+
"GENERIC_SAVE": "Save",
"GENERIC_UPDATE": "Update",
"GENERIC_DELETE": "Delete",
diff --git a/phone/src/os/call/components/CallTimer.tsx b/phone/src/os/call/components/CallTimer.tsx
index 2b6414b..4a65284 100644
--- a/phone/src/os/call/components/CallTimer.tsx
+++ b/phone/src/os/call/components/CallTimer.tsx
@@ -38,7 +38,7 @@ function CallTimer({ isAccepted }) {
return () => clearInterval(timer.current)
}, [isAccepted, setDuration]);
- if (!duration) return null;
+ if (!duration || !isAccepted) return null;
return (
{
+ const { t } = useTranslation();
+ const history = useHistory();
+ const { addNotificationAlert, removeId } = useNotifications();
+
+ const { play, stop, playing } = useRingtoneSound();
+
+ const { icon, notificationIcon } = useApp('DIALER');
+
+ const callNotificationBase = {
+ app: 'CALL',
+ id: NOTIFICATION_ID,
+ cantClose: true,
+ icon,
+ onClick: () => history.push('/call'),
+ notificationIcon,
+ };
+
+ const { call } = useCall();
+
+ const setNotification = (call: CallProps) => {
+ if (!call || !call.active) {
+ stop();
+ removeId(NOTIFICATION_ID);
+ return;
+ }
+ if (call.accepted) {
+ stop();
+ removeId(NOTIFICATION_ID);
+ addNotificationAlert(
+ {
+ ...callNotificationBase,
+ keepWhenPhoneClosed: true,
+ content: (
+
+ {t('APPS_DIALER_CURRENT_CALL_WITH', {
+ transmitter: call.transmitter,
+ })}
+
+ ),
+ title: t('APPS_DIALER_CURRENT_CALL_TITLE'),
+ },
+ true
+ );
+ }
+ if (!call.isTransmitter && !call.accepted) {
+ if (!playing()) {
+ play();
+ }
+ removeId(NOTIFICATION_ID);
+ addNotificationAlert(
+ {
+ ...callNotificationBase,
+ title: t('APPS_DIALER_INCOMING_CALL_TITLE', {
+ transmitter: call.transmitter,
+ }),
+ keepWhenPhoneClosed: true,
+ content: (
+
+ {t('APPS_DIALER_TRANSMITTER_IS_CALLING', {
+ transmitter: call.transmitter,
+ })}
+
+ ),
+ },
+ true
+ );
+ }
+ };
+
+ const resetCallNotification = () => setNotification(call);
+
+ return { setNotification, resetCallNotification };
+};
diff --git a/phone/src/os/call/hooks/useCallService.tsx b/phone/src/os/call/hooks/useCallService.tsx
index cc39dc8..13e9fc9 100644
--- a/phone/src/os/call/hooks/useCallService.tsx
+++ b/phone/src/os/call/hooks/useCallService.tsx
@@ -1,18 +1,14 @@
-import React, { useEffect, useState } from 'react';
+import { useEffect, useState } from 'react';
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
import { useSetRecoilState } from 'recoil';
-import { callerState } from './state';
-import { useNotifications } from '../../notifications/hooks/useNotifications';
-import { useTranslation } from 'react-i18next';
-import { CallNotification } from '../components/CallNotification';
import { useCall } from './useCall';
import { CallProps } from '../../../common/typings/call';
-import { useApp } from '../../apps/hooks/useApps';
import InjectDebugData from '../../debug/InjectDebugData';
import { useCallModal } from './useCallModal';
import { useHistory, useLocation } from 'react-router-dom';
-
-const NOTIFICATION_ID = 'call:current';
+import { callerState } from './state';
+import { useCallNotifications } from './useCallNotifications';
+import { useDuration } from './useDuration';
InjectDebugData([
/* {
@@ -22,7 +18,7 @@ InjectDebugData([
accepted: false,
isTransmitter: false,
transmitter: 'Chip',
- receiver: 'Taso',
+ receiver: 'Taso',
active: true,
},
},
@@ -34,33 +30,19 @@ InjectDebugData([
]);
export const useCallService = () => {
- const { t } = useTranslation();
const { modal } = useCallModal();
const history = useHistory();
const { pathname } = useLocation();
- const {
- addNotificationAlert,
- removeId,
- addNotification,
- } = useNotifications();
const { call, setCall } = useCall();
+ const { resetDuration } = useDuration();
- const { icon, notificationIcon } = useApp('DIALER');
+ const { setNotification } = useCallNotifications();
const setModal = useSetRecoilState(callerState.callModal);
const [modalHasBeenOpenedThisCall, setModalOpened] = useState(false);
- const callNotificationBase = {
- app: 'CALL',
- id: NOTIFICATION_ID,
- cantClose: true,
- icon,
- onClick: () => history.push('/call'),
- notificationIcon,
- };
-
useEffect(() => {
setModalOpened(!!modal);
}, [modal]);
@@ -75,47 +57,10 @@ export const useCallService = () => {
}, [history, modal, pathname, modalHasBeenOpenedThisCall]);
const _setCall = (_call: CallProps) => {
+ resetDuration();
setCall(_call);
- if (!_call || !_call.active) {
- removeId(NOTIFICATION_ID);
- return;
- }
- if (_call.accepted) {
- removeId(NOTIFICATION_ID);
- addNotification({
- ...callNotificationBase,
- content: (
-
- {t('APPS_DIALER_CURRENT_CALL_WITH', {
- transmitter: _call.transmitter,
- })}
-
- ),
- title: t('APPS_DIALER_CURRENT_CALL_TITLE'),
- });
- }
- if (!_call.isTransmitter && !_call.accepted) {
- removeId(NOTIFICATION_ID);
- addNotificationAlert(
- {
- ...callNotificationBase,
- title: t('APPS_DIALER_INCOMING_CALL_TITLE', {
- transmitter: _call.transmitter,
- }),
- keepWhenPhoneClosed: true,
- content: (
-
- {t('APPS_DIALER_TRANSMITTER_IS_CALLING', {
- transmitter: _call.transmitter,
- })}
-
- ),
- },
- true
- );
- }
+ setNotification(_call);
};
-
useNuiEvent('CALL', 'setCaller', _setCall, call);
useNuiEvent('CALL', 'callModal', setModal);
};
diff --git a/phone/src/os/call/hooks/useDuration.ts b/phone/src/os/call/hooks/useDuration.ts
index 67a143a..52220e5 100644
--- a/phone/src/os/call/hooks/useDuration.ts
+++ b/phone/src/os/call/hooks/useDuration.ts
@@ -1,7 +1,14 @@
+import { useCallback } from 'react';
import { useRecoilState } from 'recoil';
import { callerState } from './state';
export const useDuration = () => {
const [duration, setDuration] = useRecoilState(callerState.callDuration);
- return { duration, setDuration}
-}
\ No newline at end of file
+
+ const resetDuration = useCallback(
+ () => setDuration({ ms: 0, s: 0, m: 0, h: 0 }),
+ [setDuration]
+ );
+
+ return { duration, setDuration, resetDuration };
+};
diff --git a/phone/src/os/notifications/components/NotificationAlert.tsx b/phone/src/os/notifications/components/NotificationAlert.tsx
index c7d3044..c5e8f5b 100644
--- a/phone/src/os/notifications/components/NotificationAlert.tsx
+++ b/phone/src/os/notifications/components/NotificationAlert.tsx
@@ -29,6 +29,7 @@ const useStyles = makeStyles((theme) => ({
},
},
alertContent: {
+ wordBreak: 'break-all',
display: '-webkit-box',
maxWidth: '360px',
height: '60px',
diff --git a/phone/src/os/notifications/providers/NotificationsProvider.tsx b/phone/src/os/notifications/providers/NotificationsProvider.tsx
index 05ee812..43d69d7 100644
--- a/phone/src/os/notifications/providers/NotificationsProvider.tsx
+++ b/phone/src/os/notifications/providers/NotificationsProvider.tsx
@@ -5,9 +5,13 @@ import React, {
useMemo,
useRef,
useEffect,
+ useContext,
} from 'react';
import { useRecoilValue } from 'recoil';
+import { useSettings } from '../../../apps/settings/hooks/useSettings';
import { phoneState } from '../../phone/hooks/state';
+import { soundContext } from '../../sound/providers/SoundProvider';
+import { getSoundSettings } from '../../sound/utils/getSoundSettings';
import { DEFAULT_ALERT_HIDE_TIME } from '../notifications.constants';
export interface INotification {
@@ -17,6 +21,7 @@ export interface INotification {
content?: React.ReactNode;
icon?: JSX.Element;
notificationIcon?: JSX.Element;
+ sound?: boolean;
cantClose?: boolean;
keepWhenPhoneClosed?: boolean;
onClose?: (notification: INotification) => void;
@@ -59,13 +64,17 @@ export const NotificationsContext = createContext<{
export function NotificationsProvider({ children }) {
const isPhoneOpen = useRecoilValue(phoneState.visibility);
+ const [settings] = useSettings();
+
const [barUncollapsed, setBarUncollapsed] = useState(false);
const [notifications, setNotifications] = useState([]);
+ const { mount, play } = useContext(soundContext);
+
const alertTimeout = useRef();
const [alerts, setAlerts] = useState<
- Array<[INotification, boolean, Partial]>
+ Array<[INotification, boolean, Partial, string | undefined]>
>([]);
const [currentAlert, setCurrentAlert] = useState();
@@ -122,7 +131,12 @@ export function NotificationsProvider({ children }) {
);
const _showAlert = useCallback(
- (n: INotification, persist: boolean, update: Partial) => {
+ (
+ n: INotification,
+ persist: boolean,
+ update: Partial,
+ soundUrl: string
+ ) => {
return new Promise((res) => {
const resolve = () => {
if (persist) {
@@ -144,6 +158,10 @@ export function NotificationsProvider({ children }) {
onCloseAlert: onExit(n.onClose),
});
+ if (n.sound && soundUrl) {
+ play(soundUrl);
+ }
+
if (n.keepWhenPhoneClosed) {
return;
}
@@ -155,7 +173,7 @@ export function NotificationsProvider({ children }) {
}, DEFAULT_ALERT_HIDE_TIME + 300);
});
},
- [addOrUpdateNotification]
+ [addOrUpdateNotification, play]
);
const addNotificationAlert = (
@@ -163,7 +181,18 @@ export function NotificationsProvider({ children }) {
persist?: boolean,
update?: Partial
) => {
- setAlerts((curr) => [...curr, [n, persist, update]]);
+ if (n.sound) {
+ const { sound, volume } = getSoundSettings(
+ 'notification',
+ settings,
+ n.app
+ );
+ mount(sound, volume, false).then(({ url }) =>
+ setAlerts((curr) => [...curr, [n, persist, update, url]])
+ );
+ return;
+ }
+ setAlerts((curr) => [...curr, [n, persist, update, undefined]]);
};
const removeId = (id: string) => {
diff --git a/phone/src/os/phone/hooks/usePhone.ts b/phone/src/os/phone/hooks/usePhone.ts
index b511a69..acdde8d 100644
--- a/phone/src/os/phone/hooks/usePhone.ts
+++ b/phone/src/os/phone/hooks/usePhone.ts
@@ -1,6 +1,7 @@
import { useRecoilValue } from 'recoil';
import { IServerConfig } from '../../../common/typings/config';
import ServerConfig from '../../../config.autogen.json';
+import { useCallNotifications } from '../../call/hooks/useCallNotifications';
import { useNotifications } from '../../notifications/hooks/useNotifications';
import Nui from '../../nui-events/utils/Nui';
import { phoneState } from './state';
@@ -16,9 +17,11 @@ export const usePhone = (): IUsePhone => {
const isPhoneOpen = useRecoilValue(phoneState.visibility);
const { removeAlerts } = useNotifications();
+ const { resetCallNotification } = useCallNotifications();
const closePhone = () => {
removeAlerts();
+ resetCallNotification();
Nui.send('phone:close');
};
const openPhone = () => {
diff --git a/phone/src/os/phone/hooks/usePhoneVisibility.ts b/phone/src/os/phone/hooks/usePhoneVisibility.ts
index e279dfa..6f27bab 100644
--- a/phone/src/os/phone/hooks/usePhoneVisibility.ts
+++ b/phone/src/os/phone/hooks/usePhoneVisibility.ts
@@ -38,7 +38,7 @@ export const usePhoneVisibility = () => {
const bottom = useMemo(() => {
if (!visibility) {
- return `calc(-70% * ${zoom})`;
+ return `calc(-728px * ${zoom})`;
}
return 0;
}, [visibility, zoom]);
diff --git a/phone/src/os/sound/hooks/useRingtoneSound.ts b/phone/src/os/sound/hooks/useRingtoneSound.ts
new file mode 100644
index 0000000..3792ccf
--- /dev/null
+++ b/phone/src/os/sound/hooks/useRingtoneSound.ts
@@ -0,0 +1,47 @@
+import { useCallback, useContext, useEffect, useMemo } from 'react';
+import { useSettings } from '../../../apps/settings/hooks/useSettings';
+import { soundContext } from '../providers/SoundProvider';
+import { getSoundSettings } from '../utils/getSoundSettings';
+
+export const useRingtoneSound = () => {
+ const [settings] = useSettings();
+
+ const context = useContext(soundContext);
+
+ if (!context) {
+ throw new Error('useRingtoneSound must be wrapped in SoundProvider');
+ }
+
+ const options = useMemo(() => getSoundSettings('ringtone', settings), [
+ settings,
+ ]);
+
+ useEffect(() => {
+ if (!context.isMounted(options.sound)) {
+ context.mount(options.sound, options.volume, true);
+ return;
+ }
+ context.volume(options.sound, options.volume);
+ }, [context, options.sound, options.volume]);
+
+ const play = useCallback(() => {
+ context.play(options.sound, options.volume, true);
+ }, [context, options.sound, options.volume]);
+
+ const stop = useCallback(() => {
+ context.stop(options.sound);
+ }, [context, options.sound]);
+
+ const playing = useCallback(() => {
+ return context.playing(options.sound);
+ }, [context, options.sound]);
+
+ return useMemo(
+ () => ({
+ play,
+ stop,
+ playing,
+ }),
+ [play, playing, stop]
+ );
+};
diff --git a/phone/src/os/phone/hooks/useSound.ts b/phone/src/os/sound/hooks/useSound.ts
similarity index 100%
rename from phone/src/os/phone/hooks/useSound.ts
rename to phone/src/os/sound/hooks/useSound.ts
diff --git a/phone/src/os/sound/providers/SoundProvider.tsx b/phone/src/os/sound/providers/SoundProvider.tsx
new file mode 100644
index 0000000..f620851
--- /dev/null
+++ b/phone/src/os/sound/providers/SoundProvider.tsx
@@ -0,0 +1,154 @@
+import { Howl } from 'howler';
+import React, { createContext, useCallback, useEffect, useRef } from 'react';
+
+interface IMountResponse {
+ howl: Howl;
+ url: string;
+}
+
+interface ISoundContext {
+ mount(
+ url: string,
+ volume?: number,
+ loop?: boolean,
+ autoplay?: boolean
+ ): Promise;
+ play(url?: string, volume?: number, loop?: boolean): void;
+ stop(url: string): void;
+ remove(url: string): boolean;
+ volume(url: string, volume?: number): number;
+ playing(url: string): boolean;
+ isMounted(url: string): boolean;
+}
+
+export const soundContext = createContext(null);
+
+export const SoundProvider = ({ children }: { children: React.ReactNode }) => {
+ const soundRefs = useRef