@tauri-apps/api
Advanced tools
Comparing version 2.1.1 to 2.2.0
43
core.js
@@ -79,35 +79,26 @@ import { __classPrivateFieldGet, __classPrivateFieldSet } from './external/tslib/tslib.es6.js'; | ||
// no-op | ||
}); | ||
} | ||
// the id is used as a mechanism to preserve message order | ||
); | ||
// the id is used as a mechanism to preserve message order | ||
_Channel_nextMessageId.set(this, 0); | ||
_Channel_pendingMessages.set(this, {}); | ||
_Channel_pendingMessages.set(this, []); | ||
this.id = transformCallback(({ message, id }) => { | ||
// the id is used as a mechanism to preserve message order | ||
if (id === __classPrivateFieldGet(this, _Channel_nextMessageId, "f")) { | ||
__classPrivateFieldSet(this, _Channel_nextMessageId, id + 1, "f"); | ||
// Process the message if we're at the right order | ||
if (id == __classPrivateFieldGet(this, _Channel_nextMessageId, "f")) { | ||
__classPrivateFieldGet(this, _Channel_onmessage, "f").call(this, message); | ||
__classPrivateFieldSet(this, _Channel_nextMessageId, __classPrivateFieldGet(this, _Channel_nextMessageId, "f") + 1, "f"); | ||
// process pending messages | ||
const pendingMessageIds = Object.keys(__classPrivateFieldGet(this, _Channel_pendingMessages, "f")); | ||
if (pendingMessageIds.length > 0) { | ||
let nextId = id + 1; | ||
for (const pendingId of pendingMessageIds.sort()) { | ||
// if we have the next message, process it | ||
if (parseInt(pendingId) === nextId) { | ||
// eslint-disable-next-line security/detect-object-injection | ||
const message = __classPrivateFieldGet(this, _Channel_pendingMessages, "f")[pendingId]; | ||
// eslint-disable-next-line security/detect-object-injection | ||
delete __classPrivateFieldGet(this, _Channel_pendingMessages, "f")[pendingId]; | ||
__classPrivateFieldGet(this, _Channel_onmessage, "f").call(this, message); | ||
// move the id counter to the next message to check | ||
nextId += 1; | ||
} | ||
else { | ||
// we do not have the next message, let's wait | ||
break; | ||
} | ||
} | ||
__classPrivateFieldSet(this, _Channel_nextMessageId, nextId, "f"); | ||
while (__classPrivateFieldGet(this, _Channel_nextMessageId, "f") in __classPrivateFieldGet(this, _Channel_pendingMessages, "f")) { | ||
const message = __classPrivateFieldGet(this, _Channel_pendingMessages, "f")[__classPrivateFieldGet(this, _Channel_nextMessageId, "f")]; | ||
__classPrivateFieldGet(this, _Channel_onmessage, "f").call(this, message); | ||
// eslint-disable-next-line @typescript-eslint/no-array-delete | ||
delete __classPrivateFieldGet(this, _Channel_pendingMessages, "f")[__classPrivateFieldGet(this, _Channel_nextMessageId, "f")]; | ||
__classPrivateFieldSet(this, _Channel_nextMessageId, __classPrivateFieldGet(this, _Channel_nextMessageId, "f") + 1, "f"); | ||
} | ||
} | ||
// Queue the message if we're not | ||
else { | ||
__classPrivateFieldGet(this, _Channel_pendingMessages, "f")[id.toString()] = message; | ||
// eslint-disable-next-line security/detect-object-injection | ||
__classPrivateFieldGet(this, _Channel_pendingMessages, "f")[id] = message; | ||
} | ||
@@ -114,0 +105,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
export { Submenu } from './menu/submenu.js'; | ||
export { Submenu, itemFromKind } from './menu/submenu.js'; | ||
export { MenuItem } from './menu/menuItem.js'; | ||
@@ -3,0 +3,0 @@ export { Menu } from './menu/menu.js'; |
import { Resource } from '../core'; | ||
import { CheckMenuItemOptions } from './checkMenuItem'; | ||
import { IconMenuItemOptions } from './iconMenuItem'; | ||
import { MenuOptions } from './menu'; | ||
import { MenuItemOptions } from './menuItem'; | ||
import { PredefinedMenuItemOptions } from './predefinedMenuItem'; | ||
import { SubmenuOptions } from './submenu'; | ||
export type ItemKind = 'MenuItem' | 'Predefined' | 'Check' | 'Icon' | 'Submenu' | 'Menu'; | ||
export declare function newMenu(kind: ItemKind, opts?: unknown): Promise<[number, string]>; | ||
export declare function newMenu(kind: ItemKind, opts?: MenuOptions | MenuItemOptions | SubmenuOptions | PredefinedMenuItemOptions | CheckMenuItemOptions | IconMenuItemOptions): Promise<[number, string]>; | ||
export declare class MenuItemBase extends Resource { | ||
@@ -5,0 +11,0 @@ #private; |
@@ -29,2 +29,18 @@ import { __classPrivateFieldGet, __classPrivateFieldSet } from '../external/tslib/tslib.es6.js'; | ||
} | ||
// about predefined menu item icon | ||
if ('item' in opts && | ||
opts.item && | ||
typeof opts.item === 'object' && | ||
'About' in opts.item && | ||
opts.item.About && | ||
typeof opts.item.About === 'object' && | ||
'icon' in opts.item.About && | ||
opts.item.About.icon) { | ||
opts.item.About.icon = transformImage(opts.item.About.icon); | ||
} | ||
// icon menu item icon | ||
if ('icon' in opts && opts.icon) { | ||
opts.icon = transformImage(opts.icon); | ||
} | ||
// submenu items | ||
if ('items' in opts && opts.items) { | ||
@@ -49,2 +65,4 @@ function prepareItem(i) { | ||
} | ||
// @ts-expect-error the `prepareItem` return doesn't exactly match | ||
// this is fine, because the difference is in `[number, string]` variant | ||
opts.items = opts.items.map(prepareItem); | ||
@@ -51,0 +69,0 @@ } |
@@ -1,6 +0,2 @@ | ||
import { MenuItem } from './menuItem.js'; | ||
import { CheckMenuItem } from './checkMenuItem.js'; | ||
import { IconMenuItem } from './iconMenuItem.js'; | ||
import { PredefinedMenuItem } from './predefinedMenuItem.js'; | ||
import { Submenu } from './submenu.js'; | ||
import { itemFromKind } from './submenu.js'; | ||
import { Position } from '../dpi.js'; | ||
@@ -13,24 +9,2 @@ import { invoke } from '../core.js'; | ||
// SPDX-License-Identifier: MIT | ||
function itemFromKind([rid, id, kind]) { | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
switch (kind) { | ||
case 'Submenu': | ||
// @ts-expect-error constructor is protected for external usage only | ||
return new Submenu(rid, id); | ||
case 'Predefined': | ||
// @ts-expect-error constructor is protected for external usage only | ||
return new PredefinedMenuItem(rid, id); | ||
case 'Check': | ||
// @ts-expect-error constructor is protected for external usage only | ||
return new CheckMenuItem(rid, id); | ||
case 'Icon': | ||
// @ts-expect-error constructor is protected for external usage only | ||
return new IconMenuItem(rid, id); | ||
case 'MenuItem': | ||
default: | ||
// @ts-expect-error constructor is protected for external usage only | ||
return new MenuItem(rid, id); | ||
} | ||
/* eslint-enable @typescript-eslint/no-unsafe-return */ | ||
} | ||
/** A type that is either a menu bar on the window | ||
@@ -37,0 +11,0 @@ * on Windows and Linux or as a global menu in the menubar on macOS. |
@@ -7,4 +7,6 @@ import { IconMenuItemOptions, PredefinedMenuItemOptions, CheckMenuItemOptions } from '../menu'; | ||
import { type LogicalPosition, PhysicalPosition, type Window } from '../window'; | ||
import { MenuItemBase } from './base'; | ||
import { type ItemKind, MenuItemBase } from './base'; | ||
import { type MenuOptions } from './menu'; | ||
/** @ignore */ | ||
export declare function itemFromKind([rid, id, kind]: [number, string, ItemKind]): Submenu | MenuItem | PredefinedMenuItem | CheckMenuItem | IconMenuItem; | ||
export type SubmenuOptions = Omit<MenuItemOptions, 'accelerator' | 'action'> & MenuOptions; | ||
@@ -11,0 +13,0 @@ /** A type that is a submenu inside a {@linkcode Menu} or {@linkcode Submenu}. */ |
@@ -12,2 +12,3 @@ import { MenuItem } from './menuItem.js'; | ||
// SPDX-License-Identifier: MIT | ||
/** @ignore */ | ||
function itemFromKind([rid, id, kind]) { | ||
@@ -191,2 +192,2 @@ /* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
export { Submenu }; | ||
export { Submenu, itemFromKind }; |
@@ -1,2 +0,2 @@ | ||
import { InvokeArgs } from './core'; | ||
import type { InvokeArgs } from './core'; | ||
/** | ||
@@ -55,3 +55,3 @@ * Intercepts all IPC requests with the given mock handler. | ||
*/ | ||
export declare function mockIPC(cb: <T>(cmd: string, payload?: InvokeArgs) => Promise<T>): void; | ||
export declare function mockIPC(cb: (cmd: string, payload?: InvokeArgs) => unknown): void; | ||
/** | ||
@@ -58,0 +58,0 @@ * Mocks one or many window labels. |
@@ -81,3 +81,4 @@ // Copyright 2019-2024 Tauri Programme within The Commons Conservancy | ||
}; | ||
window.__TAURI_INTERNALS__.invoke = function (cmd, args, | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
window.__TAURI_INTERNALS__.invoke = async function (cmd, args, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
@@ -84,0 +85,0 @@ options) { |
{ | ||
"name": "@tauri-apps/api", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "Tauri API definitions", | ||
@@ -41,5 +41,5 @@ "funding": { | ||
"@rollup/plugin-terser": "0.4.4", | ||
"@rollup/plugin-typescript": "12.1.1", | ||
"@rollup/plugin-typescript": "12.1.2", | ||
"@types/eslint": "^9.0.0", | ||
"@types/node": "22.9.0", | ||
"@types/node": "^22.10.1", | ||
"eslint": "^9.4.0", | ||
@@ -50,5 +50,4 @@ "eslint-config-prettier": "9.1.0", | ||
"globals": "^15.4.0", | ||
"rollup": "4.24.4", | ||
"rollup": "4.29.1", | ||
"tslib": "^2.6.3", | ||
"typescript": "^5.4.5", | ||
"typescript-eslint": "^8.1.0" | ||
@@ -55,0 +54,0 @@ }, |
@@ -631,5 +631,5 @@ import { invoke } from './core.js'; | ||
async function isAbsolute(path) { | ||
return invoke('plugin:path|isAbsolute', { path }); | ||
return invoke('plugin:path|is_absolute', { path }); | ||
} | ||
export { BaseDirectory, appCacheDir, appConfigDir, appDataDir, appLocalDataDir, appLogDir, audioDir, basename, cacheDir, configDir, dataDir, delimiter, desktopDir, dirname, documentDir, downloadDir, executableDir, extname, fontDir, homeDir, isAbsolute, join, localDataDir, normalize, pictureDir, publicDir, resolve, resolveResource, resourceDir, runtimeDir, sep, tempDir, templateDir, videoDir }; |
@@ -85,4 +85,22 @@ import type { Menu, Submenu } from './menu'; | ||
iconAsTemplate?: boolean; | ||
/** Whether to show the tray menu on left click or not, default is `true`. **macOS only**. */ | ||
/** | ||
* Whether to show the tray menu on left click or not, default is `true`. | ||
* | ||
* #### Platform-specific: | ||
* | ||
* - **Linux**: Unsupported. | ||
* | ||
* @deprecated use {@linkcode TrayIconOptions.showMenuOnLeftClick} instead. | ||
*/ | ||
menuOnLeftClick?: boolean; | ||
/** | ||
* Whether to show the tray menu on left click or not, default is `true`. | ||
* | ||
* #### Platform-specific: | ||
* | ||
* - **Linux**: Unsupported. | ||
* | ||
* @since 2.2.0 | ||
*/ | ||
showMenuOnLeftClick?: boolean; | ||
/** A handler for an event on the tray icon. */ | ||
@@ -182,4 +200,22 @@ action?: (event: TrayIconEvent) => void; | ||
setIconAsTemplate(asTemplate: boolean): Promise<void>; | ||
/** Disable or enable showing the tray menu on left click. **macOS only**. */ | ||
/** | ||
* Disable or enable showing the tray menu on left click. | ||
* | ||
* #### Platform-specific: | ||
* | ||
* - **Linux**: Unsupported. | ||
* | ||
* @deprecated use {@linkcode TrayIcon.setShowMenuOnLeftClick} instead. | ||
*/ | ||
setMenuOnLeftClick(onLeft: boolean): Promise<void>; | ||
/** | ||
* Disable or enable showing the tray menu on left click. | ||
* | ||
* #### Platform-specific: | ||
* | ||
* - **Linux**: Unsupported. | ||
* | ||
* @since 2.2.0 | ||
*/ | ||
setShowMenuOnLeftClick(onLeft: boolean): Promise<void>; | ||
} |
25
tray.js
@@ -147,3 +147,11 @@ import { Resource, invoke, Channel } from './core.js'; | ||
} | ||
/** Disable or enable showing the tray menu on left click. **macOS only**. */ | ||
/** | ||
* Disable or enable showing the tray menu on left click. | ||
* | ||
* #### Platform-specific: | ||
* | ||
* - **Linux**: Unsupported. | ||
* | ||
* @deprecated use {@linkcode TrayIcon.setShowMenuOnLeftClick} instead. | ||
*/ | ||
async setMenuOnLeftClick(onLeft) { | ||
@@ -155,2 +163,17 @@ return invoke('plugin:tray|set_show_menu_on_left_click', { | ||
} | ||
/** | ||
* Disable or enable showing the tray menu on left click. | ||
* | ||
* #### Platform-specific: | ||
* | ||
* - **Linux**: Unsupported. | ||
* | ||
* @since 2.2.0 | ||
*/ | ||
async setShowMenuOnLeftClick(onLeft) { | ||
return invoke('plugin:tray|set_show_menu_on_left_click', { | ||
rid: this.rid, | ||
onLeft | ||
}); | ||
} | ||
} | ||
@@ -157,0 +180,0 @@ function mapEvent(e) { |
@@ -356,3 +356,3 @@ /** | ||
* if (event.payload.type === 'over') { | ||
* console.log('User hovering', event.payload.paths); | ||
* console.log('User hovering', event.payload.position); | ||
* } else if (event.payload.type === 'drop') { | ||
@@ -369,2 +369,5 @@ * console.log('User dropped', event.payload.paths); | ||
* | ||
* When the debugger panel is open, the drop position of this event may be inaccurate due to a known limitation. | ||
* To retrieve the correct drop position, please detach the debugger. | ||
* | ||
* @returns A promise resolving to a function to unlisten to the event. | ||
@@ -371,0 +374,0 @@ * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted. |
@@ -484,3 +484,3 @@ import { PhysicalPosition, PhysicalSize, Size, Position } from './dpi.js'; | ||
* if (event.payload.type === 'over') { | ||
* console.log('User hovering', event.payload.paths); | ||
* console.log('User hovering', event.payload.position); | ||
* } else if (event.payload.type === 'drop') { | ||
@@ -497,2 +497,5 @@ * console.log('User dropped', event.payload.paths); | ||
* | ||
* When the debugger panel is open, the drop position of this event may be inaccurate due to a known limitation. | ||
* To retrieve the correct drop position, please detach the debugger. | ||
* | ||
* @returns A promise resolving to a function to unlisten to the event. | ||
@@ -499,0 +502,0 @@ * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted. |
@@ -1022,2 +1022,55 @@ /** | ||
/** | ||
* Sets the badge count. It is app wide and not specific to this window. | ||
* | ||
* #### Platform-specific | ||
* | ||
* - **Windows**: Unsupported. Use @{linkcode Window.setOverlayIcon} instead. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { getCurrentWindow } from '@tauri-apps/api/window'; | ||
* await getCurrentWindow().setBadgeCount(5); | ||
* ``` | ||
* | ||
* @param count The badge count. Use `undefined` to remove the badge. | ||
* @return A promise indicating the success or failure of the operation. | ||
*/ | ||
setBadgeCount(count?: number): Promise<void>; | ||
/** | ||
* Sets the badge cont **macOS only**. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { getCurrentWindow } from '@tauri-apps/api/window'; | ||
* await getCurrentWindow().setBadgeLabel("Hello"); | ||
* ``` | ||
* | ||
* @param label The badge label. Use `undefined` to remove the badge. | ||
* @return A promise indicating the success or failure of the operation. | ||
*/ | ||
setBadgeLabel(label?: string): Promise<void>; | ||
/** | ||
* Sets the overlay icon. **Windows only** | ||
* The overlay icon can be set for every window. | ||
* | ||
* | ||
* Note that you may need the `image-ico` or `image-png` Cargo features to use this API. | ||
* To enable it, change your Cargo.toml file: | ||
* | ||
* ```toml | ||
* [dependencies] | ||
* tauri = { version = "...", features = ["...", "image-png"] } | ||
* ``` | ||
* | ||
* @example | ||
* ```typescript | ||
* import { getCurrentWindow } from '@tauri-apps/api/window'; | ||
* await getCurrentWindow().setOverlayIcon("/tauri/awesome.png"); | ||
* ``` | ||
* | ||
* @param icon Icon bytes or path to the icon file. Use `undefined` to remove the overlay icon. | ||
* @return A promise indicating the success or failure of the operation. | ||
*/ | ||
setOverlayIcon(icon?: string | Image | Uint8Array | ArrayBuffer | number[]): Promise<void>; | ||
/** | ||
* Sets the taskbar progress state. | ||
@@ -1138,3 +1191,3 @@ * | ||
* if (event.payload.type === 'over') { | ||
* console.log('User hovering', event.payload.paths); | ||
* console.log('User hovering', event.payload.position); | ||
* } else if (event.payload.type === 'drop') { | ||
@@ -1141,0 +1194,0 @@ * console.log('User dropped', event.payload.paths); |
@@ -1366,2 +1366,70 @@ import { PhysicalPosition, PhysicalSize, Size, Position } from './dpi.js'; | ||
/** | ||
* Sets the badge count. It is app wide and not specific to this window. | ||
* | ||
* #### Platform-specific | ||
* | ||
* - **Windows**: Unsupported. Use @{linkcode Window.setOverlayIcon} instead. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { getCurrentWindow } from '@tauri-apps/api/window'; | ||
* await getCurrentWindow().setBadgeCount(5); | ||
* ``` | ||
* | ||
* @param count The badge count. Use `undefined` to remove the badge. | ||
* @return A promise indicating the success or failure of the operation. | ||
*/ | ||
async setBadgeCount(count) { | ||
return invoke('plugin:window|set_badge_count', { | ||
label: this.label, | ||
value: count | ||
}); | ||
} | ||
/** | ||
* Sets the badge cont **macOS only**. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { getCurrentWindow } from '@tauri-apps/api/window'; | ||
* await getCurrentWindow().setBadgeLabel("Hello"); | ||
* ``` | ||
* | ||
* @param label The badge label. Use `undefined` to remove the badge. | ||
* @return A promise indicating the success or failure of the operation. | ||
*/ | ||
async setBadgeLabel(label) { | ||
return invoke('plugin:window|set_badge_label', { | ||
label: this.label, | ||
value: label | ||
}); | ||
} | ||
/** | ||
* Sets the overlay icon. **Windows only** | ||
* The overlay icon can be set for every window. | ||
* | ||
* | ||
* Note that you may need the `image-ico` or `image-png` Cargo features to use this API. | ||
* To enable it, change your Cargo.toml file: | ||
* | ||
* ```toml | ||
* [dependencies] | ||
* tauri = { version = "...", features = ["...", "image-png"] } | ||
* ``` | ||
* | ||
* @example | ||
* ```typescript | ||
* import { getCurrentWindow } from '@tauri-apps/api/window'; | ||
* await getCurrentWindow().setOverlayIcon("/tauri/awesome.png"); | ||
* ``` | ||
* | ||
* @param icon Icon bytes or path to the icon file. Use `undefined` to remove the overlay icon. | ||
* @return A promise indicating the success or failure of the operation. | ||
*/ | ||
async setOverlayIcon(icon) { | ||
return invoke('plugin:window|set_overlay_icon', { | ||
label: this.label, | ||
value: icon ? transformImage(icon) : undefined | ||
}); | ||
} | ||
/** | ||
* Sets the taskbar progress state. | ||
@@ -1522,3 +1590,3 @@ * | ||
* if (event.payload.type === 'over') { | ||
* console.log('User hovering', event.payload.paths); | ||
* console.log('User hovering', event.payload.position); | ||
* } else if (event.payload.type === 'drop') { | ||
@@ -1525,0 +1593,0 @@ * console.log('User dropped', event.payload.paths); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
628312
13
15475