Skip to content

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

JadeView IPC Types

TypeScript type definitions for JadeView v2 Frontend API, providing type safety and IntelliSense for front-end developers working with JadeView WebView.

Installation

npm install --save-dev jadeview-ipc-types

Usage

The type definitions will be automatically recognized by TypeScript when you install the package. You can then use the jade or window.jade object with full type safety and IntelliSense.

jade.invoke(command, payload?, options?)

Call backend API and get return result.

// Basic invoke
const result = await jade.invoke('message', { data: 'test' });

// With timeout
const result = await jade.invoke('slowCommand', { key: 'value' }, { timeout: 5000 });

// With generic type
const version: string = await jade.invoke<string>('get_version');

jade.invokeBatch(commands)

Batch invoke multiple commands, wait for all to complete. Results are returned in the same order as the input commands. If any command fails, the entire batch fails.

const [path, version] = await jade.invokeBatch([
  { command: 'get_init_path' },
  { command: 'get_version' },
]);

// With payload and options
const results = await jade.invokeBatch([
  { command: 'get_init_path' },
  { command: 'open_module', payload: { name: 'settings' } },
  { command: 'slow_cmd', options: { timeout: 10000 } },
]);

jade.on(eventName, callback)

Subscribe to backend events. Returns an unsubscribe function.

// Subscribe to event
const unsubscribe = jade.on('window-state-changed', (payload) => {
  console.log('Window state changed:', payload);
});

// Unsubscribe when done
unsubscribe();

jade.dialog

Dialog API for showing native dialogs.

showOpenDialog

const result = await jade.dialog.showOpenDialog({
  title: '选择文件',
  properties: ['openFile', 'multiSelections'],
  filters: [
    { name: 'Images', extensions: ['jpg', 'png'] },
    { name: 'All Files', extensions: ['*'] }
  ]
});

if (!result.canceled) {
  console.log('Selected files:', result.filePaths);
}

showSaveDialog

const result = await jade.dialog.showSaveDialog({
  title: '保存文件',
  defaultPath: 'document.txt',
  filters: [
    { name: 'Text', extensions: ['txt'] }
  ]
});

if (!result.canceled) {
  console.log('Save path:', result.filePath);
}

showMessageBox

const result = await jade.dialog.showMessageBox({
  title: '确认操作',
  message: '确定要删除吗?',
  buttons: ['确定', '取消'],
  defaultId: 1,
  cancelId: 1,
  type: 'warning'
});

if (result.response === 0) {
  console.log('User confirmed');
}

showErrorBox

await jade.dialog.showErrorBox('错误', '操作失败');

Importing Types

import type {
  JadeAPI,
  InvokeOptions,
  InvokeBatchItem,
  DialogAPI,
  OpenDialogOptions,
  SaveDialogOptions,
  MessageBoxOptions,
  OpenDialogResult,
  SaveDialogResult,
  MessageBoxResult,
  FileFilter,
  DialogProperty,
  MessageBoxType,
} from 'jadeview-ipc-types';

API Reference

InvokeOptions

Property Type Required Description
timeout number No Timeout in milliseconds

InvokeBatchItem

Property Type Required Description
command string Yes Command name
payload unknown No Data to pass to backend
options InvokeOptions No Invoke options

OpenDialogOptions

Property Type Required Description
title string No Dialog title
defaultPath string No Default path
buttonLabel string No Custom button label
filters FileFilter[] No File filters
properties DialogProperty[] No Dialog properties
blocking boolean No Block process, default true

SaveDialogOptions

Property Type Required Description
title string No Dialog title
defaultPath string No Default save path
buttonLabel string No Custom button label
filters FileFilter[] No File filters
blocking boolean No Block process, default true

MessageBoxOptions

Property Type Required Description
title string No Message box title
message string No Message content
detail string No Detail text
buttons string[] No Button labels
defaultId number No Default button index
cancelId number No Cancel button index
type MessageBoxType No Icon type
blocking boolean No Block process, default true

DialogProperty

Value Description
openFile Allow selecting files
openDirectory Allow selecting directories
multiSelections Allow multiple selections
showHiddenFiles Show hidden files
promptToCreate Prompt to create files

Also accepts custom strings for future extensions.

MessageBoxType

Value Description
none No icon
info Info icon
error Error icon
warning Warning icon
question Question icon

Notes

  • This package only provides type definitions, not the actual implementation
  • The implementation is provided by the JadeView WebView runtime
  • jade / window.jade is always available in JadeView WebView environment
  • invokeBatch internally calls invoke sequentially; if any command fails, the entire batch fails

License

MIT

About

TypeScript type definitions for JadeView IPC system, providing type safety and IntelliSense for front-end developers working with JadeView WebView.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages