diff --git a/packages/online/app/components/instance.vue b/packages/online/app/components/instance.vue
new file mode 100644
index 00000000..5b4d528d
--- /dev/null
+++ b/packages/online/app/components/instance.vue
@@ -0,0 +1,89 @@
+
+
+
+
+
+
+
+
+ 运行中
+
+
+
+
+
+ 切换
+
+
+
+ 删除
+
+
+
+
+ 分享
+
+
+
+
+
+
+
+
diff --git a/packages/online/app/components/instances.vue b/packages/online/app/components/instances.vue
index 0bbf2e9c..f43c6d8b 100644
--- a/packages/online/app/components/instances.vue
+++ b/packages/online/app/components/instances.vue
@@ -1,71 +1,85 @@
-
-
-
-
- 实例管理
- 添加
+
+
+
+
+
+
+
+
+
+
+
-
-
-
- {{ name }}
- (运行中)
- |
-
-
-
-
-
- |
-
-
-
-
+
+
diff --git a/packages/online/app/icons/plus.vue b/packages/online/app/icons/plus.vue
new file mode 100644
index 00000000..3efff18e
--- /dev/null
+++ b/packages/online/app/icons/plus.vue
@@ -0,0 +1,5 @@
+
+
+
\ No newline at end of file
diff --git a/packages/online/app/icons/share.vue b/packages/online/app/icons/share.vue
new file mode 100644
index 00000000..25bbca57
--- /dev/null
+++ b/packages/online/app/icons/share.vue
@@ -0,0 +1,5 @@
+
+
+
\ No newline at end of file
diff --git a/packages/online/app/index.ts b/packages/online/app/index.ts
index 22d36c63..aa5e4387 100644
--- a/packages/online/app/index.ts
+++ b/packages/online/app/index.ts
@@ -2,6 +2,8 @@ import { connect, global, icons, root } from '@koishijs/client'
import IconDocs from './icons/docs.vue'
import IconForum from './icons/forum.vue'
import IconInstances from './icons/instances.vue'
+import IconPlus from './icons/plus.vue'
+import IconShare from './icons/share.vue'
import Home from './components/home.vue'
import Instances from './components/instances.vue'
import ClientWebSocket from './socket'
@@ -10,6 +12,8 @@ import '@koishijs/client/app'
icons.register('activity:docs', IconDocs)
icons.register('activity:forum', IconForum)
icons.register('activity:instances', IconInstances)
+icons.register('plus', IconPlus)
+icons.register('share', IconShare)
root.page({
id: 'home',
diff --git a/packages/online/app/utils.ts b/packages/online/app/utils.ts
index bfee0885..d3a21e10 100644
--- a/packages/online/app/utils.ts
+++ b/packages/online/app/utils.ts
@@ -52,7 +52,7 @@ provideStorage((key, version, fallback) => {
return result
})
-interface Instance {
+export interface Instance {
name: string
lastVisit: number
}
@@ -60,13 +60,18 @@ interface Instance {
export const root = '/koishi/play/v1/instances'
export const instances = ref>({})
+export async function flush() {
+ await fs.writeFile(`${root}/index.json`, JSON.stringify(instances.value))
+}
+
export async function remove(key: string) {
await fs.rm(`${root}/${key}`, { recursive: true })
delete instances.value[key]
- await fs.writeFile(`${root}/index.json`, JSON.stringify(instances.value))
+ await flush()
}
-export async function activate(id?: string) {
+export async function activate(id?: string, event?: Event) {
+ (event?.target as HTMLElement)?.blur()
await loader.app?.stop()
id ||= Math.random().toString(36).slice(2, 10)
data.value.current = id
@@ -75,6 +80,8 @@ export async function activate(id?: string) {
try {
await loader.init(`${root}/${id}`)
await loader.readConfig()
+ instances.value[id].lastVisit = Date.now()
+ await flush()
} catch {
loader.config = {
plugins: {
@@ -96,7 +103,7 @@ export async function activate(id?: string) {
}
await fs.writeFile(filename, dump(loader.config))
instances.value[id] = { name: id, lastVisit: Date.now() }
- await fs.writeFile(`${root}/index.json`, JSON.stringify(instances.value))
+ await flush()
await loader.init(`${root}/${id}`)
}
const files = await fs.readdir(`${root}/${id}/data/storage`)