Skip to content

【提案】 dweb+protocol://splashscreen.window.std.dweb/ #227

@Gaubee

Description

@Gaubee

#51 讨论中,关于 web-like 方案的提案:

interface DwebAppManifest extends CommonManifestV3 {
  dweb_window_splashscreens: Array<DwebWindowSplashscreens>;
}
interface DwebWindowSplashscreen {
  url: URL;
  baseUrl?: HttpUrl;
  match?: {
    /**如果url中有mime,那么会优先使用url中的 */
    size?: Size;
    orientation?: Orientation;
    theme?: Theme;
    platform?: Platform;
    /**
     * 不同的 platform 会有不同的规则
     * 参考 https://wicg.github.io/ua-client-hints/#sec-ch-ua-platform-version
     */
    platformVersion?: string;
    platformArchitecture?: "x86" | "arm";
    platformBitness: "32" | "64";
    /**
     * 参考 NavigatorUAData.mobile
     * https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/mobile
     */
    mobile?: boolean;
  };
  settings?: {
    /** 如果是 text/html,默认禁用js,这里可以强制启用 */
    enableJavascript?: boolean;
    /**
     * 多少毫秒后自动关闭,如果配置,那么时间到后,自动显示成标准窗口
     * 同时开发者可以在 应用内 主动通过相关协议接口关闭启动屏幕
     *
     * 如果不配置,那么只能是开发者主动关闭启动屏幕
     */
    duraction?: number;
  };
}
/**启动屏幕大小 */
type Size = `${number}x${number}` | `${number}` /* 正方形 */;
/**启动屏幕方向,会根据当前窗口所在桌面的的衡宽比来进行挑选 */
type Orientation = "portrait" | "landscape";
type Theme = "dark" | "light";
/**
 * 参考 NavigatorUAData.platform
 * https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/platform
 */
type Platform = "Windows" | "iOS" | "Linux" | "macOS" | "Android";

type URL = DataURL | FileURL | HttpUrl;
/**
 * eg: `data:text/html;utf-8,<image src='data:image/png;base64,AAA=='></image>`
 */
type DataURL = `data:${MIME};${Encoding},${string}`;
type MIME =
  | `text/html`
  | `image/png`
  | `image/webp`
  | `image/gif`
  | `image/jpeg`;
type Encoding = "utf8" | "base64";
/**虚拟文件,必须是受支持的 MIME 类型,会根据文件后缀自己配置mime */
type FileURL = `file:///${string}`;
type HttpURL = `https:///${string}`;

有几点需要注意:

  1. DwebWindowSplashscreen.mime 并不一定生效,如果 url 中有 mime,那么会优先使用 url 中的
  2. 填写 match 并不会提升优先级,优先级只会根据前后顺序来决策:
    1. 应用启动阶段会得知窗口当前的 theme、maxSize、orientation
    2. 会依次寻找符合要求的启动屏幕的配置,如果命中,那么就不会再匹配后面的配置
    3. 因此,建议将严格的配置放在列表前方,宽松的配置放在列表后方
  3. 如果 url 使用 HttpURL 格式,那么会在应用安装阶段下载它,然后将它篡改成 DataURL。

    PS:现在的 icons 也应该遵循这样的逻辑来。目前的 icons 是基于 window.std.dweb 的 blobCache,这其实并不通用,因为 blobCache 属于 window.std.dweb 自己的缓存。应该将它转化成 DataURL,这样在传递到其它应用的时候仍然可以离线地正确渲染,不造成网络影响。

  4. DataURL 中,使用 text/html,意味着将会使用 webview 来做渲染,我们将在 webview 中禁止网络访问、禁止 JavaScript 执行,然后使用 loadData 来加载:
    1. Android 上使用 webview.loadDataWithBaseURL(baseUrl,data,mimeType,encoding)
    2. IOS 上使用wkwebview.loadData(data,MIMEType,characterEncodingName,baseURL)
    3. Windows/macOS 上使用 jxbrowser.navigation.loadUrl+interceptCallback
  5. 这里的 baseUrl 默认是 https://${appId}/,必须与 appId 同域;如果 url 自身是 HttpURL 格式,那么就会默认作为 baseUrl;

    appId 通常是 xxx.com.dweb,那么这里的同域的意思是 baseUrl 着必须是 https://xxx.com/ 或者 https://xxx.com.dweb/ 开头

  6. 基于 DataURL,并不意味着它有长度限制,因为最终我们都会转成使用 loadData 来加载

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions