feat(desktop): updateNotificationsToken
This commit is contained in:
parent
102710ef2f
commit
be093e1b75
|
|
@ -183,9 +183,9 @@ function bootstrap() {
|
|||
|
||||
if (ck && apiURL) {
|
||||
const cookie = parse(atob(ck), { decode: (value) => value })
|
||||
Object.keys(cookie).forEach((name) => {
|
||||
Object.keys(cookie).forEach(async (name) => {
|
||||
const value = cookie[name]
|
||||
mainWindow.webContents.session.cookies.set({
|
||||
await mainWindow.webContents.session.cookies.set({
|
||||
url: apiURL,
|
||||
name,
|
||||
value,
|
||||
|
|
|
|||
|
|
@ -153,8 +153,6 @@ const registerPushNotifications = async () => {
|
|||
const credentials = store.get(credentialsKey)
|
||||
const persistentIds = store.get(persistentIdsKey)
|
||||
|
||||
updateNotificationsToken()
|
||||
|
||||
const instance = new PushReceiver({
|
||||
debug: true,
|
||||
firebase: JSON.parse(env.VITE_FIREBASE_CONFIG),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type { Credentials } from "@eneris/push-receiver/dist/types"
|
||||
import type { Cookie } from "electron"
|
||||
import Store from "electron-store"
|
||||
|
||||
// @keep-sorted
|
||||
|
|
@ -7,9 +6,7 @@ type StoreData = {
|
|||
"notifications-credentials"?: Credentials | null
|
||||
"notifications-persistent-ids"?: string[] | null
|
||||
appearance?: "light" | "dark" | "system" | null
|
||||
betterAuthSessionCookie?: string | null
|
||||
cacheSizeLimit?: number | null
|
||||
cookies?: Cookie[] | null
|
||||
minimizeToTray?: boolean | null
|
||||
proxy?: string | null
|
||||
user?: string | null
|
||||
|
|
|
|||
|
|
@ -6,6 +6,14 @@ import { logger } from "~/logger"
|
|||
import { apiClient } from "./api-client"
|
||||
import { store } from "./store"
|
||||
|
||||
const notificationChannel = isMacOS
|
||||
? "macos"
|
||||
: isWindows
|
||||
? "windows"
|
||||
: isLinux
|
||||
? "linux"
|
||||
: "desktop"
|
||||
|
||||
export const updateNotificationsToken = async (newCredentials?: Credentials) => {
|
||||
if (newCredentials) {
|
||||
store.set("notifications-credentials", newCredentials)
|
||||
|
|
@ -16,7 +24,7 @@ export const updateNotificationsToken = async (newCredentials?: Credentials) =>
|
|||
await apiClient.messaging.$post({
|
||||
json: {
|
||||
token: credentials.fcm.token,
|
||||
channel: isMacOS ? "macos" : isWindows ? "windows" : isLinux ? "linux" : "desktop",
|
||||
channel: notificationChannel,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
|
|
@ -24,3 +32,11 @@ export const updateNotificationsToken = async (newCredentials?: Credentials) =>
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteNotificationsToken = async () => {
|
||||
await apiClient.messaging.$delete({
|
||||
json: {
|
||||
channel: notificationChannel,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
import { deleteNotificationsToken, updateNotificationsToken } from "~/lib/user"
|
||||
|
||||
import { t } from "./_instance"
|
||||
|
||||
export const authRoute = {
|
||||
sessionChanged: t.procedure.action(async () => {
|
||||
await updateNotificationsToken()
|
||||
}),
|
||||
|
||||
signOut: t.procedure.action(async () => {
|
||||
await deleteNotificationsToken()
|
||||
}),
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import { appRoute } from "./app"
|
||||
import { authRoute } from "./auth"
|
||||
import { debugRoute } from "./debug"
|
||||
import { dockRoute } from "./dock"
|
||||
import { menuRoute } from "./menu"
|
||||
|
|
@ -12,6 +13,7 @@ export const router = {
|
|||
...appRoute,
|
||||
...dockRoute,
|
||||
...readerRoute,
|
||||
...authRoute,
|
||||
}
|
||||
|
||||
export type Router = typeof router
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { setWhoami } from "~/atoms/user"
|
|||
import { QUERY_PERSIST_KEY } from "~/constants"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
import { getAccountInfo, getSession, signOut as signOutFn } from "~/lib/auth"
|
||||
import { tipcClient } from "~/lib/client"
|
||||
import { defineQuery } from "~/lib/defineQuery"
|
||||
import { clearLocalPersistStoreData } from "~/store/utils/clear"
|
||||
|
||||
|
|
@ -71,6 +72,7 @@ export const useSession = (options?: { enabled?: boolean }) => {
|
|||
}
|
||||
|
||||
export const handleSessionChanges = () => {
|
||||
tipcClient?.sessionChanged()
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +94,7 @@ export const signOut = async () => {
|
|||
// clear local store data
|
||||
await clearLocalPersistStoreData()
|
||||
// Sign out
|
||||
await signOutFn().then(() => {
|
||||
handleSessionChanges()
|
||||
})
|
||||
await tipcClient?.signOut()
|
||||
await signOutFn()
|
||||
window.location.reload()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2193,6 +2193,23 @@ declare const entries: drizzle_orm_pg_core.PgTableWithColumns<{
|
|||
identity: undefined;
|
||||
generated: undefined;
|
||||
}, {}, {}>;
|
||||
readabilityContent: drizzle_orm_pg_core.PgColumn<{
|
||||
name: "readability_content";
|
||||
tableName: "entries";
|
||||
dataType: "string";
|
||||
columnType: "PgText";
|
||||
data: string;
|
||||
driverParam: string;
|
||||
notNull: false;
|
||||
hasDefault: false;
|
||||
isPrimaryKey: false;
|
||||
isAutoincrement: false;
|
||||
hasRuntimeDefault: false;
|
||||
enumValues: [string, ...string[]];
|
||||
baseColumn: never;
|
||||
identity: undefined;
|
||||
generated: undefined;
|
||||
}, {}, {}>;
|
||||
};
|
||||
dialect: "pg";
|
||||
}>;
|
||||
|
|
@ -2426,6 +2443,7 @@ declare const entriesOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
|
|||
} | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null>>;
|
||||
language: z.ZodNullable<z.ZodString>;
|
||||
feedId: z.ZodString;
|
||||
readabilityContent: z.ZodNullable<z.ZodString>;
|
||||
}, "media" | "attachments" | "extra">, {
|
||||
attachments: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
||||
url: z.ZodString;
|
||||
|
|
@ -2504,6 +2522,7 @@ declare const entriesOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
|
|||
url: string | null;
|
||||
language: string | null;
|
||||
feedId: string;
|
||||
readabilityContent: string | null;
|
||||
guid: string;
|
||||
categories: string[] | null;
|
||||
authorUrl: string | null;
|
||||
|
|
@ -2541,6 +2560,7 @@ declare const entriesOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
|
|||
url: string | null;
|
||||
language: string | null;
|
||||
feedId: string;
|
||||
readabilityContent: string | null;
|
||||
guid: string;
|
||||
categories: string[] | null;
|
||||
authorUrl: string | null;
|
||||
|
|
@ -13218,6 +13238,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
|||
description?: string | undefined;
|
||||
title?: string | undefined;
|
||||
content?: string | undefined;
|
||||
readabilityContent?: string | undefined;
|
||||
} | undefined;
|
||||
};
|
||||
outputFormat: "json";
|
||||
|
|
@ -13231,6 +13252,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
|||
query: {
|
||||
id: string;
|
||||
language?: "ar-DZ" | "ar-IQ" | "ar-KW" | "ar-MA" | "ar-SA" | "ar-TN" | "de" | "en" | "es" | "fi" | "fr" | "it" | "ja" | "ko" | "pt" | "ru" | "tr" | "zh-CN" | "zh-HK" | "zh-TW" | undefined;
|
||||
target?: "content" | "readabilityContent" | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
|
|
@ -13372,6 +13394,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
|||
url: string | null;
|
||||
language: string | null;
|
||||
feedId: string;
|
||||
readabilityContent: string | null;
|
||||
guid: string;
|
||||
categories: string[] | null;
|
||||
authorUrl: string | null;
|
||||
|
|
@ -13835,6 +13858,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
|||
author: string | null;
|
||||
url: string | null;
|
||||
language: string | null;
|
||||
readabilityContent: string | null;
|
||||
guid: string;
|
||||
categories: string[] | null;
|
||||
authorUrl: string | null;
|
||||
|
|
@ -13942,6 +13966,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
|||
author: string | null;
|
||||
url: string | null;
|
||||
language: string | null;
|
||||
readabilityContent: string | null;
|
||||
guid: string;
|
||||
categories: string[] | null;
|
||||
authorUrl: string | null;
|
||||
|
|
@ -14009,6 +14034,24 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
|||
status: 200;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
"/readability": {
|
||||
$get: {
|
||||
input: {
|
||||
query: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 0;
|
||||
data: {
|
||||
content?: string | null | undefined;
|
||||
} | null;
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
"/stream": {
|
||||
$post: {
|
||||
|
|
@ -14041,6 +14084,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
|||
url: string | null;
|
||||
language: string | null;
|
||||
feedId: string;
|
||||
readabilityContent: string | null;
|
||||
guid: string;
|
||||
categories: string[] | null;
|
||||
authorUrl: string | null;
|
||||
|
|
@ -14176,6 +14220,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
|||
author: string | null;
|
||||
url: string | null;
|
||||
language: string | null;
|
||||
readabilityContent: string | null;
|
||||
guid: string;
|
||||
categories: string[] | null;
|
||||
authorUrl: string | null;
|
||||
|
|
@ -15203,6 +15248,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
|||
};
|
||||
language: string | null;
|
||||
feedId: string;
|
||||
readabilityContent: string | null;
|
||||
guid: string;
|
||||
categories: string[] | null;
|
||||
authorUrl: string | null;
|
||||
|
|
@ -15815,6 +15861,21 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
|||
status: 200;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
"/": {
|
||||
$delete: {
|
||||
input: {
|
||||
json: {
|
||||
channel: "macos" | "windows" | "linux" | "ios" | "android" | "web" | "desktop";
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 0;
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
};
|
||||
};
|
||||
}, "/messaging"> | hono_types.MergeSchemaPath<{
|
||||
"/configs": {
|
||||
$get: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue