Function constructServerAPIWithPermissions

  • This function constructs the server API that will be exposed to the client.

    If you want to expose cumtom APIs to client, copy this function and modify it.

    Parameters

    • permissions: (
          | "clipboard:read-all"
          | "clipboard:write-all"
          | "clipboard:read-text"
          | "clipboard:write-text"
          | "clipboard:read-image"
          | "clipboard:write-image"
          | "clipboard:read-files"
          | "clipboard:write-files"
          | "dialog:all"
          | "notification:all"
          | "fs:read"
          | "fs:write"
          | "fs:exists"
          | "os:all"
          | "shell:open"
          | "shell:execute"
          | "fetch:all"
          | "system-info:all"
          | "system-info:memory"
          | "system-info:cpu"
          | "system-info:os"
          | "system-info:disk"
          | "system-info:network"
          | "system-info:battery"
          | "system-info:process"
          | "system-info:components"
          | "network:interface"
          | "network:port"
          | "updownload:download"
          | "updownload:upload"
      )[]

    Returns {
        clipboard: IClipboard;
        dialog: IDialog;
        event: IEventServer;
        fetch: IFetchInternal;
        fs: IFs;
        log: ILogger;
        network: INetwork;
        notification: INotification;
        os: IOs;
        path: Omit<IPath, "BaseDirectory">;
        shell: IShellServer;
        sysInfo: ISystemInfo;
        updownload: IUpdownload;
    }

    import { IframeParentIO, RPCChannel } from 'kkrpc/browser'
    import { constructServerAPIWithPermissions } from 'tauri-api-adapter'
    const permissions = ['fetch:all']
    const io = new IframeParentIO(iframe.contentWindow)
    const rpc = new RPCChannel(io, { expose: constructServerAPIWithPermissions(permissions) })