Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/ip-1.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
rleojoseph authored Mar 12, 2024
2 parents b9dd262 + 466d90b commit 0e14859
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 13 deletions.
33 changes: 33 additions & 0 deletions js-miniapp-bridge/src/common-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,22 @@ export class MiniAppBridge {
});
}

/**
* Associating miniAppFinishedLoading function to MiniAppBridge object.
* @returns Promise resolve with string
* Host app can implement an interface miniAppFinishedLoading to perform any operations after the miniapp is loaded.
*/
miniAppFinishedLoading() {
return new Promise<string>((resolve, reject) => {
return this.executor.exec(
'miniAppFinishedLoading',
null,
success => resolve(success),
error => reject(error)
);
});
}

/**
* This will retrieve the list of products details available for In-App Purchases associated with Mini App in the Platform.
* @returns List of In-app purchase products
Expand Down Expand Up @@ -883,6 +899,23 @@ export class MiniAppBridge {
clearMiniAppPreferences() {
return this.preferences.clearMiniAppPreferences();
}

/**
* This interface will get you the list of all features that is supported by the SDK and Host application
* @returns List of features for eg., ["GET_UNIQUE_ID", "GET_USERNAME", "GET_PROFILE_PHOTO", "IS_DARK_MODE"]
*/
getFeatureList() {
return new Promise<string[]>((resolve, reject) => {
return this.executor.exec(
'getFeatureList',
null,
response => {
resolve(JSON.parse(response) as string[]);
},
error => reject(parseMiniAppError(error))
);
});
}
}

/**
Expand Down
47 changes: 46 additions & 1 deletion js-miniapp-sample/src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import ConsoleView from './pages/console-view';

import { makeStyles, ThemeProvider } from '@material-ui/core';
Expand All @@ -7,22 +7,67 @@ import { Provider } from 'react-redux';
import Home from './pages/home';
import store from './services/store';
import Theme from './theme';
import MiniApp from 'js-miniapp-sdk';

const useStyles = makeStyles((theme) => ({
App: {
width: '100%',
textAlign: 'center',
},
toastStyle: {
position: 'fixed',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
padding: '10px',
backgroundColor: '#444',
color: 'white',
borderRadius: '5px',
zIndex: '9999',
textAlign: 'center',
},
}));

function App() {
const classes = useStyles();
const [toastVisible, setToastVisible] = useState(false);

useEffect(() => {
try {
if (document.readyState === 'complete') {
miniAppDidFinishLoad();
console.log('Called Miniapp FinishedLoad()');
}
} catch (e) {
console.log(e);
}
}, []);

function miniAppDidFinishLoad() {
MiniApp.miniappUtils
.miniAppFinishedLoading()
.then((response) => {
console.log('miniAppFinishedLoading(): ', response);
setToastVisible(true);
const timer = setTimeout(() => setToastVisible(false), 5000);
return () => clearTimeout(timer);
})
.catch((miniAppError) => {
console.log('miniAppFinishedLoading - Error: ', miniAppError);
});
}

return (
<Provider store={store}>
<ThemeProvider theme={Theme}>
<div className={classes.App}>
<Home />
<ConsoleView />
{toastVisible && (
<div className={classes.toastStyle}>
HostApp was notified successfully.
</div>
)}
</div>
</ThemeProvider>
</Provider>
Expand Down
91 changes: 91 additions & 0 deletions js-miniapp-sample/src/pages/feature-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React, { useEffect, useState } from 'react';

import { makeStyles } from '@material-ui/core';
import MiniApp from 'js-miniapp-sdk';
import ListItem from '@mui/material/ListItem';
import ListItemButton from '@mui/material/ListItemButton';
import ListItemIcon from '@mui/material/ListItemIcon';
import ListItemText from '@mui/material/ListItemText';
import Brightness1Icon from '@mui/icons-material/Brightness1';

const useStyles = makeStyles((theme) => ({
content: {
height: '25%',
justifyContent: 'center',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
fontSize: 18,
color: theme.color.primary,
fontWeight: 'bold',
},
card: {
marginTop: '40px',
},
actions: {
justifyContent: 'center',
flexDirection: 'column',
},
button: {
marginTop: '20px',
width: '80%',
maxWidth: 280,
},
textfield: {
width: '80%',
maxWidth: 300,
'& input': {
color: theme.color.primary,
lineHeight: '1.5em',
fontSize: '1.2em',
background: 'white',
},
},
scrollable: {
overflowY: 'auto',
width: '100%',
paddingBottom: 20,
},
}));

function FeatureListComponent() {
const classes = useStyles();
const [featureList, setFeatureList] = useState();
useEffect(() => {
try {
getFeatureList();
} catch (e) {
console.log(e);
}
});

function getFeatureList() {
MiniApp.miniappUtils
.getFeatureList()
.then((response) => {
setFeatureList(response);
console.log('getFeatureList SUCCESS: ', response);
})
.catch((error) => {
console.log('getFeatureList ERROR: ', error);
});
}

return (
<div className={classes.scrollable}>
{featureList &&
featureList.map((item) => (
<ListItem key={item} disablePadding>
<ListItemButton>
<ListItemIcon>
<Brightness1Icon />
</ListItemIcon>
<ListItemText primary={item} />
</ListItemButton>
</ListItem>
))}
</div>
);
}

export default FeatureListComponent;
13 changes: 13 additions & 0 deletions js-miniapp-sample/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ShareIcon from '@material-ui/icons/Share';
import StorageIcon from '@material-ui/icons/Storage';
import VpnKeyIcon from '@material-ui/icons/VpnKey';
import ArtTrackIcon from '@material-ui/icons/ArtTrack';
import FormatListNumberedIcon from '@material-ui/icons/FormatListNumbered';

import Ads from './pages/ads';
import { CloseConfirmAlert } from './pages/app-close-alert';
Expand All @@ -47,6 +48,7 @@ import WebLocation from './pages/web-location';
import WindowActions from './pages/window-actions';
import CookieManagerComponent from './pages/cookie-manager';
import { MiniAppPreferenceComponent } from './pages/miniapp-preferences';
import FeatureListComponent from './pages/feature-list';

//default root location when using ios
const iosHomeNavLink = { navLink: '/index.html', label: 'Home' };
Expand Down Expand Up @@ -117,6 +119,10 @@ const miniAppPreferenceNavLink = {
navLink: '/miniapp-preference',
label: 'MiniApp Preference',
};
const miniFeatureListNavLink = {
navLink: '/miniapp-feature-list',
label: 'Feature List',
};

const navLinks = [
iosHomeNavLink,
Expand Down Expand Up @@ -145,6 +151,7 @@ const navLinks = [
universalBridgeNavLink,
colorThemeNavLink,
cookieManagerNavLink,
miniFeatureListNavLink,
];

const homeItem = [
Expand Down Expand Up @@ -289,6 +296,12 @@ const appItems = [
navLink: cookieManagerNavLink.navLink,
element: <CookieManagerComponent />,
},
{
icon: <FormatListNumberedIcon />,
label: miniFeatureListNavLink.label,
navLink: miniFeatureListNavLink.navLink,
element: <FeatureListComponent />,
},
];

const navItems: Object[] = homeItem.concat(
Expand Down
2 changes: 2 additions & 0 deletions js-miniapp-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
### 1.20.0 (2024-xx-xx)
- **Feature:** Added new interfaces `set(key: string, value: string)`, `get(key: string)`, `remove(key: string)`, `clearMiniAppPreferences()` which uses the native storage features like Shared Preferences/User defaults to store anything from MiniApp.
- **Feature:** Updated HostEnvironmentInfo to have `hostBuildType`, `deviceToken` and `pushToken`
- **Feature:** Added new interface `miniAppFinishedLoading()` which can be used by miniapp to notify the host app that it has finished loading.
- **Fix:** Few Contacts with special characters is failed to retrieve, its fixed now
- **Feature:** Added new interface `getFeatureList()` that will return the list if features supported by the Host and MiniApp SDK.

### 1.19.0 (2023-11-02)
- **Feature:** Added new interface `getAllCookies()` to get `CookieInfo` which contains `name` and `value` of the cookie
Expand Down
51 changes: 51 additions & 0 deletions js-miniapp-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ Here is the example of manifest. You can also see [it](https://github.com/rakute
- [Send Analytics](#send-analytics)
- [Get Cookies](#get-cookies)
- [MiniApp Storage][#miniapp-storage]
- [MiniApp Finished Loading](#miniapp-finished-loading)
- [Get Feature list][#get-feature-list]
### Retrieve a unique ID
Expand Down Expand Up @@ -1186,6 +1188,32 @@ import MiniApp from 'js-miniapp-sdk';
MiniApp.miniappUtils.sendAnalytics(analyticsInfo);
```
<div id='miniapp-finished-loading'/>
## MiniApp Finished Loading <small style="color:green;font-size: 12px">Available from v1.20.0</small>
<dl>
<dd>
**API:** [Platform.miniAppFinishedLoading](api/interfaces/miniapputilsprovider.html#miniAppFinishedLoading)
Using the following interface the Miniapp can notify the host app that it has finished loading.
```javascript
import MiniApp from 'js-miniapp-sdk';

MiniApp.miniappUtils
.miniAppFinishedLoading()
.then((response) => {
console.log(response);
})
.catch((miniAppError) => {
console.log('miniAppFinishedLoading - Error: ', miniAppError);
});
```
</dd>
<div id='get-cookies'/>
## Get Cookies from host application <small style="color:green;font-size: 12px">Available from v1.19.0</small>
Expand Down Expand Up @@ -1308,6 +1336,29 @@ MiniApp.preferences

```
<div id='get-feature-list'/>
## Get feature list <small style="color:green;font-size: 12px">Available from v1.20.0</small>
This interface will help the MiniApps to get the list of features that is supported by the MiniApp native SDK also with the list of other features that is supported by the Host app
```javascript
import MiniApp from 'js-miniapp-sdk';

MiniApp.miniappUtils
.getFeatureList()
.then((response) => {
// Array of strings/features that is supported
// For eg., ["GET_USERNAME", "IS_DARK_MODE", "GET_ALL_COOKIES"]
console.log(response);
})
.catch((error) => {
console.log(error);
});

```
## Advanced Usage
<dl>
Expand Down
17 changes: 17 additions & 0 deletions js-miniapp-sdk/src/modules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export interface MiniAppUtilsProvider {
*/
closeMiniApp(withConfirmation: boolean): Promise<string>;

/**
* Miniapp can notify the host app that it has finished loading using this call.
* Host app can implement this interface to perform any other actions after the miniapp has loaded.
*/
miniAppFinishedLoading(): Promise<string>;

/**
* Interface that is used to get the Color theme used in the Host application
*/
Expand All @@ -37,13 +43,21 @@ export interface MiniAppUtilsProvider {
* @param analyticsInfo Analytics info
*/
sendAnalytics(analytics: MAAnalyticsInfo): Promise<string>;

/**
* Interface to get list of features supported by the SDK and Host
*/
getFeatureList(): Promise<string[]>;
}

/** @internal */
export class MiniAppUtils implements MiniAppUtilsProvider {
closeMiniApp(withConfirmation: boolean): Promise<string> {
return getBridge().closeMiniApp(withConfirmation);
}
miniAppFinishedLoading(): Promise<string> {
return getBridge().miniAppFinishedLoading();
}
setCloseAlert(alertInfo: CloseAlertInfo): Promise<string> {
return getBridge().setCloseAlert(alertInfo);
}
Expand All @@ -59,4 +73,7 @@ export class MiniAppUtils implements MiniAppUtilsProvider {
}
return Promise.reject('sendAnalytics Error');
}
getFeatureList(): Promise<string[]> {
return getBridge().getFeatureList();
}
}
Loading

0 comments on commit 0e14859

Please sign in to comment.