diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64e4839..b69b408 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,8 @@ jobs: run: yarn --frozen-lockfile - name: Run Enzyme Tests run: yarn test + - name: Check build status + run: yarn build env: CI: true @@ -52,9 +54,12 @@ jobs: run: yarn --frozen-lockfile - name: Run Jest Tests run: yarn test + - name: Check build status + run: yarn build env: CI: true + lint: name: Lint Lua scripts runs-on: ubuntu-latest diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml new file mode 100644 index 0000000..750437c --- /dev/null +++ b/.github/workflows/prerelease.yml @@ -0,0 +1,51 @@ +name: Prerelease Publisher +on: + push: + branches: + - master +jobs: + tagged-release: + runs-on: ubuntu-latest + + outputs: + VERSION_TAG: ${{ steps.get_vars.outputs.VERSION_TAG }} + steps: + - name: Install archive tools + run: sudo apt-get install zip gzip tar + - name: Checkout source code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + ref: ${{ github.ref }} + - name: Get variables + run: echo ::set-output name=VERSION_TAG::${GITHUB_REF/refs\/tags\//} + id: get_vars + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn config get cacheFolder)" + - uses: actions/cache@v2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Use Node.js + uses: actions/setup-node@v2 + with: + node-version: '14.x' + - name: Install dependencies + run: yarn --frozen-lockfile + - name: Run build + run: npm run build + - name: Create Release + uses: "marvinpinto/action-automatic-releases@latest" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + prerelease: true + files: | + + id: auto_release + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/tagged-releases.yml b/.github/workflows/tagged-releases.yml new file mode 100644 index 0000000..d5991e1 --- /dev/null +++ b/.github/workflows/tagged-releases.yml @@ -0,0 +1,70 @@ +name: Tagged Release Publisher +on: + push: + tags: + - "v*" +jobs: + create-tagged-release: + runs-on: ubuntu-latest + + outputs: + VERSION_TAG: ${{ steps.get_vars.outputs.VERSION_TAG }} + steps: + - name: Install archive tools + run: sudo apt-get install zip gzip tar + - name: Checkout source code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + ref: ${{ github.ref }} + - name: Get variables + run: echo ::set-output name=VERSION_TAG::${GITHUB_REF/refs\/tags\//} + id: get_vars + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn config get cacheFolder)" + - uses: actions/cache@v2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Use Node.js + uses: actions/setup-node@v2 + with: + node-version: '14.x' + - name: Install dependencies + run: yarn --frozen-lockfile + - name: Run build + run: npm run build + - name: Create Sentry Release + uses: tclindner/sentry-releases-action@v1.2.0 + env: + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + SENTRY_ORG: ${{ secrets.SENTRY_ORG }} + SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} + SENTRY_URL: https://sentry.projecterror.dev/ + with: + environment: production + tagName: ${{ steps.get_vars.outputs.VERSION_TAG }} + sourceMapOptions: './resources/html/static/js' + - name: Bundle built files + run: | + mkdir npwd_temp + mkdir npwd_temp/resources + cp -t npwd_temp/resources -r resources/dist resources/html + cp -t npwd_temp fxmanifest.lua config.json LICENSE README.md + zip -r npwd-${{ steps.get_vars.outputs.VERSION_TAG }} npwd_temp + rm -rf npwd_temp + echo "Cleaned up" + - name: Create Release + uses: "marvinpinto/action-automatic-releases@latest" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + prerelease: false + files: | + "npwd-${{ steps.get_vars.outputs.VERSION_TAG }}" + id: auto_release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2d7d59a..c0795ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,12 @@ # No IDE Folders .idea +npwd_temp + resources/html phone/.eslintcache +phone/.env # Node Modules and Built Folders node_modules @@ -22,4 +25,5 @@ yarn-error.log* sv_npwd.log # FXServer Yarn -.yarn.installed \ No newline at end of file +.yarn.installed +phone/.env diff --git a/config.json b/config.json index f38e291..376c608 100644 --- a/config.json +++ b/config.json @@ -1,15 +1,9 @@ { "Locale": "en", - "KeyTogglePhone": 288, - "KeyTakeCall": 38, - "PhoneAsItem": false, - "SwimDestroy": false, - "RunRate": 10, - "DestroyChance": 100, - "DestroyPhoneReCheck": 3, - "notificationPosition": { - "horizontal": "right", - "vertical": "top" + "PhoneAsItem": { + "enabled": false, + "exportResource": "my-core-resource", + "exportName": "myCheckerFunction" }, "general": { "useDashNumber": true, @@ -42,6 +36,7 @@ }, "debug": { "level": "silly", - "enabled": true + "enabled": true, + "sentryEnabled": true } } diff --git a/package.json b/package.json index 212d75a..3e93e67 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "pretty-quick": "^3.1.0" }, "scripts": { - "build": "lerna run build", + "build": "lerna run test && CI=false lerna run build", "prepare": "husky install", "bootstrap": "lerna bootstrap", "format:staged": "pretty-quick --staged", diff --git a/phone/package.json b/phone/package.json index 98cd222..7fa837c 100644 --- a/phone/package.json +++ b/phone/package.json @@ -28,6 +28,8 @@ }, "devDependencies": { "@craco/craco": "^6.1.1", + "@sentry/integrations": "^6.10.0", + "@sentry/webpack-plugin": "^1.16.0", "@sentry/react": "^5.29.2", "@sentry/tracing": "^5.29.2", "@types/enzyme": "^3.10.7", @@ -40,6 +42,7 @@ "@welldone-software/why-did-you-render": "^6.1.1", "@wojtekmaj/enzyme-adapter-react-17": "^0.6.1", "cross-env": "^7.0.3", + "dotenv": "^10.0.0", "ts-loader": "^8.3.0", "typescript": "^4.3.2" }, @@ -47,6 +50,7 @@ "i18n:missing": "node --experimental-json-modules i18n.missingKeys.js", "start": "cross-env PUBLIC_URL=/ craco start", "watch": "cross-env REACT_APP_IN_GAME=1 craco start", + "build:release": "cross-env SENTRY_RELEASE=true craco build", "build": "craco build", "test": "craco test --watchAll=false --testMatch **/src/**/*.test.{ts,js,tsx}" }, diff --git a/phone/public/iframe.webcomp.js b/phone/public/iframe.webcomp.js new file mode 100644 index 0000000..f26f1d2 --- /dev/null +++ b/phone/public/iframe.webcomp.js @@ -0,0 +1,96 @@ +customElements.define( + 'x-frame-bypass', + class extends HTMLIFrameElement { + static get observedAttributes() { + return ['src']; + } + constructor() { + super(); + } + attributeChangedCallback() { + this.load(this.src); + } + connectedCallback() { + this.sandbox = + '' + this.sandbox || + 'allow-forms allow-modals allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation-by-user-activation'; // all except allow-top-navigation + } + load(url, options) { + if (!url || !url.startsWith('http')) + throw new Error(`Unable to load src ${url} does not start with http(s)://`); + this.srcdoc = ` + + + + +
+ +`; + this.fetchProxy(url, options, 0) + .then((res) => res.text()) + .then((data) => { + if (data) + this.srcdoc = data.replace( + /]*)>/i, + ` + + `, + ); + }) + .catch((e) => console.error('Unable to load proxy iframe service', e)); + } + fetchProxy(url, options, i) { + const proxies = (options || {}).proxies || [ + 'https://cors-anywhere.herokuapp.com/', + 'https://api.codetabs.com/v1/proxy/?quest=', + ]; + return fetch(proxies[i] + url, options) + .then((res) => { + if (!res.ok) throw new Error(`${res.status} ${res.statusText}`); + return res; + }) + .catch((error) => { + if (i === proxies.length - 1) throw error; + return this.fetchProxy(url, options, i + 1); + }); + } + }, + { extends: 'iframe' }, +); diff --git a/phone/public/index.html b/phone/public/index.html index 8e9020a..f82138b 100644 --- a/phone/public/index.html +++ b/phone/public/index.html @@ -8,6 +8,8 @@ /> + + Project Error - New Phone Who Dis diff --git a/phone/public/media/misc/Outgoing-Dial-Effect.ogg b/phone/public/media/misc/Outgoing-Dial-Effect.ogg new file mode 100644 index 0000000..52a1720 Binary files /dev/null and b/phone/public/media/misc/Outgoing-Dial-Effect.ogg differ diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index a0a9a88..ec6cb71 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -9,13 +9,10 @@ import { Navigation } from './os/navigation-bar/components/Navigation'; import { useSimcardService } from './os/simcard/hooks/useSimcardService'; import { usePhoneService } from './os/phone/hooks/usePhoneService'; import { useApps } from './os/apps/hooks/useApps'; -import { useNuiRequest } from 'fivem-nui-react-lib'; import { useTwitterService } from './apps/twitter/hooks/useTwitterService'; -import { useMatchService } from './apps/match/hooks/useMatchService'; import { useMarketplaceService } from './apps/marketplace/hooks/useMarketplaceService'; import { useBankService } from './apps/bank/hooks/useBankService'; import { useMessagesService } from './apps/messages/hooks/useMessageService'; -import { usePhotoService } from './apps/camera/hooks/usePhotoService'; import { isSettingsSchemaValid, useSettings } from './apps/settings/hooks/useSettings'; import { useCallService } from './os/call/hooks/useCallService'; import { useDialService } from './apps/dialer/hooks/useDialService'; @@ -32,6 +29,8 @@ import PhoneWrapper from './PhoneWrapper'; import dayjs from 'dayjs'; import DefaultConfig from '../../config.json'; +import { TopLevelErrorComponent } from './ui/components/TopLevelErrorComponent'; +import { useConfig } from './os/phone/hooks/useConfig'; function Phone() { const { t, i18n } = useTranslation(); @@ -42,8 +41,6 @@ function Phone() { const { addAlert } = useSnackbar(); - const Nui = useNuiRequest(); - // Set language from local storage // This will only trigger on first mount & settings changes useEffect(() => { @@ -62,15 +59,16 @@ function Phone() { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + useConfig(); + useKeyboardService(); usePhoneService(); useSimcardService(); useTwitterService(); - useMatchService(); useMarketplaceService(); useBankService(); useMessagesService(); - usePhotoService(); + /*usePhotoService();*/ useCallService(); useDialService(); @@ -78,22 +76,24 @@ function Phone() { return (
- - - -
- <> - - {callModal && } - {apps.map((App) => ( - - ))} - - - -
- -
+ + + + +
+ <> + + {callModal && } + {apps.map((App) => ( + + ))} + + + +
+ +
+
); } diff --git a/phone/src/apps/bank/components/transactions/TransactionList.tsx b/phone/src/apps/bank/components/transactions/TransactionList.tsx index 55fa842..12ecaac 100644 --- a/phone/src/apps/bank/components/transactions/TransactionList.tsx +++ b/phone/src/apps/bank/components/transactions/TransactionList.tsx @@ -49,16 +49,6 @@ export const TransactionList = () => { ))} - ); diff --git a/phone/src/apps/browser/components/BrowserApp.tsx b/phone/src/apps/browser/components/BrowserApp.tsx new file mode 100644 index 0000000..f4bc5ad --- /dev/null +++ b/phone/src/apps/browser/components/BrowserApp.tsx @@ -0,0 +1,108 @@ +import { AppWrapper } from '../../../ui/components'; +import React, { Reducer, useReducer, useRef } from 'react'; +import { AppContent } from '../../../ui/components/AppContent'; +import { Box, makeStyles } from '@material-ui/core'; +import { BrowserURLBar } from './BrowserURLBar'; +import { promiseTimeout } from '../../../utils/promiseTimeout'; +import { usePhoneConfig } from '../../../config/hooks/usePhoneConfig'; + +const useStyles = makeStyles(() => ({ + iframe: { + height: '100%', + width: '100%', + zoom: 0.5, + border: 'none', + }, + root: { + height: '100%', + display: 'flex', + flexDirection: 'column', + }, +})); + +interface BrowserState { + browserUrl: string; + browserHistory: string[]; +} + +interface ReducerAction { + payload: any; + type: ReducerActionsType; +} + +enum ReducerActionsType { + SET_URL, + ADD_HISTORY, + RELOAD, +} + +const browserReducer: Reducer = (state, action) => { + switch (action.type) { + case ReducerActionsType.ADD_HISTORY: + if (action.payload === 'about:blank') return state; + return { ...state, browserHistory: state.browserHistory.concat(action.payload) }; + case ReducerActionsType.SET_URL: + return { ...state, browserUrl: action.payload }; + default: + throw new Error('Invalid reducer action type'); + } +}; + +export const BrowserApp: React.FC = () => { + const classes = useStyles(); + const [{ appSettings }] = usePhoneConfig(); + const [browserState, dispatch] = useReducer(browserReducer, { + browserUrl: appSettings.browserHomePage, + browserHistory: [appSettings.browserHomePage], + }); + + const { browserHistory, browserUrl } = browserState; + + const iframeRef = useRef(null); + const _setBrowserUrl = (newUrl: string) => { + const formattedUrl = newUrl.match(/^(http|https):\/\//) ? newUrl : 'https://' + newUrl; + dispatch({ payload: browserUrl, type: ReducerActionsType.ADD_HISTORY }); + dispatch({ payload: formattedUrl, type: ReducerActionsType.SET_URL }); + }; + + const handleGoBack = () => { + if (browserHistory.length <= 1) return; + // Get last page from history + const lastPage = browserHistory[browserHistory.length - 1]; + + // Bail if last page is same as current + if (lastPage === browserUrl) return; + _setBrowserUrl(lastPage); + }; + + const reloadPage = async () => { + const strCopy = browserUrl.slice(); + dispatch({ payload: 'about:blank', type: ReducerActionsType.SET_URL }); + await promiseTimeout(100); + dispatch({ payload: strCopy, type: ReducerActionsType.SET_URL }); + }; + + return ( + + + 1} + setBrowser={_setBrowserUrl} + goBack={handleGoBack} + reloadPage={reloadPage} + /> + +