platform-sdk-chen-yu
v21.1.2
Published
Cross-runtime SDK adapters for browser, Capacitor, and Electron host capabilities.
Downloads
151
Readme
platform-sdk-chen-yu
Cross-runtime SDK adapters for browser, Capacitor, and Electron host capabilities.
This package is intentionally framework-agnostic. Angular services can wrap these SDK classes, while Electron preload scripts and standalone web apps can use them directly.
SDK modules
platform: detectsbrowser,capacitor,electron, orunsupported.notifications: sends system notifications through Electron, Capacitor LocalNotifications, or browser Notification API.splash-screen: hides or shows native splash screens.clipboard: reads and writes plain text through Electron, Capacitor Clipboard, or browser Clipboard API.file: picks files and saves files through Electron preload bridges, Capacitor Filesystem, or browser file inputs/downloads.window: controls host windows and opens external links. Browser runtimes provide safe no-op fallbacks for desktop-only actions.device: reads device info and network status through Electron, Capacitor Device/Network, or browser navigator data.update: reads the current app version, checks for updates, and delegates download/install actions to the host runtime.
Usage
import { ClipboardService, DeviceService, FileService, UpdateService, WindowService } from 'platform-sdk-chen-yu';
const clipboard = new ClipboardService();
await clipboard.writeText('合同编号 HT-2026-001');
const file = new FileService();
await file.saveFile({
filename: 'report.txt',
data: 'hello',
mimeType: 'text/plain',
});
const win = new WindowService();
await win.openExternal('https://example.com');
const device = new DeviceService();
const info = await device.getInfo();
const update = new UpdateService();
const current = await update.getCurrentVersion();
const updateResult = await update.checkForUpdate();Electron preload bridge
Electron apps can expose the following optional bridge shape:
window.electronAPI = {
clipboard: {
readText: () => ipcRenderer.invoke('clipboard:read-text'),
writeText: (text) => ipcRenderer.invoke('clipboard:write-text', text),
},
fileSystem: {
pickFiles: (options) => ipcRenderer.invoke('file:pick-files', options),
saveFile: (options) => ipcRenderer.invoke('file:save-file', options),
openExternal: (url) => ipcRenderer.invoke('shell:open-external', url),
},
windowControls: {
close: () => ipcRenderer.invoke('window:close'),
maximize: () => ipcRenderer.invoke('window:maximize'),
minimize: () => ipcRenderer.invoke('window:minimize'),
restore: () => ipcRenderer.invoke('window:restore'),
toggleFullscreen: () => ipcRenderer.invoke('window:toggle-fullscreen'),
setTitle: (title) => ipcRenderer.invoke('window:set-title', title),
openExternal: (url) => ipcRenderer.invoke('shell:open-external', url),
},
device: {
getInfo: () => ipcRenderer.invoke('device:get-info'),
getNetworkStatus: () => ipcRenderer.invoke('device:get-network-status'),
},
updater: {
getCurrentVersion: () => ipcRenderer.invoke('updater:get-current-version'),
checkForUpdate: () => ipcRenderer.invoke('updater:check-for-update'),
downloadUpdate: () => ipcRenderer.invoke('updater:download-update'),
installUpdate: () => ipcRenderer.invoke('updater:install-update'),
openReleasePage: () => ipcRenderer.invoke('updater:open-release-page'),
},
};Browser version injection
Browser builds can inject version and update metadata before the app starts:
window.__PLATFORM_VERSION__ = {
appName: 'platform-ruo-yi-ng',
version: '1.4.0',
buildNumber: '20260428.1',
commitHash: 'abc1234',
environment: 'production',
};
window.__PLATFORM_UPDATE__ = {
checkUrl: '/version.json',
releasePageUrl: 'https://example.com/releases',
};