Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into feature/lists-3
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Sep 20, 2024
2 parents 6e150a2 + 039dd3d commit fb90a43
Show file tree
Hide file tree
Showing 144 changed files with 4,703 additions and 521 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ on:
push:
branches: [main, dev]

name: CI Typecheck and Lint
name: CI Format, Typecheck and Lint
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: Lint and Typecheck
name: Format, Lint and Typecheck
runs-on: ubuntu-latest

strategy:
Expand All @@ -33,10 +33,10 @@ jobs:
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Lint and Typecheck

- name: Format, Lint and Typecheck
run: |
pnpm run format:check
pnpm run typecheck
npm run lint
pnpm run lint
- name: Run test
run: pnpm test
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
packages/shared/src/hono.ts
pnpm-lock.yaml
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"severity": "off"
}
],
"cSpell.words": ["rsshub"],
"cSpell.words": ["rsshub", "Русский"],
"editor.foldingImportsByDefault": true,
"commentTranslate.hover.enabled": false,
"typescript.tsdk": "node_modules/typescript/lib",
Expand Down
59 changes: 0 additions & 59 deletions apps/main/src/@types/default-resource.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/main/src/@types/resources.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import en from "@locales/native/en-US.json"
import en from "@locales/native/en.json"
import ja from "@locales/native/ja.json"
import zh from "@locales/native/zh-CN.json"

Expand Down
2 changes: 2 additions & 0 deletions apps/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import squirrelStartup from "electron-squirrel-startup"

import { isDev, isMacOS } from "./env"
import { initializeAppStage0, initializeAppStage1 } from "./init"
import { updateProxy } from "./lib/proxy"
import { setAuthSessionToken } from "./lib/user"
import { registerUpdater } from "./updater"
import { createMainWindow, createWindow } from "./window"
Expand Down Expand Up @@ -52,6 +53,7 @@ function bootstrap() {

mainWindow = createMainWindow()

updateProxy()
registerUpdater()

//remove Electron, Follow from user agent
Expand Down
18 changes: 17 additions & 1 deletion apps/main/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ export const initializeAppStage1 = () => {
registerMenuAndContextMenu()
}

let contextMenuDisposer: () => void
export const registerMenuAndContextMenu = () => {
registerAppMenu()
contextMenu({
if (contextMenuDisposer) {
contextMenuDisposer()
}

contextMenuDisposer = contextMenu({
showSaveImageAs: true,
showCopyLink: true,
showCopyImageAddress: true,
Expand All @@ -75,6 +80,17 @@ export const registerMenuAndContextMenu = () => {
copyVideoAddress: t("contextMenu.copyVideoAddress"),
saveVideoAs: t("contextMenu.saveVideoAs"),
inspect: t("contextMenu.inspect"),
copy: t("contextMenu.copy"),
cut: t("contextMenu.cut"),
paste: t("contextMenu.paste"),
saveImage: t("contextMenu.saveImage"),
saveVideo: t("contextMenu.saveVideo"),
selectAll: t("contextMenu.selectAll"),
services: t("contextMenu.services"),
searchWithGoogle: t("contextMenu.searchWithGoogle"),
learnSpelling: t("contextMenu.learnSpelling"),
lookUpSelection: t("contextMenu.lookUpSelection"),
saveLinkAs: t("contextMenu.saveLinkAs"),
},

prepend: (_defaultActions, params) => {
Expand Down
58 changes: 58 additions & 0 deletions apps/main/src/lib/context-menu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { BrowserWindow } from "electron"
import { Menu } from "electron"

import { t } from "./i18n"

export const registerContextMenu = (window: BrowserWindow) => {
const handler = (_event: Electron.Event, props: Electron.ContextMenuParams) => {
const { selectionText, isEditable } = props

const selectionMenu = Menu.buildFromTemplate([
{ role: "copy", label: t("menu.copy"), accelerator: "CmdOrCtrl+C" },
{ type: "separator" },
{ role: "selectAll", label: t("menu.selectAll"), accelerator: "CmdOrCtrl+A" },
])

const inputMenu = Menu.buildFromTemplate([
{ role: "undo", label: t("menu.undo"), accelerator: "CmdOrCtrl+Z" },
{
role: "redo",
label: t("menu.redo"),
accelerator: "CmdOrCtrl+Shift+Z",
},
{ type: "separator" },
{
role: "cut",
label: t("menu.cut"),
accelerator: "CmdOrCtrl+X",
},
{
role: "copy",
label: t("menu.copy"),
accelerator: "CmdOrCtrl+C",
},
{
role: "paste",
label: t("menu.paste"),
accelerator: "CmdOrCtrl+V",
},
{
type: "separator",
},
{ role: "selectAll", label: t("menu.selectAll"), accelerator: "CmdOrCtrl+A" },
])

if (isEditable) {
inputMenu.popup({
window,
})
} else if (selectionText && selectionText.trim() !== "") {
selectionMenu.popup({ window })
}
}
window.webContents.on("context-menu", handler)

return () => {
window.webContents.removeListener("context-menu", handler)
}
}
76 changes: 76 additions & 0 deletions apps/main/src/lib/proxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { session } from "electron"

import { logger } from "../logger"
import { store } from "./store"

// Sets up the proxy configuration for the app.
//
// See https://www.electronjs.org/docs/latest/api/session#sessetproxyconfig
// for more information about the proxy API.
//
// The open-source project [poooi/poi](https://github.com/poooi/poi) is doing well in proxy configuration
// refer the following files for more details:
//
// https://github.com/poooi/poi/blob/5741d0d02c0a08626dd53196b094223457014491/lib/proxy.ts#L36
// https://github.com/poooi/poi/blob/5741d0d02c0a08626dd53196b094223457014491/views/components/settings/network/index.es

export const setProxyConfig = (inputProxy: string) => {
const proxyUri = normalizeProxyUri(inputProxy)
if (!proxyUri) {
return false
}
store.set("proxy", inputProxy)
return true
}

export const getProxyConfig = () => {
const proxyConfig = store.get("proxy") as string | undefined
if (!proxyConfig) {
return
}
const proxyUri = normalizeProxyUri(proxyConfig)
return proxyUri
}

const URL_SCHEME = new Set(["http:", "https:", "ftp:", "socks:", "socks4:", "socks5:"])

const normalizeProxyUri = (userProxy: string) => {
if (!userProxy) {
return
}
try {
const proxyUrl = new URL(userProxy)
if (!URL_SCHEME.has(proxyUrl.protocol) || !proxyUrl.hostname || !proxyUrl.port) {
return
}
// There are multiple ways to specify a proxy in Electron,
// but for security reasons, we only support simple proxy URLs for now.
return [
`${proxyUrl.protocol}//${proxyUrl.hostname}:${proxyUrl.port}`,
// Failing over to using no proxy if the proxy is unavailable
"direct://",
].join(",")
} catch {
return
}
}

const BYPASS_RULES = ["<local>"].join(";")

export const updateProxy = () => {
const proxyUri = getProxyConfig()
if (!proxyUri) {
session.defaultSession.setProxy({
// Note that the system mode is different from setting no proxy configuration.
// In the latter case, Electron falls back to the system settings only if no command-line options influence the proxy configuration.
mode: "system",
})
return
}

logger.log(`Loading proxy: ${proxyUri}`)
session.defaultSession.setProxy({
proxyRules: proxyUri,
proxyBypassRules: BYPASS_RULES,
})
}
Loading

0 comments on commit fb90a43

Please sign in to comment.