new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Electron · all subjects

api/main-process

142 notes in this subject, read out of this brain and free to use. This is page 2 of 3.

nativeImage.createFromNamedImage(imageName[, options]) on macOS

Creates a new NativeImage instance from the NSImage that maps to the given image name. Available on macOS. Parameters: imageName (string); options (Object or number array, optional). If options is a number array (deprecated), it is interpreted as hslShift. If it is an object, the following properties can be specified: hslShift (number[], optional), pointSize (Number, optional, defaults to 30.0), weight ('ultralight' | 'thin' | 'light' | 'regular' | 'medium' | 'semibold' | 'bold' | 'heavy' | 'black', optional, defaults to 'regular'), scale ('small' | 'medium' | 'large', optional, defaults to 'medium'). Returns NativeImage.

nativeImage HSL shift values for createFromNamedImage

The hslShift is applied to the image with the following rules: hsl_shift[0] (hue) is the absolute hue value for the image where 0 and 1 map to 0 and 360 on the hue color wheel (red). hsl_shift[1] (saturation) is a saturation shift where 0 removes all color, 0.5 leaves unchanged, and 1 fully saturates the image. hsl_shift[2] (lightness) is a lightness shift where 0 removes all lightness (black), 0.5 leaves unchanged, and 1 is full lightness (white). For example, [-1, 0, 1] makes the image completely white and [-1, 1, 0] makes the image completely black.

nativeImage.createMenuSymbol(imageName) on macOS

Creates a new NativeImage instance from an SF Symbol for use in a native Menu. Available on macOS. Parameters: imageName (string). Returns NativeImage.

NativeImage.getNativeHandle() on macOS

Returns a Buffer storing C pointer to underlying native handle of the image. On macOS, a pointer to NSImage instance is returned. The returned pointer is a weak pointer to the underlying native image instead of a copy, so you must ensure that the associated nativeImage instance is kept around. Available on macOS.

nativeImage.isMacTemplateImage property on macOS

A boolean property that determines whether the image is considered a template image on macOS. Please note that this property only has an effect on macOS.

nativeTheme.shouldUseHighContrastColors property

nativeTheme.shouldUseHighContrastColors is a readonly boolean available on macOS and Windows that indicates whether the OS or Chromium currently has high-contrast mode enabled or is being instructed to show a high-contrast UI.

nativeTheme.shouldDifferentiateWithoutColor property

nativeTheme.shouldDifferentiateWithoutColor is a readonly boolean available on macOS that indicates whether the user prefers UI that differentiates items using something other than color alone, such as shapes or labels. This maps to NSWorkspace.accessibilityDisplayShouldDifferentiateWithoutColor.

nativeTheme 'updated' event

The nativeTheme module emits an 'updated' event when something in the underlying NativeTheme has changed. This normally means that either the value of shouldUseDarkColors, shouldUseHighContrastColors, or shouldUseInvertedColorScheme has changed. The application must check these properties to determine which one has changed.

nativeTheme.shouldUseDarkColors property

nativeTheme.shouldUseDarkColors is a readonly boolean that indicates whether the OS or Chromium currently has dark mode enabled or is being instructed to show a dark-style UI. To modify this value, use the themeSource property instead.

nativeTheme.themeSource property

nativeTheme.themeSource is a string property that can be 'system', 'light', or 'dark'. It is used to override and supersede the value that Chromium has chosen internally. The default value is 'system'. Setting it to 'system' removes the override and resets everything to the OS default. Applications should use a three-state pattern: 'Follow OS' sets themeSource to 'system', 'Dark Mode' sets it to 'dark', and 'Light Mode' sets it to 'light'. The application should always use shouldUseDarkColors to determine what CSS to apply.

nativeTheme.themeSource 'light' effects

Setting nativeTheme.themeSource to 'light' has the following effects: shouldUseDarkColors becomes false when accessed; any UI Electron renders on Linux and Windows including context menus and DevTools uses the light UI; any UI the OS renders on macOS including menus and window frames uses the light UI; the CSS prefers-color-scheme query matches 'light' mode; and the 'updated' event is emitted.

nativeTheme.prefersReducedTransparency property

nativeTheme.prefersReducedTransparency is a readonly boolean that indicates whether the user has chosen via system accessibility settings to reduce transparency at the OS level.

nativeTheme.inForcedColorsMode property

nativeTheme.inForcedColorsMode is a readonly boolean available on Windows that indicates whether Chromium is in forced colors mode, controlled by system accessibility settings. Currently, Windows high contrast is the only system setting that triggers forced colors mode.

nativeTheme.shouldUseInvertedColorScheme property

nativeTheme.shouldUseInvertedColorScheme is a readonly boolean available on macOS and Windows that indicates whether the OS or Chromium currently has an inverted color scheme or is being instructed to use an inverted color scheme.

nativeTheme.shouldUseDarkColorsForSystemIntegratedUI property

nativeTheme.shouldUseDarkColorsForSystemIntegratedUI is a readonly boolean available on macOS and Windows that indicates whether the system theme has been set to dark or light. On Windows, this property distinguishes between system and app light/dark theme, returning true if the system theme is set to dark and false otherwise. On macOS, the return value is the same as shouldUseDarkColors.

Display object internal

The internal property is a boolean that is true for an internal display and false for an external display.

Display object size

The size property is a Size representing the size of the display.

Display object workArea

The workArea property is a Rectangle representing the work area of the display in DIP (Device-Independent Pixels) points.

Display object workAreaSize

The workAreaSize property is a Size representing the size of the work area.

Display object represents physical display

The Display object represents a physical display connected to the system. A fake Display may exist on a headless system, or a Display may correspond to a remote, virtual display.

Display object accelerometerSupport

The accelerometerSupport property is a string on the Display object that can be 'available', 'unavailable', or 'unknown'.

Display object bounds

The bounds property is a Rectangle representing the bounds of the display in DIP (Device-Independent Pixels) points.

Display object colorDepth

The colorDepth property is a number representing the number of bits per pixel on the display.

Display object colorSpace

The colorSpace property is a string representing a color space (three-dimensional object which contains all realizable color combinations) for the purpose of color conversions.

Display object depthPerComponent

The depthPerComponent property is a number representing the number of bits per color component.

Display object detected

The detected property is a boolean that is true if the display is detected by the system.

Display object displayFrequency

The displayFrequency property is a number representing the display refresh rate.

Display object id

The id property is a number that is a unique identifier associated with the display. A value of -1 means the display is invalid or the correct id is not yet known, and a value of -10 means the display is a virtual display assigned to a unified desktop.

Display object label

The label property is a string providing a user-friendly label for the display, determined by the platform.

Display object maximumCursorSize

The maximumCursorSize property is a Size representing the maximum cursor size in native pixels.

Display object nativeOrigin

The nativeOrigin property is a Point that returns the display's origin in pixel coordinates. It is only available on windowing systems like X11 that position displays in pixel coordinates.

Display object rotation

The rotation property is a number that can be 0, 90, 180, or 270, representing screen rotation in clock-wise degrees.

Display object scaleFactor

The scaleFactor property is a number representing the output device's pixel scale factor.

Display object touchSupport

The touchSupport property is a string that can be 'available', 'unavailable', or 'unknown'.

Display object monochrome

The monochrome property is a boolean indicating whether or not the display is a monochrome display.

ProcessMemoryInfo.private property

The private property is an Integer that represents the amount of memory not shared by other processes, such as JS heap or HTML content, measured in Kilobytes.

ProcessMemoryInfo.shared property

The shared property is an Integer that represents the amount of memory shared between processes, typically memory consumed by the Electron code itself, measured in Kilobytes.

ProcessMemoryInfo.residentSet property

The residentSet property is an Integer that represents the amount of memory currently pinned to actual physical RAM, measured in Kilobytes. It is available on Linux and Windows platforms.

process.windowsStore property

process.windowsStore is a readonly boolean that is true if the app is running as an MSIX package (including AppX for Windows Store), and undefined otherwise.

process.parentPort property

process.parentPort is an Electron.ParentPort property if this is a UtilityProcess (or null otherwise), allowing communication with the parent process.

process.defaultApp property

process.defaultApp is a readonly boolean that is true in the main process when the app is started by being passed as a parameter to the default Electron executable. For example, when running the app with 'electron .', it is true, even if isPackaged is true. It is undefined otherwise. This can be useful to determine how many arguments will need to be sliced off from process.argv.

ImageView use case: splash screens

ImageView is useful for showing splash screens that will be swapped for WebContentsViews when the content finishes loading.

ImageView splash screen example

const { BaseWindow, ImageView, nativeImage, WebContentsView } = require('electron') const path = require('node:path') const win = new BaseWindow({ width: 800, height: 600 }) const splashView = new ImageView() const splashImage = nativeImage.createFromPath(path.join(__dirname, 'loading.png')) splashView.setImage(splashImage) win.setContentView(splashView) const webContentsView = new WebContentsView() webContentsView.webContents.once('did-finish-load', () => { win.setContentView(webContentsView) }) webContentsView.webContents.loadURL('https://electronjs.org') This example shows how to create a splash screen ImageView, set an image from a file, display it in a window, then replace it with a WebContentsView once content has loaded.

ImageView class purpose and process

ImageView is a View that displays an image. It runs in the Main process only. This module cannot be used until the ready event of the app module is emitted.

ImageView experimental status

ImageView is experimental and may be changed or removed in the future.

ImageView inheritance

ImageView extends View and is an EventEmitter. Electron's built-in classes cannot be subclassed in user code.

ImageView constructor

new ImageView() creates an ImageView instance with no required parameters.

ImageView.setImage method

image.setImage(image) sets the image for the ImageView. The image parameter is of type NativeImage. Only image formats supported by NativeImage can be used with ImageView.

LanguageModelUtility.availability() static method

LanguageModelUtility.availability([options]) is an experimental static method that takes optional LanguageModelCreateCoreOptions and returns Promise<string>. It determines the availability of the language model and returns one of: 'available', 'downloadable', 'downloading', or 'unavailable'.

LanguageModelUtility class overview

LanguageModelUtility is a class for implementing local AI language models. It runs in the Utility process. Do not use the constructor directly outside of the class itself, as it will not be properly connected to the localAIHandler.

LanguageModelUtility constructor parameters

The LanguageModelUtility constructor takes an initialState object with two properties: contextUsage (number) and contextWindow (number).

LanguageModelUtility.create() static method

LanguageModelUtility.create(options) is an experimental static method that takes a LanguageModelCreateOptions parameter and returns Promise<LanguageModelUtility>. It creates a new LanguageModelUtility with the provided options.

LanguageModelUtility.contextUsage property

The experimental contextUsage property is a number representing how many tokens are currently in the context window.

LanguageModelUtility.contextWindow property

The experimental contextWindow property is a number representing the size of the context window, in tokens.

LanguageModelUtility.prompt() method

languageModelUtility.prompt(input, options) is an experimental instance method that takes LanguageModelMessage[] and LanguageModelPromptOptions parameters. It returns Promise<string> | Promise<import('stream/web').ReadableStream<string>>. This method prompts the model for a response.

LanguageModelUtility.append() method

languageModelUtility.append(input, options) is an experimental instance method that takes LanguageModelMessage[] and LanguageModelAppendOptions parameters. It returns Promise<undefined>. This method appends a message without prompting for a response.

LanguageModelUtility.measureContextUsage() method

languageModelUtility.measureContextUsage(input, options) is an experimental instance method that takes LanguageModelMessage[] and LanguageModelPromptOptions parameters. It returns Promise<number> and measures how many tokens the input would use.

LanguageModelUtility.clone() method

languageModelUtility.clone(options) is an experimental instance method that takes LanguageModelCloneOptions parameters. It returns Promise<LanguageModelUtility>. This method clones the LanguageModelUtility such that the context and initial prompt are preserved.

LanguageModelUtility.destroy() method

languageModelUtility.destroy() is an experimental instance method that destroys the model and aborts any ongoing executions.

LanguageModelAppendOptions signal parameter

LanguageModelAppendOptions object has a signal parameter of type AbortSignal, which is an external Node.js class from globals.

Give your agent this brain