Skip to content

Commit

Permalink
feat(console): using console service by default
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 31, 2023
1 parent 3dcebb0 commit 7708b87
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 11 deletions.
15 changes: 15 additions & 0 deletions packages/client/client/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ import { SlotOptions } from './components'
import { useColorMode, useConfig } from './config'
import { ActionContext } from '.'

export type Plugin = cordis.Plugin<Context>

export namespace Plugin {
export type Function<T = any> = cordis.Plugin.Function<T, Context>
export type Constructor<T = any> = cordis.Plugin.Constructor<T, Context>
export type Object<S = any, T = any> = cordis.Plugin.Object<S, T, Context>
}

export type EffectScope = cordis.EffectScope<Context>
export type ForkScope = cordis.ForkScope<Context>
export type MainScope = cordis.MainScope<Context>
export type Service = cordis.Service<Context>

export const Service = cordis.Service<Context>

const config = useConfig()
const mode = useColorMode()

Expand Down
3 changes: 2 additions & 1 deletion packages/client/client/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const responseHooks: Record<string, [Function, Function]> = {}
export function send<T extends keyof Events>(type: T, ...args: Parameters<Events[T]>): Promisify<ReturnType<Events[T]>>
export function send(type: string, ...args: any[]) {
if (!socket.value) return
console.debug('↑%c', 'color:brown', type, args)
const id = Math.random().toString(36).slice(2, 9)
socket.value.send(JSON.stringify({ id, type, args }))
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -84,7 +85,7 @@ export function connect(callback: () => AbstractWebSocket) {
value.addEventListener('message', (ev) => {
refresh()
const data = JSON.parse(ev.data)
console.debug('%c', 'color:purple', data.type, data.body)
console.debug('%c', 'color:purple', data.type, data.body)
if (data.type in listeners) {
listeners[data.type](data.body)
}
Expand Down
2 changes: 0 additions & 2 deletions plugins/commands/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ function findAncestors(scope: EffectScope, suffix: string[] = []): string[] {
}

export default class CommandProvider extends DataService<CommandData[]> {
static using = ['console'] as const

cached: CommandData[]
update = debounce(0, () => this.refresh())

Expand Down
2 changes: 1 addition & 1 deletion plugins/console/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ namespace NodeConsole {
timeout: Schema.number().default(Time.minute),
}),
devMode: Schema.boolean().default(process.env.NODE_ENV === 'development').hidden(),
cacheDir: Schema.string().default('.vite').hidden(),
cacheDir: Schema.string().default('cache/vite').hidden(),
}).i18n({
'zh-CN': require('./locales/zh-CN'),
})
Expand Down
2 changes: 1 addition & 1 deletion plugins/console/src/shared/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export namespace DataService {

export abstract class DataService<T = never> extends Service {
static filter = false

static keys = new Set<string>()
static using = ['console']

static define(name: keyof Console.Services) {
this.keys.add(name)
Expand Down
4 changes: 2 additions & 2 deletions plugins/locales/client/locales.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
<el-input
autosize
type="textarea"
:modelValue="store.locales['$' + locale]?.[`${active}.${path}`]"
:placeholder="store.locales[locale][`${active}.${path}`] || store.locales[''][`${active}.${path}`]"
:modelValue="(store.locales['$' + locale]?.[`${active}.${path}`] as any)"
:placeholder="store.locales[locale][`${active}.${path}`] || store.locales[''][`${active}.${path}`] as any"
@update:modelValue="handleUpdate(locale, path, $event)"
></el-input>
</div>
Expand Down
2 changes: 0 additions & 2 deletions plugins/logger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ declare module '@koishijs/plugin-console' {
}

class LogProvider extends DataService<string[]> {
static using = ['console'] as const

root: string
date: string
files: number[] = []
Expand Down
2 changes: 0 additions & 2 deletions plugins/status/src/envinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { helpers } from 'envinfo'
import which from 'which-pm-runs'

class EnvInfoProvider extends DataService<Dict<Dict<string>>> {
static using = ['console'] as const

private task: Promise<Dict<Dict<string>>>

constructor(ctx: Context, public config: EnvInfoProvider.Config) {
Expand Down

0 comments on commit 7708b87

Please sign in to comment.