widget-js/widgets

repository·master·Indexed 20 days ago

https://github.com/widget-js/widgets

A collection of ergonomic desktop widgets for Windows 10/11, featuring specialized UI components for AI assistants, system monitoring, productivity tools, and weather displays. The ecosystem includes various packages such as AI components (DeepSeek, ChatGPT, Gemini), monitoring dashboards, and utility tools like Pomodoro timers and calendars.

Tokens
6.5K
Snippets
23
Records
26
Agent score
72%

What's inside widget-js/widgets

  1. Explore available widget packages

    master

    The widget-js/widgets ecosystem consists of several specialized component packages. You can find individual repositories for each category:

    • AI Components: DeepSeek, ChatGPT, and Gemini integration (rtugeek/ai).
    • Monitoring Components: Dashboard, energy labels, and server monitoring (rtugeek/monitor).
    • Default Components: Countdown, Dynamic Island, Labor Progress, and Time Progress (widget-js/widgets).
    • Grid/Folder Components: Layout management (rtugeek/grid).
    • iTime Components: Todo lists, Deadlines, Pomodoro, and Calendars (rtugeek/itime-web).
    • Clipboard Components: Clipboard management (rtugeek/clipboard).
    • Weather Components: Various sizes (2x2, 4x2, 4x4) (rtugeek/weather).
    • Hotspot Components: Trending searches for Bilibili, Weibo, Douyin, Zhihu, and Bangumi (widget-js/hotspot).
    • Clock Components: Flip clock, standard clock, Glitch clock, and Micky clock (rtugeek/clock).
    • Photo Components: Stickers and slideshow albums (rtugeek/photo).
    • Fun Components: Electronic Wooden Fish and Dashboards (rtugeek/fun).
  2. Run the widget project locally

    master

    To run the widget project in a development environment, follow these steps:

    1. Install the Desktop Client: Download and run the desktop component client from the Microsoft Store or the official website.
    2. Clone the Repository:
      git clone https://github.com/widget-js/widget.git
    3. Install Dependencies: Navigate to the project directory and run:
      pnpm run install
    4. Start Development Server:
      pnpm run dev
    git clone https://github.com/widget-js/widget.git
    pnpm run install
    pnpm run dev
  3. Understand the AppRuntimeInfo and SimpleAppRuntimeInfo types

    master

    When working with runtime information, you can choose between two type shapes:

    • AppRuntimeInfo: The complete data structure provided by the core API.
    • SimpleAppRuntimeInfo: A sanitized version of AppRuntimeInfo created by omitting the following keys:
      • chrome
      • node
      • appPath
      • platform
      • v8

    Use SimpleAppRuntimeInfo when you want to write code that is agnostic of whether it is running in a browser, Node.js, or a specific desktop application wrapper.

  4. Configure ESLint with @antfu/eslint-config

    master

    This project uses @antfu/eslint-config for linting and code style enforcement. The configuration is set up for a library (type: 'lib') with support for TypeScript, React, and JSX.

    Key configuration areas include:

    • Stylistic settings: Controls indentation (2 spaces) and quote type ('single').
    • Language support: Enables typescript, react, and jsx; disables vue, jsonc, yaml, and markdown.
    • Ignores: The following paths are excluded from linting:
      • **/fixtures
      • src/components/ui/**
    • Custom Rules: Specific overrides are applied for code style (e.g., curly, style/max-statements-per-line) and TypeScript usage (e.g., disabling ts/explicit-function-return-type).
    import antfu from '@antfu/eslint-config'
    
    export default antfu({
      type: 'lib',
      stylistic: {
        indent: 2,
        quotes: 'single',
      },
      typescript: true,
      react: true,
      jsx: true,
      vue: false,
      jsonc: false,
      yaml: false,
      markdown: false,
      ignores: [
        '**/fixtures',
        'src/components/ui/**',
      ],
      rules: {
        'curly': ['error', 'multi-line'],
        'no-use-before-define': 'off',
        'eqeqeq': 'off',
        'ts/ban-ts-comment': 'off',
        'unused-imports/no-unused-vars': ['error', {
          caughtErrors: 'none',
          argsIgnorePattern: '^_',
          varsIgnorePattern: '^_',
        }],
        'ts/explicit-function-return-type': 'off',
        'style/max-statements-per-line': ['error', {
          max: 2,
        }],
      },
    })
  5. Use PayApi to manage virtual product purchases

    master

    The PayApi object provides methods to fetch virtual products and initiate payment orders for WeChat Pay (Wx) or Alipay. It is designed for handling virtual goods like AI service subscriptions or digital assets.

    import { PayApi } from '@/api/pay';
    
    // 1. Fetch products by category
    const products = await PayApi.getProducts('ai');
    
    // 2. Create a WeChat Pay order
    const wxOrder = await PayApi.createWxOrder(products[0].id);
    console.log(wxOrder.codeUrl); // Use this URL to show the QR code
    
    // 3. Create an Alipay order
    const alipayOrder = await PayApi.createAlipayOrder(products[0].id, 'https://your-site.com/callback');
    console.log(alipayOrder.form); // Use this form to redirect the user
    
    // 4. Get an Alipay URL directly if you have an orderId
    const url = await PayApi.getAlipayUrl(alipayOrder.orderId);
    window.location.href = url;
  6. Use the WidgetTags component

    master

    The WidgetTags component is a UI element used for selecting or filtering widget categories via a horizontal list of pill-shaped buttons. It manages a single string value representing the selected tag and provides an onChange callback when a user selects a different category.

    Available Tags

    The component uses the following internal values for its tags:

    • '' (All)
    • 'ai' (AI)
    • 'utilities' (Utilities)
    • 'productivity' (Productivity)
    • 'news' (News)
    • 'weather' (Weather)
    • 'fun' (Fun)
    • 'calendar' (Calendar)
    • 'time' (Time)
    • 'finance' (Finance)
    • 'installed' (Installed)
    import { WidgetTags } from '@/pages/add/components/widget-tags'
    
    // Example usage in a parent component
    export function MyWidgetManager() {
      const [selectedTag, setSelectedTag] = useState<string>('')
    
      return (
        <WidgetTags 
          value={selectedTag} 
          onChange={(newValue) => setSelectedTag(newValue)} 
        />
      )
    }
  7. Check and get application version with AppApi

    master

    Use AppApi.getVersion(componentName) to retrieve the current version of a specific application component (e.g., 'app'). This is useful for verifying if the host application meets the requiredAppVersion of a widget before deployment.

    import { AppApi } from '@widget-js/core';
    
    const appVersion = await AppApi.getVersion('app');
    console.log(appVersion); // e.g., '1.2.3'
  8. Deploy a widget using DeployedWidgetApi

    master

    To add or remove widgets from the application, use the DeployedWidgetApi.

    Adding a Widget

    Use DeployedWidgetApi.addWidget to deploy a widget. You can specify the deployment mode (e.g., BACKGROUND, NORMAL, OVERLAP, or TRAY) and provide a packageJsonUrl if the widget is hosted remotely.

    Removing a Widget

    Use DeployedWidgetApi.removeDeployedWidgetByName to uninstall a widget by its name.

    Other Actions

    • Create Desktop Shortcut: Use DeployedWidgetApi.createDesktopShortcut(widgetName) to create a shortcut for a specific widget.
    • Open DevTools: Use DeployedWidgetApi.openDevTools(widgetName) to open developer tools for a deployed widget (typically used in development modes).
    // Adding a widget
    await DeployedWidgetApi.addWidget({
      widgetName: 'my-widget-name',
      deployMode: DeployMode.BACKGROUND,
      packageJsonUrl: 'https://example.com/package.json',
    });
    
    // Removing a widget
    await DeployedWidgetApi.removeDeployedWidgetByName('my-widget-name');
    
    // Creating a desktop shortcut
    await DeployedWidgetApi.createDesktopShortcut('my-widget-name');
    
    // Opening DevTools
    await DeployedWidgetApi.openDevTools('my-widget-name');
  9. Retrieve AI token usage history with AiApi.getUsage

    master

    Use AiApi.getUsage to fetch the history of AI token consumption. This method supports pagination via page and limit parameters. It returns an object containing an array of AiTokenHistory items and the total count.

    const { items, total } = await AiApi.getUsage({ page: 1, limit: 20 });
    // items is AiTokenHistory[], total is number
  10. Manage widget configuration with WidgetApi

    master

    If a widget is configurable, you can open its specific configuration page using WidgetApi.openConfigPageByName(widgetName). This is typically used for background widgets that require user settings.

    import { WidgetApi } from '@widget-js/core';
    
    // Open the settings page for a specific widget
    await WidgetApi.openConfigPageByName('widget-name');
  11. Retrieve AI token packages with AiApi.getPackages

    master

    Use AiApi.getPackages to fetch a list of available AI token packages. This method supports pagination via page and limit parameters. It returns an object containing an array of AiTokenPackage items and the total count.

    const { items, total } = await AiApi.getPackages({ page: 1, limit: 10 });
    // items is AiTokenPackage[], total is number