mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
feat: update to tauri 2.0.0-alpha.9 (#372)
This commit is contained in:
committed by
GitHub
parent
717ae67097
commit
3c9771e287
@@ -24,7 +24,11 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
import { invoke, transformCallback } from "@tauri-apps/api/tauri";
|
||||
import {
|
||||
invoke,
|
||||
PluginListener,
|
||||
addPluginListener,
|
||||
} from "@tauri-apps/api/tauri";
|
||||
|
||||
/**
|
||||
* Options to send a notification.
|
||||
@@ -551,59 +555,16 @@ async function channels(): Promise<Channel[]> {
|
||||
return invoke("plugin:notification|getActive");
|
||||
}
|
||||
|
||||
class EventChannel {
|
||||
id: number;
|
||||
unregisterFn: (channel: EventChannel) => Promise<void>;
|
||||
|
||||
constructor(
|
||||
id: number,
|
||||
unregisterFn: (channel: EventChannel) => Promise<void>
|
||||
) {
|
||||
this.id = id;
|
||||
this.unregisterFn = unregisterFn;
|
||||
}
|
||||
|
||||
toJSON(): string {
|
||||
return `__CHANNEL__:${this.id}`;
|
||||
}
|
||||
|
||||
async unregister(): Promise<void> {
|
||||
return this.unregisterFn(this);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: use addPluginListener API on @tauri-apps/api/tauri 2.0.0-alpha.4
|
||||
async function onNotificationReceived(
|
||||
cb: (notification: Options) => void
|
||||
): Promise<EventChannel> {
|
||||
const channelId = transformCallback(cb);
|
||||
const handler = new EventChannel(channelId, (channel) =>
|
||||
invoke("plugin:notification|remove_listener", {
|
||||
event: "notification",
|
||||
channelId: channel.id,
|
||||
})
|
||||
);
|
||||
return invoke("plugin:notification|register_listener", {
|
||||
event: "notification",
|
||||
handler,
|
||||
}).then(() => handler);
|
||||
): Promise<PluginListener> {
|
||||
return addPluginListener("notification", "notification", cb);
|
||||
}
|
||||
|
||||
// TODO: use addPluginListener API on @tauri-apps/api/tauri 2.0.0-alpha.4
|
||||
async function onAction(
|
||||
cb: (notification: Options) => void
|
||||
): Promise<EventChannel> {
|
||||
const channelId = transformCallback(cb);
|
||||
const handler = new EventChannel(channelId, (channel) =>
|
||||
invoke("plugin:notification|remove_listener", {
|
||||
event: "actionPerformed",
|
||||
channelId: channel.id,
|
||||
})
|
||||
);
|
||||
return invoke("plugin:notification|register_listener", {
|
||||
event: "actionPerformed",
|
||||
handler,
|
||||
}).then(() => handler);
|
||||
): Promise<PluginListener> {
|
||||
return addPluginListener("notification", "actionPerformed", cb);
|
||||
}
|
||||
|
||||
export type {
|
||||
|
||||
@@ -27,6 +27,6 @@
|
||||
"tslib": "^2.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^1.2.0"
|
||||
"@tauri-apps/api": "2.0.0-alpha.4"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user