feat: tipc showShareMenu and saveToEagle
This commit is contained in:
+1
-43
@@ -1,5 +1,5 @@
|
||||
import "dotenv/config"
|
||||
import { app, BrowserWindow, ipcMain, ShareMenu } from "electron"
|
||||
import { app, BrowserWindow, ipcMain } from "electron"
|
||||
import path from "path"
|
||||
import { electronApp, optimizer } from "@electron-toolkit/utils"
|
||||
import { createWindow } from "./window"
|
||||
@@ -34,48 +34,6 @@ app.whenReady().then(() => {
|
||||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
|
||||
// IPC test
|
||||
ipcMain.on("ping", () => console.log("pong"))
|
||||
|
||||
ipcMain.on("share-url", (_, url: string) => {
|
||||
new ShareMenu({
|
||||
urls: [url],
|
||||
}).popup()
|
||||
})
|
||||
|
||||
ipcMain.on(
|
||||
"save-to-eagle",
|
||||
async (
|
||||
event,
|
||||
data: {
|
||||
url: string
|
||||
images: string[]
|
||||
},
|
||||
) => {
|
||||
try {
|
||||
const res = await fetch("http://localhost:41595/api/item/addFromURLs", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
items: data.images?.map((image) => ({
|
||||
url: image,
|
||||
website: data.url,
|
||||
headers: {
|
||||
referer: data.url,
|
||||
},
|
||||
})),
|
||||
}),
|
||||
})
|
||||
const result = await res.json()
|
||||
event.reply("save-to-eagle-reply", result)
|
||||
} catch (error) {
|
||||
event.reply("save-to-eagle-reply", null)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
createWindow()
|
||||
|
||||
app.on("activate", function () {
|
||||
|
||||
+40
-1
@@ -1,5 +1,5 @@
|
||||
import { tipc } from "@egoist/tipc/main"
|
||||
import { Menu, MessageBoxOptions, dialog } from "electron"
|
||||
import { Menu, MessageBoxOptions, ShareMenu, dialog } from "electron"
|
||||
|
||||
const t = tipc.create()
|
||||
|
||||
@@ -53,6 +53,45 @@ export const router = {
|
||||
})
|
||||
return result.response === 0
|
||||
}),
|
||||
|
||||
showShareMenu: t.procedure
|
||||
.input<string>()
|
||||
.action(async ({ input, context }) => {
|
||||
const menu = new ShareMenu({
|
||||
urls: [input],
|
||||
})
|
||||
|
||||
menu.popup({
|
||||
callback: () => {
|
||||
context.sender.send("menu-closed")
|
||||
},
|
||||
})
|
||||
}),
|
||||
|
||||
saveToEagle: t.procedure
|
||||
.input<{ url: string; images: string[] }>()
|
||||
.action(async ({ input }) => {
|
||||
try {
|
||||
const res = await fetch("http://localhost:41595/api/item/addFromURLs", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
items: input.images?.map((image) => ({
|
||||
url: image,
|
||||
website: input.url,
|
||||
headers: {
|
||||
referer: input.url,
|
||||
},
|
||||
})),
|
||||
}),
|
||||
})
|
||||
return await res.json()
|
||||
} catch (error) {
|
||||
return null
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
||||
export type Router = typeof router
|
||||
|
||||
Reference in New Issue
Block a user