Skip to content

Commit

Permalink
refactor: implement js apis
Browse files Browse the repository at this point in the history
  • Loading branch information
ahqsoftwares committed Nov 13, 2024
1 parent 68ce410 commit abbfe4f
Showing 1 changed file with 76 additions and 5 deletions.
81 changes: 76 additions & 5 deletions packages/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,77 @@ class Window {
})
}

/**
* Sets the badge count. It is app wide and not specific to this window.
*
* #### Platform-specific
*
* - **Windows**: Use `setOverlayIcon` instead.
*
* @example
* ```typescript
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setBadgeCount(5);
* ```
*
* @param count The badge count. Set undefined to remove the badge.
* @return A promise indicating the success or failure of the operation.
*/
async setBadgeCount(count?: number): Promise<void> {
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. Set undefined to remove the badge.
* @return A promise indicating the success or failure of the operation.
*/
async setBadgeLabel(label?: string): Promise<void> {
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. Set undefined to remove the overlay icon.
* @return A promise indicating the success or failure of the operation.
*/
async setOverlayIcon(icon?: string | Image | Uint8Array | ArrayBuffer | number[]): Promise<void> {
return invoke('plugin:window|set_overlay_icon', {
label: this.label,
value: icon ? transformImage(icon) : undefined
})
}

/**
* Sets the taskbar progress state.
*
Expand Down Expand Up @@ -2271,11 +2342,11 @@ function mapMonitor(m: Monitor | null): Monitor | null {
return m === null
? null
: {
name: m.name,
scaleFactor: m.scaleFactor,
position: new PhysicalPosition(m.position),
size: new PhysicalSize(m.size)
}
name: m.name,
scaleFactor: m.scaleFactor,
position: new PhysicalPosition(m.position),
size: new PhysicalSize(m.size)
}
}

/**
Expand Down

0 comments on commit abbfe4f

Please sign in to comment.