Twinkle Tray

repository·master·Indexed 27 days ago

https://github.com/xanderfrangos/twinkle-tray

A Windows utility for managing the brightness of external monitors via the system tray, bypassing native Windows limitations. Version 1.18.0-beta2 supports DDC/CI and WMI, providing a command-line interface (v1.13.0+) for brightness changes, monitor selection, and VCP code transmission. The repository also includes modules such as @paymoapp/active-window for retrieving active window metadata across Windows, MacOS, and Linux, and @hensm/ddcci for Windows-based DDC/CI support.

Tokens
17.6K
Snippets
20
Records
101
Agent score
93%

What's inside twinkle-tray

  1. Install @paymoapp/active-window

    master

    Install the library via npm to use native modules for retrieving active window metadata (title, application name, icon, etc.) on Windows, MacOS, and Linux (X11 only).

    Note: The project uses Node-API version 6 and provides prebuilt binaries via prebuild. If a prebuilt binary is unavailable, it will be built during installation. You can manually trigger a rebuild using npm run build:gyp.

    npm install --save @paymoapp/active-window
  2. Install win32-displayconfig

    master

    The win32-displayconfig module provides simplified Node.js bindings to the Win32 Display Device Reference API.

    Compatibility Requirements:

    • Windows: Tested on Windows 10 (version 2004). Not supported on Windows 7 or 8.
    • Node.js: Requires N-API Version 4. Minimum supported versions are 8.16.0 (no Node 9 support), 10.16.0, and 11.8.0. Actively tested on Node 10.21 and above.
  3. Build and run the Node Active Window demo

    master

    The platform-dependent C++ / Objective-C++ libraries can be tested using the provided demo programs. Navigate to the specific platform's demo directory (e.g., module/linux/demo) and use make to build.

    Available running modes:

    • default: make run - Fetches current window details, waits 3 seconds, then fetches again.
    • loop: make run MODE=loop - Polls the current window every 3 seconds until SIGINT (Ctrl+C).
    • watch: make run MODE=watch - Watches for changes to the active window or its title without polling.
    • benchmark: make run MODE=benchmark - Fetches window details 100,000 times (Linux) or 10,000 times (Windows) and prints total CPU seconds consumed.
  4. Initialize and use @paymoapp/active-window

    master

    To use the library, you must first call ActiveWindow.initialize(). On MacOS, if you are not running a GUI application, you should pass { osxRunLoop: true } to initialize() to enable subscriptions.

    On MacOS, you must also check requestPermissions() to ensure the application has screen recording permissions; otherwise, the window title will return as an empty string.

    import ActiveWindow from '@paymoapp/active-window';
    
    // Must be called before any other method
    ActiveWindow.initialize();
    
    // Required for MacOS to fetch window titles
    if (!ActiveWindow.requestPermissions()) {
    	console.log('Error: You need to grant screen recording permission in System Preferences > Security & Privacy > Privacy > Screen Recording');
    	process.exit(0);
    }
    
    const activeWin = ActiveWindow.getActiveWindow();
    
    console.log('Window title:', activeWin.title);
    console.log('Application:', activeWin.application);
    console.log('Application path:', activeWin.path);
    console.log('Application PID:', activeWin.pid);
    console.log('Application icon:', activeWin.icon);
    import ActiveWindow from '@paymoapp/active-window';
    
    ActiveWindow.initialize();
    
    if (!ActiveWindow.requestPermissions()) {
    	console.log('Error: You need to grant screen recording permission in System Preferences > Security & Privacy > Privacy > Screen Recording');
    	process.exit(0);
    }
    
    const activeWin = ActiveWindow.getActiveWindow();
    
    console.log('Window title:', activeWin.title);
    console.log('Application:', activeWin.application);
    console.log('Application path:', activeWin.path);
    console.log('Application PID:', activeWin.pid);
    console.log('Application icon:', activeWin.icon);
  5. Build Twinkle Tray from Source

    master

    To run a development build, you must build on Windows.

    1. Clone or download the repository.
    2. Install node-gyp build tools (often included with NodeJS).
    3. Install dependencies: npm install.
    4. Build the executable: npm run build.
    5. Run the development build: npm start.
    npm install
    npm run build
  6. Install Twinkle Tray via Package Manager

    master

    You can install Twinkle Tray using several Windows package managers:

    Windows Package Manager (winget)

    winget install xanderfrangos.twinkletray

    Chocolatey (unofficial)

    To install:

    choco install twinkle-tray

    To upgrade:

    choco upgrade twinkle-tray

    Note: Chocolatey packages are not maintained by this repository.

    Scoop (unofficial)

    To install:

    scoop bucket add extras
    scoop install extras/twinkle-tray

    To upgrade:

    scoop update twinkle-tray

    Note: Scoop packages are not maintained by this repository.

    winget install xanderfrangos.twinkletray
  7. Manage Startup Behavior

    master

    Twinkle Tray can be configured to launch automatically when you log in to Windows. This is managed via the Windows Registry (Software\Microsoft\Windows\CurrentVersion\Run).

    • Enable Startup: Adds the application path to the Windows Run registry key.
    • Disable Startup: Removes the application from the Windows Run registry key and the StartupApproved registry key.
  8. Manage Localization and Languages

    master

    Twinkle Tray supports multiple languages via JSON localization files.

    • Detection: The app attempts to detect the system locale (e.g., en, zh-CN, pt).
    • Customization: Users can manually select a language in settings. If a specific language file (e.g., localization/fr.json) exists, it is loaded; otherwise, it falls back to the default English (en.json) file.
    • API/Internal: The getLocalization function handles the mapping of system locales to supported language codes.
  9. Configure Hotkeys for Monitor Control

    master

    Twinkle Tray supports custom hotkeys to control monitor settings like brightness, SDR level, contrast, volume, and power state.

    Supported Action Types:

    • set: Sets a specific value.
    • offset: Adjusts the current value by a given amount.
    • cycle: Cycles through a predefined list of values.
    • refresh: Triggers a monitor refresh.
    • off: Triggers the sleep action defined in settings.

    Targetable Properties:

    • brightness: Controls standard brightness.
    • sdr: Controls the SDR level (for HDR monitors).
    • contrast: Controls contrast (uses VCP 0x12).
    • volume: Controls volume (uses VCP 0x62).
    • powerState: Controls power state (uses VCP 0xD2).
    • Custom VCP: Any valid VCP hex code can be targeted.

    Note: If settings.hotkeysBreakLinkedLevels is true, using a hotkey will automatically disable linked brightness levels.

  10. Use Monitor Profiles and Brightness Persistence

    master

    Twinkle Tray can save and re-apply brightness settings for known displays.

    • Known Displays: The application maintains a database of known displays and their last brightness levels on disk.
    • Applying Profiles: The applyProfile function can be used to apply a set of brightness/contrast settings to a list of monitors. It supports:
      • Smooth Transitions: If useTransition is enabled, brightness changes are smoothed over time using transitionBrightness.
      • Direct Application: Immediate application of values to WMI, Studio Display, or DDC/CI monitors.
    • Skipping Displays: Monitors matching rules in settings.userSkipReapply can be excluded from profile application.
  11. Troubleshoot Twinkle Tray Compatibility

    master

    Twinkle Tray relies on DDC/CI and WMI. Ensure DDC/CI is enabled in your monitor's physical settings/OSD menu.

    Common Issues:

    • AMD Radeon Control Panel: May interfere if "Custom Colors" is enabled. Disable it to resolve conflicts.
    • Connection Types: VGA/DVI and certain USB/Thunderbolt/Surface docks with HDMI or DisplayPort may not be compatible.
    • Monitor Behavior: Some monitors may behave poorly with DDC/CI brightness or power state commands; this is a known limitation of certain hardware models.