mirror of
https://github.com/ivabus/gui
synced 2025-04-24 14:37:11 +03:00
29 lines
1,009 B
TypeScript
29 lines
1,009 B
TypeScript
import Pushy from "pushy-electron";
|
|
import { readSessionData } from "./auth";
|
|
import { post } from "./v1-client";
|
|
import * as log from "electron-log";
|
|
import { BrowserWindow } from "electron";
|
|
|
|
export default function initialize(mainWindow: BrowserWindow) {
|
|
Pushy.listen();
|
|
// Register device for push notifications
|
|
Pushy.register({ appId: "64110fb47446e48a2a0e906d" })
|
|
.then(async (token) => {
|
|
const { device_id } = await readSessionData();
|
|
console.log("DEVICE_ID:", device_id, token);
|
|
if (device_id)
|
|
await post(`/auth/device/${device_id}/register-push-token`, { push_token: token });
|
|
})
|
|
.catch((err) => {
|
|
// Display error dialog
|
|
// Pushy.alert(mainWindow, 'Pushy registration error: ' + err.message);
|
|
});
|
|
|
|
// Listen for incoming notifications
|
|
Pushy.setNotificationListener((data: any) => {
|
|
// Display an alert with the "message" payload value
|
|
log.info("push data:", data);
|
|
// TODO: replace this with something
|
|
Pushy.alert(mainWindow, data?.message as string);
|
|
});
|
|
}
|