Skip to content

How to write platform specific code

lavegupta edited this page Apr 12, 2021 · 9 revisions

Writing platform-specific code

If there is a requirement to write some platform-specific logic. So that we can do with the getPlatformType function which checks for the platform on which the app is running and returns the following value:

'electron' for Desktop App

'android' for Android Mobile App

'ios' for iOS Mobile App

undefined if none of the above.

There is a constant PLATFORM_TYPES that is also available to match the returned value.

PLATFORM_TYPES = { ELECTRON: 'electron', ANDROID: 'android', IOS: 'ios' };

you can import both from @zimbra-client/platform.

Example

import { h } from 'preact';
import createApp from './components/app';
import { getPlatformType, PLATFORM_TYPES } from '@zimbra-client/platform';

export default function Zimlet(context) {
const platformType = getPlatformType();

if (platformType === PLATFORM_TYPES.ELECTRON) {
	// Write platform specific logic here...
};

// Rest of the component code...
}
Clone this wiki locally