@binblink/wasmnest-plugin-sdk-mobile 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +439 -2
- package/README_en.md +415 -0
- package/bin/build.js +271 -0
- package/bin/cli.js +96 -0
- package/bin/lib.js +349 -0
- package/bin/manifest-gen.js +327 -0
- package/bin/package.js +151 -0
- package/bin/scaffold.js +299 -0
- package/dev-shell/README.md +151 -0
- package/dev-shell/index.html +27 -0
- package/dev-shell/package.json +27 -0
- package/dev-shell/pnpm-workspace.yaml +9 -0
- package/dev-shell/postcss.config.js +6 -0
- package/dev-shell/src/App.vue +90 -0
- package/dev-shell/src/apps/mock-terminal/MockTerminalSlotCard.vue +43 -0
- package/dev-shell/src/apps/mock-terminal/MockTerminalView.vue +168 -0
- package/dev-shell/src/apps/mock-terminal/index.ts +50 -0
- package/dev-shell/src/components/DevToolbar.vue +100 -0
- package/dev-shell/src/components/DialogHost.vue +119 -0
- package/dev-shell/src/components/LogPanel.vue +80 -0
- package/dev-shell/src/i18n.ts +22 -0
- package/dev-shell/src/loader.ts +239 -0
- package/dev-shell/src/locale.ts +29 -0
- package/dev-shell/src/locales/en-shell.ts +332 -0
- package/dev-shell/src/locales/index.ts +70 -0
- package/dev-shell/src/locales/shell.ts +331 -0
- package/dev-shell/src/main.ts +58 -0
- package/dev-shell/src/mock/dialog-service.ts +58 -0
- package/dev-shell/src/mock/file-transfer.ts +390 -0
- package/dev-shell/src/mock/mobile-api.ts +369 -0
- package/dev-shell/src/mock/preset-tasks.ts +186 -0
- package/dev-shell/src/mock/session.ts +121 -0
- package/dev-shell/src/mock-context.ts +374 -0
- package/dev-shell/src/registry.ts +151 -0
- package/dev-shell/src/shared-runtime.ts +44 -0
- package/dev-shell/src/shell/ShellView.vue +52 -0
- package/dev-shell/src/shell/adapters/devAppSource.ts +144 -0
- package/dev-shell/src/shell/components/PluginContextHost.vue +40 -0
- package/dev-shell/src/shell/components/ShellAppCell.vue +75 -0
- package/dev-shell/src/shell/components/ShellAppIcon.vue +111 -0
- package/dev-shell/src/shell/components/ShellAppSurface.vue +46 -0
- package/dev-shell/src/shell/components/ShellBrandTile.vue +27 -0
- package/dev-shell/src/shell/components/ShellCapsuleMenu.vue +123 -0
- package/dev-shell/src/shell/components/ShellChip.vue +49 -0
- package/dev-shell/src/shell/components/ShellGroupCard.vue +17 -0
- package/dev-shell/src/shell/components/ShellHost.vue +75 -0
- package/dev-shell/src/shell/components/ShellNotificationShade.vue +501 -0
- package/dev-shell/src/shell/components/ShellPermissionPrompt.vue +127 -0
- package/dev-shell/src/shell/components/ShellPlaceholderSurface.vue +33 -0
- package/dev-shell/src/shell/components/ShellSection.vue +27 -0
- package/dev-shell/src/shell/components/ShellSheet.vue +74 -0
- package/dev-shell/src/shell/components/ShellStatusbar.vue +84 -0
- package/dev-shell/src/shell/components/screens/PluginRoutePage.vue +98 -0
- package/dev-shell/src/shell/components/screens/ShellAppDetailScreen.vue +359 -0
- package/dev-shell/src/shell/components/screens/ShellAppRunScreen.vue +90 -0
- package/dev-shell/src/shell/components/screens/ShellAppsScreen.vue +195 -0
- package/dev-shell/src/shell/components/screens/ShellHomeScreen.vue +357 -0
- package/dev-shell/src/shell/components/screens/ShellPermissionsScreen.vue +376 -0
- package/dev-shell/src/shell/components/screens/ShellSettingsScreen.vue +240 -0
- package/dev-shell/src/shell/components/screens/ShellSwitcherScreen.vue +559 -0
- package/dev-shell/src/shell/components/ui/ConfirmDialog.vue +137 -0
- package/dev-shell/src/shell/components/ui/Toggle.vue +53 -0
- package/dev-shell/src/shell/composables/useShellApps.ts +417 -0
- package/dev-shell/src/shell/composables/useShellNavigation.ts +197 -0
- package/dev-shell/src/shell/composables/useShellNotifications.ts +115 -0
- package/dev-shell/src/shell/composables/useShellOpen.ts +44 -0
- package/dev-shell/src/shell/composables/useShellOverlays.ts +101 -0
- package/dev-shell/src/shell/composables/useShellPreferences.ts +143 -0
- package/dev-shell/src/shell/composables/useShellRecent.ts +84 -0
- package/dev-shell/src/shell/composables/useSlotCarousel.ts +238 -0
- package/dev-shell/src/shell/composables/useToast.ts +33 -0
- package/dev-shell/src/shell/index.ts +88 -0
- package/dev-shell/src/shell/logger.ts +45 -0
- package/dev-shell/src/shell/permissions.ts +145 -0
- package/dev-shell/src/shell/registry.ts +220 -0
- package/dev-shell/src/shell/slotCards.ts +47 -0
- package/dev-shell/src/shell/styles/shell.css +1155 -0
- package/dev-shell/src/shell/surfaceIntent.ts +107 -0
- package/dev-shell/src/shell/types.ts +152 -0
- package/dev-shell/src/shell/utils.ts +54 -0
- package/dev-shell/src/styles/main.css +153 -0
- package/dev-shell/src/styles/mobile.css +981 -0
- package/dev-shell/src/styles/wallpaper.css +130 -0
- package/dev-shell/src/theme.ts +71 -0
- package/dev-shell/src/vite-env.d.ts +20 -0
- package/dev-shell/tailwind.config.js +101 -0
- package/dev-shell/tsconfig.json +16 -0
- package/dev-shell/vite.config.ts +130 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +229 -0
- package/dist/types.d.ts +738 -0
- package/dist/types.js +0 -0
- package/dist/vite-plugin.d.ts +16 -0
- package/dist/vite-plugin.js +95 -0
- package/package.json +88 -3
- package/src/constants.ts +6 -0
- package/src/global-dialog.ts +168 -0
- package/src/index.ts +96 -0
- package/src/runtime.ts +44 -0
- package/src/types.ts +822 -0
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/PluginGlobalDialog.vue +388 -0
- package/src/ui/QuickCard.d.ts +33 -0
- package/src/ui/QuickCard.vue +167 -0
- package/src/ui/Select.d.ts +37 -0
- package/src/ui/Select.vue +307 -0
- package/src/ui/plugin-global-dialog.d.ts +11 -0
- package/src/ui/useSwipeTabs.d.ts +20 -0
- package/src/ui/useSwipeTabs.ts +53 -0
- package/src/update.ts +123 -0
- package/src/vite-plugin.ts +132 -0
- package/template/.gitignore +4 -0
- package/template/README.md +46 -0
- package/template/package.json +23 -0
- package/template/plugin.json +13 -0
- package/template/rust/Cargo.toml +19 -0
- package/template/rust/src/lib.rs +33 -0
- package/template/src/env.d.ts +24 -0
- package/template/src/index.ts +37 -0
- package/template/tsconfig.json +17 -0
- package/template/vite.config.ts +21 -0
package/src/update.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 应用更新检查(SDK 默认实现;宿主统一提供 GitHub Release 判定)
|
|
3
|
+
*
|
|
4
|
+
* 数据面由宿主给出(`PluginContext.appUpdate.check`):宿主负责查 Release、校验
|
|
5
|
+
* 身份 / 完整性、做平台兼容裁决;本模块只做状态机与展示口径,供应用设置页复用。
|
|
6
|
+
*
|
|
7
|
+
* 应用可以选择:
|
|
8
|
+
* - **默认实现**:`useAppUpdate()` / `<AppUpdateSection />`(宿主能力 + 本模块状态);
|
|
9
|
+
* - **自实现**:自己查更新 / 自己画界面,不消费本模块。
|
|
10
|
+
*
|
|
11
|
+
* 失败口径:检查是被动动作,不向用户抛技术错误——状态落 `error`,技术详情由宿主
|
|
12
|
+
* 日志承载(应用可自行决定是否提示)。
|
|
13
|
+
*/
|
|
14
|
+
import { computed, getCurrentInstance, inject, ref, type ComputedRef, type Ref } from 'vue'
|
|
15
|
+
import type { AppUpdateAPI, AppUpdateCheckResult, AppUpdateReason, PluginContext } from './types'
|
|
16
|
+
|
|
17
|
+
/** 状态机的展示态(与宿主返回的 status 子集一致) */
|
|
18
|
+
export type AppUpdateStatus =
|
|
19
|
+
'idle' | 'checking' | 'up-to-date' | 'available' | 'incompatible' | 'error'
|
|
20
|
+
|
|
21
|
+
export interface UseAppUpdateOptions {
|
|
22
|
+
/**
|
|
23
|
+
* 自定义检查器(缺省 = 宿主 `PluginContext.appUpdate.check`)
|
|
24
|
+
*
|
|
25
|
+
* 应用自实现更新检查时传入;返回形状与宿主默认实现一致,SDK 默认卡片即可复用。
|
|
26
|
+
*/
|
|
27
|
+
check?: () => Promise<AppUpdateCheckResult>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface UseAppUpdate {
|
|
31
|
+
status: Ref<AppUpdateStatus>
|
|
32
|
+
latestVersion: Ref<string | undefined>
|
|
33
|
+
currentVersion: Ref<string | undefined>
|
|
34
|
+
reason: Ref<AppUpdateReason | undefined>
|
|
35
|
+
checking: ComputedRef<boolean>
|
|
36
|
+
/** 当前平台是否提供更新检查能力(旧宿主 / dev-shell 可能没有) */
|
|
37
|
+
supported: ComputedRef<boolean>
|
|
38
|
+
/** 执行一次检查;并发调用复用同一在途请求 */
|
|
39
|
+
check: () => Promise<void>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 取宿主注入的更新能力(composable 必须在 setup 期间调用;inject 只在 setup 有上下文)
|
|
44
|
+
*
|
|
45
|
+
* 不经 SDK `getPluginContext()`:桌面挂载包没有 `__WASMNEST_SHARED__`,移动端虽有
|
|
46
|
+
* 共享运行时但取 context 的路径也不同;`inject('pluginContext')` 是双端应用都已
|
|
47
|
+
* 提供的唯一入口(桌面 appContext / 移动 PluginViewHost 同键)。
|
|
48
|
+
*/
|
|
49
|
+
function resolveHostApi(): AppUpdateAPI | undefined {
|
|
50
|
+
if (!getCurrentInstance()) return undefined
|
|
51
|
+
return inject<PluginContext | undefined>('pluginContext', undefined)?.appUpdate
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 应用更新状态机(模块内无全局单例:每个设置页实例各自持状态,避免跨应用串状态)
|
|
56
|
+
*/
|
|
57
|
+
export function useAppUpdate(options: UseAppUpdateOptions = {}): UseAppUpdate {
|
|
58
|
+
const hostApi = options.check ? undefined : resolveHostApi()
|
|
59
|
+
const checker =
|
|
60
|
+
options.check ??
|
|
61
|
+
(() => {
|
|
62
|
+
if (!hostApi) {
|
|
63
|
+
return Promise.reject(
|
|
64
|
+
new Error('[PluginSDK] app update capability is not provided by this host'),
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
return hostApi.check()
|
|
68
|
+
})
|
|
69
|
+
const status = ref<AppUpdateStatus>('idle')
|
|
70
|
+
const latestVersion = ref<string | undefined>()
|
|
71
|
+
const currentVersion = ref<string | undefined>()
|
|
72
|
+
const reason = ref<AppUpdateReason | undefined>()
|
|
73
|
+
let inFlight: Promise<void> | null = null
|
|
74
|
+
|
|
75
|
+
const supported = computed(() => Boolean(options.check || hostApi))
|
|
76
|
+
|
|
77
|
+
async function run(): Promise<void> {
|
|
78
|
+
status.value = 'checking'
|
|
79
|
+
reason.value = undefined
|
|
80
|
+
try {
|
|
81
|
+
const result = await checker()
|
|
82
|
+
currentVersion.value = result.currentVersion
|
|
83
|
+
latestVersion.value = result.latestVersion
|
|
84
|
+
reason.value = result.reason
|
|
85
|
+
switch (result.status) {
|
|
86
|
+
case 'up-to-date':
|
|
87
|
+
case 'available':
|
|
88
|
+
case 'incompatible':
|
|
89
|
+
status.value = result.status
|
|
90
|
+
break
|
|
91
|
+
case 'idle':
|
|
92
|
+
case 'checking':
|
|
93
|
+
// 宿主返回中间态没有意义(调用已返回)→ 按失败处理,不把界面钉在「检查中」
|
|
94
|
+
status.value = 'error'
|
|
95
|
+
break
|
|
96
|
+
default:
|
|
97
|
+
status.value = 'error'
|
|
98
|
+
}
|
|
99
|
+
} catch {
|
|
100
|
+
status.value = 'error'
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function check(): Promise<void> {
|
|
105
|
+
if (!inFlight) {
|
|
106
|
+
const pending = run().finally(() => {
|
|
107
|
+
if (inFlight === pending) inFlight = null
|
|
108
|
+
})
|
|
109
|
+
inFlight = pending
|
|
110
|
+
}
|
|
111
|
+
return inFlight
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
status,
|
|
116
|
+
latestVersion,
|
|
117
|
+
currentVersion,
|
|
118
|
+
reason,
|
|
119
|
+
checking: computed(() => status.value === 'checking'),
|
|
120
|
+
supported,
|
|
121
|
+
check,
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @binblink/wasmnest-plugin-sdk-mobile Vite 插件
|
|
3
|
+
*
|
|
4
|
+
* 职责:
|
|
5
|
+
* 1. 共享模块(vue/vue-i18n/pinia)外置为宿主全局(window.__WASMNEST_SHARED__)
|
|
6
|
+
* 2. lib 模式下将全部 CSS(含 SFC `<style scoped>`)内联进入口 chunk ——
|
|
7
|
+
* 宿主加载插件只 import() 入口 JS,不加载 dist/style.css;不内联则
|
|
8
|
+
* 插件 scoped 样式全部丢失(真机上表现为组件样式错乱,如下拉刷新指示器
|
|
9
|
+
* 箭头失去宽高约束渲染成巨幅图形)
|
|
10
|
+
*/
|
|
11
|
+
import type { Plugin, UserConfig } from 'vite'
|
|
12
|
+
import MagicString from 'magic-string'
|
|
13
|
+
|
|
14
|
+
const SHARED_MODULES: Record<string, string> = {
|
|
15
|
+
'vue': 'window.__WASMNEST_SHARED__["vue"]',
|
|
16
|
+
'vue-i18n': 'window.__WASMNEST_SHARED__["vue-i18n"]',
|
|
17
|
+
'pinia': 'window.__WASMNEST_SHARED__["pinia"]',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function wasmnestPlugin(): Plugin[] {
|
|
21
|
+
return [sharedModulesPlugin(), inlinePluginCss()]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 共享模块外置:插件产物引用宿主全局,避免重复实例化 Vue/Pinia */
|
|
25
|
+
function sharedModulesPlugin(): Plugin {
|
|
26
|
+
const externalModules = Object.keys(SHARED_MODULES)
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
name: 'wasmnest-shared-modules',
|
|
30
|
+
enforce: 'pre',
|
|
31
|
+
|
|
32
|
+
config(config: UserConfig) {
|
|
33
|
+
const existingExternal = config.build?.rollupOptions?.external
|
|
34
|
+
const externalArray = Array.isArray(existingExternal)
|
|
35
|
+
? existingExternal
|
|
36
|
+
: typeof existingExternal === 'string'
|
|
37
|
+
? [existingExternal]
|
|
38
|
+
: []
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
build: {
|
|
42
|
+
rollupOptions: {
|
|
43
|
+
external: [...externalArray, ...externalModules],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
renderChunk(code, chunk) {
|
|
50
|
+
let modified = false
|
|
51
|
+
const s = new MagicString(code)
|
|
52
|
+
|
|
53
|
+
for (const [modName, globalExpr] of Object.entries(SHARED_MODULES)) {
|
|
54
|
+
const escapedName = modName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
55
|
+
|
|
56
|
+
const defaultRe = new RegExp(
|
|
57
|
+
`import\\s+(\\w+)\\s+from\\s+['"]${escapedName}['"]`, 'gm'
|
|
58
|
+
)
|
|
59
|
+
let match: RegExpExecArray | null
|
|
60
|
+
while ((match = defaultRe.exec(code)) !== null) {
|
|
61
|
+
const varName = match[1]
|
|
62
|
+
s.overwrite(match.index, match.index + match[0].length, `const ${varName} = ${globalExpr}`)
|
|
63
|
+
modified = true
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const namedRe = new RegExp(
|
|
67
|
+
`import\\s*\\{([^}]+)\\}\\s*from\\s+['"]${escapedName}['"]`, 'gm'
|
|
68
|
+
)
|
|
69
|
+
while ((match = namedRe.exec(code)) !== null) {
|
|
70
|
+
const imports = match[1]
|
|
71
|
+
s.overwrite(match.index, match.index + match[0].length, `const { ${imports} } = ${globalExpr}`)
|
|
72
|
+
modified = true
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const namespaceRe = new RegExp(
|
|
76
|
+
`import\\s+\\*\\s+as\\s+(\\w+)\\s+from\\s+['"]${escapedName}['"]`, 'gm'
|
|
77
|
+
)
|
|
78
|
+
while ((match = namespaceRe.exec(code)) !== null) {
|
|
79
|
+
const varName = match[1]
|
|
80
|
+
s.overwrite(match.index, match.index + match[0].length, `const ${varName} = ${globalExpr}`)
|
|
81
|
+
modified = true
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!modified) return null
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
code: s.toString(),
|
|
89
|
+
map: s.generateMap({ hires: true }),
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* CSS 内联注入(与桌面端 ai-chatbox 插件 inlinePluginCss 同模式):
|
|
97
|
+
*
|
|
98
|
+
* vite 库模式构建下提取出的 CSS asset 无人引用(宿主动态 import 的只有
|
|
99
|
+
* manifest.main 对应的 index.js),而 vite:css-post 在 generateBundle 阶段才
|
|
100
|
+
* 把 CSS 写入 bundle —— 普通(非 post)插件先于它运行拿不到 CSS 内容,
|
|
101
|
+
* 故本插件必须 enforce: 'post' 保证在 css-post 之后执行。
|
|
102
|
+
*/
|
|
103
|
+
function inlinePluginCss(): Plugin {
|
|
104
|
+
return {
|
|
105
|
+
name: 'wasmnest-inline-plugin-css',
|
|
106
|
+
apply: 'build',
|
|
107
|
+
enforce: 'post',
|
|
108
|
+
generateBundle(_options, bundle) {
|
|
109
|
+
const entry = Object.values(bundle).find((f) => f.type === 'chunk' && f.isEntry)
|
|
110
|
+
if (!entry || entry.type !== 'chunk') return
|
|
111
|
+
|
|
112
|
+
const cssParts: string[] = []
|
|
113
|
+
for (const fileName of Object.keys(bundle)) {
|
|
114
|
+
if (!fileName.endsWith('.css')) continue
|
|
115
|
+
const css = bundle[fileName]
|
|
116
|
+
if (css.type !== 'asset') continue
|
|
117
|
+
cssParts.push(
|
|
118
|
+
typeof css.source === 'string' ? css.source : new TextDecoder().decode(css.source),
|
|
119
|
+
)
|
|
120
|
+
delete bundle[fileName]
|
|
121
|
+
}
|
|
122
|
+
if (cssParts.length === 0) return
|
|
123
|
+
|
|
124
|
+
const injected =
|
|
125
|
+
`;(function(){var s=document.createElement('style');` +
|
|
126
|
+
`s.setAttribute('data-wasmnest-plugin-css','');` +
|
|
127
|
+
`s.textContent=${JSON.stringify(cssParts.join('\n'))};` +
|
|
128
|
+
`document.head.appendChild(s)})();`
|
|
129
|
+
entry.code = injected + '\n' + entry.code
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# {{NAME}}
|
|
2
|
+
|
|
3
|
+
{{NAME}} wasm 应用 — WasmNest Mobile wasm 应用工程(由 `wasmnest-plugin create` 生成)。
|
|
4
|
+
|
|
5
|
+
> 术语:本仓把「插件」称为 wasm 应用;`plugin.json` / CLI 命令 / SDK 包名仍用 `plugin` 原词。
|
|
6
|
+
|
|
7
|
+
## 快速开始
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm install # 安装依赖(含 SDK、vite、vue)
|
|
11
|
+
pnpm run dev # 浏览器开发环境(Dev Shell:空壳宿主 + 移动端骨架,HMR)
|
|
12
|
+
pnpm run build # 构建:vite(前端)+ cargo(WASM)
|
|
13
|
+
pnpm run package # 打包 dist/{{ID}}.zip 插件包
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`pnpm run dev` 首次运行自动安装 dev-shell 依赖,浏览器打开 http://localhost:5173;
|
|
17
|
+
WASM 后端命令与真机专属能力仍需真机验证(见下方指南)。
|
|
18
|
+
|
|
19
|
+
## 安装到 WasmNest Mobile
|
|
20
|
+
|
|
21
|
+
1. 将 `dist/{{ID}}.zip` 传到手机
|
|
22
|
+
2. WasmNest Mobile → 插件管理 → 从文件安装,选择 zip(支持远程下载 + SHA256 校验)
|
|
23
|
+
|
|
24
|
+
## 目录结构
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
├── plugin.json # 应用清单(id/name/权限/扩展点声明)
|
|
28
|
+
├── package.json # 工程脚本:dev / build / package
|
|
29
|
+
├── vite.config.ts # 前端构建配置(产物 dist/index.js)
|
|
30
|
+
├── tsconfig.json
|
|
31
|
+
├── src/
|
|
32
|
+
│ ├── index.ts # 前端入口:activate(context) / deactivate()
|
|
33
|
+
│ └── env.d.ts # 环境类型声明
|
|
34
|
+
├── rust/
|
|
35
|
+
│ ├── Cargo.toml # Rust 后端(wasm32-unknown-unknown;--ts-only 创建时无此目录)
|
|
36
|
+
│ └── src/lib.rs # WasmPlugin 实现(含 manifest 声明)
|
|
37
|
+
└── dist/ # 构建产物 + 应用包 zip
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 常用修改点
|
|
41
|
+
|
|
42
|
+
- **权限**:`plugin.json` 的 `permissions` 数组按需声明(**移动端 `storage` 默认授予且不可关闭**,无需声明;其余权限未声明即被拒)
|
|
43
|
+
- **扩展点**:`plugin.json` 的 `contributes`(命令、视图、navTab、终端工具栏、设置区)
|
|
44
|
+
- **前端逻辑**:`src/index.ts` 使用 `context` 提供的 API(`ui`/`events`/`storage`/`logger`/`dialogs` 等)
|
|
45
|
+
|
|
46
|
+
完整开发指南见仓库文档 `../../../docs/wasm-app-dev-mobile.md`。
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{PKG_NAME}}",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"private": true,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "wasmnest-plugin dev",
|
|
9
|
+
"build": "wasmnest-plugin build",
|
|
10
|
+
"package": "wasmnest-plugin package"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@binblink/wasmnest-plugin-sdk-mobile": "{{SDK_JS}}"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@vitejs/plugin-vue": "^6.0.0",
|
|
17
|
+
"vite": "^8.0.0",
|
|
18
|
+
"vue": "^3.4.0",
|
|
19
|
+
"vue-i18n": "^9.0.0",
|
|
20
|
+
"typescript": "^5.0.0",
|
|
21
|
+
"terser": "^5.0.0"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "{{ID}}",
|
|
3
|
+
"name": "{{NAME}}",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"platform": "mobile",
|
|
6
|
+
"description": "",
|
|
7
|
+
"author": "{{AUTHOR}}",
|
|
8
|
+
"icon": "",
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"pluginType": "{{PLUGIN_TYPE}}",
|
|
11
|
+
{{RUST_LIBRARY_LINE}} "permissions": ["storage"],
|
|
12
|
+
"contributes": {}
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "{{CRATE}}"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
license = "MIT"
|
|
5
|
+
edition = "2021"
|
|
6
|
+
|
|
7
|
+
[dependencies]
|
|
8
|
+
wasmnest-plugin-api-mobile = {{SDK_RUST}}
|
|
9
|
+
serde = { version = "1", features = ["derive"] }
|
|
10
|
+
serde_json = "1"
|
|
11
|
+
anyhow = "1"
|
|
12
|
+
|
|
13
|
+
[features]
|
|
14
|
+
default = []
|
|
15
|
+
# WASM 插件必开:启用 WasmPlugin trait / wasm_entry! 宏 / WasmHost 绑定
|
|
16
|
+
wasm = ["wasmnest-plugin-api-mobile/wasm"]
|
|
17
|
+
|
|
18
|
+
[lib]
|
|
19
|
+
crate-type = ["cdylib", "rlib"]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//! {{NAME}} Plugin (WASM — Mobile)
|
|
2
|
+
//!
|
|
3
|
+
//! 最小可编译实现:激活/停用日志,命令返回未知命令错误
|
|
4
|
+
|
|
5
|
+
use wasmnest_plugin_api_mobile::{HostLog, WasmHost, WasmPlugin};
|
|
6
|
+
use wasmnest_plugin_api_mobile::types::PluginManifest;
|
|
7
|
+
|
|
8
|
+
struct {{STRUCT}};
|
|
9
|
+
|
|
10
|
+
impl WasmPlugin for {{STRUCT}} {
|
|
11
|
+
const ID: &'static str = "{{ID}}";
|
|
12
|
+
|
|
13
|
+
fn manifest() -> PluginManifest {
|
|
14
|
+
// plugin.json 为 manifest 单一事实来源(wasmnest-plugin build/package 时自动填充)
|
|
15
|
+
serde_json::from_str(include_str!("../../plugin.json")).expect("plugin.json must be valid PluginManifest")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
fn activate() -> anyhow::Result<()> {
|
|
19
|
+
WasmHost.log_info("{{NAME}} plugin activated (mobile)");
|
|
20
|
+
Ok(())
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fn deactivate() -> anyhow::Result<()> {
|
|
24
|
+
WasmHost.log_info("{{NAME}} plugin deactivated (mobile)");
|
|
25
|
+
Ok(())
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fn invoke_command(_name: &str, _args: serde_json::Value) -> anyhow::Result<serde_json::Value> {
|
|
29
|
+
Err(anyhow::anyhow!("No commands implemented"))
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
wasmnest_plugin_api_mobile::wasm_entry!({{STRUCT}});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK 类型环境声明(模板自身用)
|
|
3
|
+
*
|
|
4
|
+
* 模板是 create 命令生成的样板工程,生成前不依赖 node_modules——本声明让
|
|
5
|
+
* tsserver 在模板目录内可解析 SDK 包名(避免 Cannot find module 假阳性)。
|
|
6
|
+
* 生成的插件工程 `pnpm install` 后以真实 SDK 类型为准(ambient 声明优先级
|
|
7
|
+
* 低于实际模块解析,自动被覆盖),此文件仅作模板开发期的类型兜底。
|
|
8
|
+
*/
|
|
9
|
+
declare module '@binblink/wasmnest-plugin-sdk-mobile' {
|
|
10
|
+
/** 插件上下文(最小可编译形状;生成工程以 SDK 真实类型为准) */
|
|
11
|
+
export interface PluginContext {
|
|
12
|
+
[key: string]: unknown
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module '@binblink/wasmnest-plugin-sdk-mobile/ui' {
|
|
17
|
+
import type { DefineComponent } from 'vue'
|
|
18
|
+
const component: DefineComponent<Record<string, unknown>, Record<string, unknown>, unknown>
|
|
19
|
+
export default component
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare module '@binblink/wasmnest-plugin-sdk-mobile/vite' {
|
|
23
|
+
export function wasmnestPlugin(options?: Record<string, unknown>): unknown
|
|
24
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* {{NAME}} 应用入口 (Mobile)
|
|
3
|
+
*
|
|
4
|
+
* 最小可编译模板:激活时注册一个宿主壳运行面(registerSurface)。
|
|
5
|
+
*
|
|
6
|
+
* 票 2026-10-10 批次 C2:模板原用 `registerTerminalToolbarItem`(终端工具栏项),
|
|
7
|
+
* 该扩展点已随宿主壳改纯 surface 形态整面退役。应用在壳内的运行面只有一种形态——
|
|
8
|
+
* `registerSurface`:应用自持整个界面(含底部导航与页签),壳不向其内加壳 chrome。
|
|
9
|
+
*/
|
|
10
|
+
import type { PluginContext } from '@binblink/wasmnest-plugin-sdk-mobile'
|
|
11
|
+
import { defineComponent, h } from 'vue'
|
|
12
|
+
|
|
13
|
+
let _ctx: PluginContext
|
|
14
|
+
|
|
15
|
+
export async function activate(context: PluginContext): Promise<void> {
|
|
16
|
+
_ctx = context
|
|
17
|
+
context.logger.info('{{NAME}} app activating...')
|
|
18
|
+
|
|
19
|
+
context.ui.registerSurface({
|
|
20
|
+
component: defineComponent({
|
|
21
|
+
name: '{{ID}}Surface',
|
|
22
|
+
setup() {
|
|
23
|
+
return () =>
|
|
24
|
+
h('div', { class: 'p-4 text-sm' }, [
|
|
25
|
+
h('p', '{{NAME}} 运行面'),
|
|
26
|
+
h('p', { class: 'opacity-70 mt-2' }, '在这里放你的应用界面(底部导航 / 页签由应用自持)'),
|
|
27
|
+
])
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
context.logger.info('{{NAME}} app activated')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function deactivate(): Promise<void> {
|
|
36
|
+
_ctx?.logger.info('{{NAME}} app deactivated')
|
|
37
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"jsx": "preserve",
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"noEmit": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*.ts", "src/**/*.vue"],
|
|
16
|
+
"exclude": ["node_modules", "rust"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import vue from '@vitejs/plugin-vue'
|
|
3
|
+
import { resolve } from 'path'
|
|
4
|
+
import { wasmnestPlugin } from '@binblink/wasmnest-plugin-sdk-mobile/vite'
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
plugins: [vue(), wasmnestPlugin()],
|
|
8
|
+
define: {
|
|
9
|
+
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
10
|
+
},
|
|
11
|
+
build: {
|
|
12
|
+
lib: {
|
|
13
|
+
entry: resolve(__dirname, 'src/index.ts'),
|
|
14
|
+
formats: ['es'],
|
|
15
|
+
fileName: () => 'index.js',
|
|
16
|
+
},
|
|
17
|
+
outDir: resolve(__dirname, 'dist'),
|
|
18
|
+
emptyOutDir: true,
|
|
19
|
+
minify: 'terser',
|
|
20
|
+
},
|
|
21
|
+
})
|