Skip to content

Commit

Permalink
feat: Firefox adapted
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Apr 4, 2024
1 parent b8d820f commit b2945db
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
39 changes: 21 additions & 18 deletions background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import sniffer from "url:~/pages/sniffer.tsx"

import { Storage } from "@plasmohq/storage"

import path from "path"

import { STORAGE_SERVER_STATUS, STORAGE_SERVERS } from "~constants"
import { getSelectedServer } from "~util"

Expand Down Expand Up @@ -77,7 +79,10 @@ export async function checkServer(server: Server): Promise<CheckResult> {
setInterval(checkAllServers, 3000)
})()

chrome.downloads.onDeterminingFilename.addListener(async function (item) {
// chrome.downloads.onDeterminingFilename only available in Chrome
const downloadEvent = chrome.downloads.onDeterminingFilename || chrome.downloads.onCreated

downloadEvent.addListener(async function (item) {
const server = await getSelectedServer()
if (!server) return

Expand All @@ -86,28 +91,26 @@ chrome.downloads.onDeterminingFilename.addListener(async function (item) {
await chrome.downloads.removeFile(item.id)
}

chrome.system.display.getInfo({ singleUnified: true }, (info) => {
const wDimension = info[0].workArea
const { top, left, height, width } = wDimension
const w = 480
const h = 600
const l = width / 2 - w / 2 + left
const t = height / 2 - h / 2 + top
const asset = <Asset>{
filename: item.filename,
filesize: item.fileSize,
finalUrl: item.finalUrl
}

const asset = <Asset>{
filename: path.basename(item.filename.replaceAll("\\", "/")),
filesize: item.fileSize,
finalUrl: item.finalUrl || item.url
}
chrome.windows.getCurrent((currentWindow) => {
const width = 480
const height = 600
const left = Math.round((currentWindow.width - width) * 0.5 + currentWindow.left)
const top = Math.round((currentWindow.height - height) * 0.5 + currentWindow.top)
console.log("onCreated 222", currentWindow, width, height, left, top)
chrome.windows.create({
url: `tabs/create.html?asset=${encodeURIComponent(
JSON.stringify(asset)
)}`,
type: "popup",
width: w,
height: h,
left: Math.round(l),
top: Math.round(t)
width,
height,
left,
top
})
})
})
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gopeed-browser-extension",
"displayName": "Gopeed",
"version": "0.0.2",
"version": "0.0.3",
"description": "Gopeed browser extension",
"homepage": "https://gopeed.com",
"author": "Levi",
Expand Down Expand Up @@ -41,8 +41,12 @@
},
"manifest": {
"permissions": [
"system.display",
"downloads"
]
],
"browser_specific_settings": {
"gecko": {
"id": "{c5d69a8f-2ed0-46a7-afa4-b3a00dc58088}"
}
}
}
}
1 change: 1 addition & 0 deletions popup/create-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function CreateServer(props: { onClose: () => void }) {

doSave()
} catch (e) {
console.error(e)
} finally {
setLoading(false)
}
Expand Down

0 comments on commit b2945db

Please sign in to comment.