# Mini-Program Management

Mini-Program Management primarily introduces APIs for operating Mini-Programs, including: opening Mini-Programs, closing Mini-Programs, deleting Mini-Programs, etc.

# 1. Opening a Mini-Program

Different scenarios require different APIs for opening Mini-Programs. Therefore, we provide multiple APIs for opening Mini-Programs.

  1. Open an online Mini-Program: Generally, only the Mini-Program ID and server address are required. This API can only open officially released and reviewed versions of Mini-Programs.
  2. Open a Mini-Program via QR code: This scenario involves scanning a QR code from the Mini-Program platform, obtaining the content within the QR code, and then using that content to open the Mini-Program. QR codes for officially released, trial, reviewed, development, and preview versions of Mini-Programs can all be opened using this API.

# 1.1 Opening a Mini-Program Normally

When opening a Mini-Program, the system first checks if there is a cached Mini-Program locally. If not, it automatically downloads the Mini-Program from the remote server and then opens it. If a cached Mini-Program exists, it opens the local Mini-Program first and then checks if a new version is available on the server.

If a new version exists, it downloads the new version. The next time the Mini-Program is opened, the new version will be used. If no new version is available, no action is taken.

/// Launch Mini-Program
/// [request] The request object for launching the Mini-Program
Future<Map> startApplet(RemoteAppletRequest request)

RemoteAppletRequest

Property Name Type Description
appletId String Mini-Program ID, required
apiServer String Server address to which the Mini-Program belongs, required
startParams Map<String, String>? Mini-Program startup parameters, only supports path and query
sequence int? Mini-Program index, optional
offlineMiniprogramZipPath String? Offline Mini-Program package zip path. A local Mini-Program package path can be passed to speed up the first launch, optional
offlineFrameworkZipPath String? Offline Base Library zip path. A Base Library path can be passed to speed up the first launch, optional
animated bool Whether to use animation, optional, default is true. Only supported on iOS
isSingleProcess bool Whether to run in single-process mode, default is false. Only supported on Android
isSingTask bool Whether to run in single-task stack mode, default is false. Only supported on Android
reLaunchMode FCRelaunchMode Mode for executing reLaunch. PARAMS_EXIST, ONLY_PARAMS_DIFF, ALWAYS, NEVER

Note: For the first offline launch, both offlineMiniprogramZipPath and offlineFrameworkZipPath must be provided.

Example code:

RemoteAppletRequest request = new RemoteAppletRequest(apiServer: 'https://api.finclip.com', appletId: appId);
request.startParams = {
  'path':'/pages/index/index',
  'query':'key1=value2&key2=value2'
};
Mop.instance.startApplet(request);

# 1.2 Opening a Mini-Program via QR Code

This process is generally more complex. It requires first scanning the QR code from the FinClip Mini-Program Open Platform, obtaining the content within the QR code, and then using that content to call this interface to open the Mini-Program.

/// Launch Mini-Program using QR code information
/// [qrcode] The string content within the QR code
/// [isSingleProcess] Whether to run in single-process mode, only supported on Android, default is `false`
/// [isSingTask] Whether to run in single-task stack mode, only supported on Android, default is `false`
Future qrcodeOpenApplet(String qrcode, {bool isSingleProcess = false, bool isSingTask = false})

Note: When opening a trial version QR code, the corresponding trial member userId must be added during SDK initialization.

Example code:

String qrCode = 'QR code content';
Mop.instance.qrcodeOpenApplet(qrCode);

# 2. Closing a Mini-Program

Closing a Mini-Program is equivalent to clicking the close button in the capsule control in the upper right corner. At this point, the Mini-Program is moved to the background; it is not destroyed.

# 2.1 Closing a Specified Mini-Program

/**
Close the specified Mini-Program
@param appletId Mini-Program ID
@param animated Whether to show animation, only effective on iOS
*/
Future<void> closeApplet(String appletId, bool animated)

# 2.2 Closing All Mini-Programs

In some scenarios, Mini-Program A might open Mini-Program B, and Mini-Program B might open Mini-Program C. To close all opened Mini-Programs in such cases, you can use this method.


/// Close all opened Mini-Programs
Future closeAllApplets()

# 3. Finishing a Mini-Program

After a Mini-Program is closed, it is not truly finished but suspended in the background. The next time it is opened, it will be immediately brought to the foreground. Therefore, if you want the Mini-Program to be truly finished after closing, you can use the following APIs to finish a specified Mini-Program or all Mini-Programs based on the actual situation.

# 3.1 Finishing a Specified Mini-Program

After closing the Mini-Program, calling this API can delete the cache, thereby destroying the Mini-Program.

/// Finish Mini-Program. The Mini-Program will be cleared from memory.
Future<void> finishRunningApplet(String appletId, bool animated)

# 3.2 Finishing All Mini-Programs

/// clear mini programs cache
/// Finish all Mini-Programs
Future clearApplets()

Example code:

Mop.instance.clearApplets();

# 4. Deleting a Mini-Program

Since running a Mini-Program caches the Mini-Program package and its information locally, subsequent openings will prioritize using the cache, resulting in faster launch times. Therefore, if you want to delete all information related to a Mini-Program, you can use the following APIs to delete a specific Mini-Program or delete all Mini-Programs.

# 4.1 Deleting a Specified Mini-Program

/// Clear the cache of the specified Mini-Program package
Future removeUsedApplet(String appId)

# 4.2 Deleting All Mini-Programs

/// Clear cache for all Mini-Programs
Future removeAllUsedApplets()

# 3. Batch Downloading Mini-Programs

The App can perform batch pre-downloading of Mini-Programs during idle time to reduce Mini-Program startup time.

  /// Batch download/preload Mini-Programs
  /// [appIds] List of Mini-Program IDs
  /// [apiServer] Server address
  /// [isBatchDownload] Whether to download Mini-Programs in batch (default `true`)
  ///
  /// Return value format:
  /// ```
  /// {
  ///   "retMsg": "ok",
  ///   "success": true,
  ///   "data": {
  ///     "list": [
  ///       {
  ///         "appId": "5f72e3559a6a7900019b5baa",
  ///         "success": true,  // Whether the download was successful
  ///         "needUpdate": false,  // Whether an update is needed
  ///         "errMsg": ""  // Error message, empty if successful
  ///       }
  ///     ]
  ///   }
  /// }
  /// ```
  Future<Map<String, dynamic>> downloadApplets(
    List<String> appIds,
    String apiServer,
    {bool isBatchDownload = true}
  )

# 4. Searching for Mini-Programs

The App can actively search for published Mini-Programs.

/// Search for Mini-Programs
  /// [text] Search content
  /// [apiServer] Server address
  ///
  /// Return value format:
  /// ```
  /// {
  ///   "retMsg": "ok",
  ///   "success": true,
  ///   "data": {
  ///     "total": 10,          // Number of Mini-Programs found
  ///     "list": [            // Collection of found Mini-Programs
  ///       {
  ///       }
  ///     ],
  ///     "pageNo": 0,  // Current page number
  ///     "pageSize": 10  // Number of items per page
  ///   }
  /// }
  /// ```
  Future<Map<String, dynamic>> searchApplets(
    String text,
    String apiServer
  )

# 5. Getting the List of Recently Used Mini-Programs

  /// Get the list of recently used Mini-Programs
  ///
  /// Return value format:
  /// ```
  /// {
  ///   "retMsg": "ok",
  ///   "success": true,
  ///   "data": {
  ///     "list": [            // Array of Mini-Programs
  ///       {
  ///       }
  ///     ]
  ///   }
  /// }
  /// ```
  Future<Map<String, dynamic>> getUsedApplets()

# 6. Getting the List of Favorited Mini-Programs

  /// Get the list of favorited Mini-Programs
  /// [apiServer] Server address
  /// [pageNo] Page number (pass 0 to get all)
  /// [pageSize] Page size (pass 0 to get all)
  ///
  /// Return value format:
  /// ```
  /// {
  ///   "retMsg": "ok",
  ///   "success": true,
  ///   "data": {
  ///     "data": {
  ///       "total": 3,              // Total number of favorited Mini-Programs
  ///       "list": [                // List of favorited Mini-Programs
  ///         {
  ///           "appId": "5f72e3559a6a7900019b5baa",
  ///           "name": "Mini-Program Name",
  ///           "logo": "/api/v1/mop/runtime/download/xxx",  // Icon path, baseUrl needs to be appended
  ///           "createTime": 1758178260152,  // Favoriting timestamp
  ///           "currentUserId": "18607180143",
  ///           "encryptedUserId": ""
  ///         }
  ///       ],
  ///       "apiServer": "https://super-apps.ai"
  ///     },
  ///     "errcode": "OK",
  ///     "error": "",
  ///     "traceid": "4aaf26a68c484a31aa9c37859f75d2cd"
  ///   }
  /// }
  /// ```
  Future<Map<String, dynamic>> getFavoriteApplets(
    String apiServer,
    {int pageNo = 0, int pageSize = 0}
  )
© FinClip with ❤ , Since 2017