Docs/DivisionBox API
Universal Developer

DivisionBox API

DivisionBox API

Overview

DivisionBox is a lightweight sub-window system based on WebContentsView, used for plugin UI, tools, and debug panels.

Introduction

This document covers the currently shipped capabilities (open/close/state + lifecycle events). Advanced layouts are out of scope.

Permission note: DivisionBox is gated by the Permission Center. Plugins must request window.create.

Core Concepts

Lifecycle states

EXAMPLE.VUE
prepare → attach → active → inactive → detach → destroy
StateDescription
preparePreparing resources
attachAttached to window
activeActive interaction
inactiveInactive, can be cached
detachDetached from window
destroyDestroyed and released

DivisionBox config

EXAMPLE.TYPESCRIPT
interface DivisionBoxConfig {
  url: string
  title: string
  icon?: string
  size?: 'compact' | 'medium' | 'expanded'
  keepAlive?: boolean
  pluginId?: string
  header?: {
    show: boolean
    title?: string
    icon?: string
  }
  ui?: {
    showInput?: boolean
    inputPlaceholder?: string
    showResults?: boolean
    initialInput?: string
  }
}

Shortcuts

ShortcutAction
Command/Ctrl+DDetach current item into DivisionBox

Usage

Plugin SDK (recommended)

EXAMPLE.TYPESCRIPT
import { useDivisionBox } from '@talex-touch/utils/plugin/sdk'

const divisionBox = useDivisionBox()
const { sessionId } = await divisionBox.open({
  url: 'https://example.com/tool',
  title: 'My Tool',
  size: 'medium',
  keepAlive: true
})

const unsubscribe = divisionBox.onLifecycleChange((event) => {
  console.log(event.sessionId, event.oldState, event.newState)
})

await divisionBox.close(sessionId)
unsubscribe()

Open from renderer

EXAMPLE.TYPESCRIPT
import { useTuffTransport } from '@talex-touch/utils/transport'
import { DivisionBoxEvents } from '@talex-touch/utils/transport/events'

const transport = useTuffTransport()
const response = await transport.send(DivisionBoxEvents.open, {
  url: 'plugin://my-plugin/panel.html',
  title: 'My Panel',
  icon: 'ri:dashboard-line',
  size: 'medium',
  keepAlive: true,
  pluginId: 'my-plugin'
})

Close

EXAMPLE.TYPESCRIPT
await divisionBox.close(sessionId, {
  delay: 0,
  animation: false,
  force: false
})

Get session state

EXAMPLE.TYPESCRIPT
const response = await transport.send(DivisionBoxEvents.getState, { sessionId })

Update session state

EXAMPLE.TYPESCRIPT
await transport.send(DivisionBoxEvents.updateState, {
  sessionId,
  key: 'scrollY',
  value: 150
})

API Reference

open(config) Opens a new DivisionBox window.

close(sessionId, options?) Closes the session; force ignores keepAlive.

onStateChange(handler) Subscribes to simplified state changes.

onLifecycleChange(handler) Subscribes to full lifecycle transitions.

updateState(sessionId, key, value) Stores session state data.

getState(sessionId, key) Reads session state data.

URL Protocols

ProtocolDescriptionExample
plugin://Plugin assetsplugin://my-plugin/index.html
file://Local filesfile:///path/to/file.html
http(s)://Web resourceshttps://example.com
tuff://Built-in pagestuff://detached?itemId=xxx

Flow Transfer Integration

EXAMPLE.JSON
{
  "flowTargets": [
    {
      "id": "open-in-panel",
      "name": "Open in panel",
      "supportedTypes": ["json", "text"],
      "featureId": "open-panel"
    }
  ]
}
EXAMPLE.TYPESCRIPT
function onFeatureTriggered(featureId: string, query: TuffQuery) {
  if (isFlowTriggered(query)) {
    const flowData = extractFlowData(query)
    divisionBox.open({
      url: `/viewer.html?sessionId=${flowData.sessionId}`,
      title: 'View Data'
    })
  }
}

IPC Channels

ChannelDirectionDescription
division-box:openRenderer → MainOpen session
division-box:closeRenderer → MainClose session
division-box:get-stateRenderer → MainGet state
division-box:update-stateRenderer → MainUpdate state
division-box:get-active-sessionsRenderer → MainList active sessions
division-box:state-changedMain → RendererState change notice
division-box:session-destroyedMain → RendererSession destroyed

Best Practices

  • Enable keepAlive for frequently used panels.
  • Choose size based on content density.
  • Persist user state via updateState/getState.
  • Release resources on inactive and destroy states.

Technical Notes

  • DivisionBox is managed by the main process using WebContentsView.
  • The SDK wraps IPC events and normalizes lifecycle updates.
Was this helpful?