mirror of
https://github.com/yang991178/fluent-reader.git
synced 2025-03-17 11:50:06 +01:00
open externally in background
This commit is contained in:
parent
2f9d1049a7
commit
fe0a8b9f17
@ -8,8 +8,8 @@ const utilsBridge = {
|
||||
return ipcRenderer.sendSync("get-version")
|
||||
},
|
||||
|
||||
openExternal: (url: string) => {
|
||||
ipcRenderer.invoke("open-external", url)
|
||||
openExternal: (url: string, background=false) => {
|
||||
ipcRenderer.invoke("open-external", url, background)
|
||||
},
|
||||
|
||||
showErrorBox: (title: string, content: string) => {
|
||||
|
@ -72,7 +72,7 @@ class Article extends React.Component<ArticleProps, ArticleState> {
|
||||
key: "openInBrowser",
|
||||
text: intl.get("openExternal"),
|
||||
iconProps: { iconName: "NavigateExternalInline" },
|
||||
onClick: this.openInBrowser
|
||||
onClick: e => { window.utils.openExternal(this.props.item.link, window.utils.platform === "darwin" ? e.metaKey : e.ctrlKey) }
|
||||
},
|
||||
{
|
||||
key: "copyURL",
|
||||
@ -171,10 +171,6 @@ class Article extends React.Component<ArticleProps, ArticleState> {
|
||||
if (refocus) refocus.focus()
|
||||
}
|
||||
|
||||
openInBrowser = () => {
|
||||
window.utils.openExternal(this.props.item.link)
|
||||
}
|
||||
|
||||
toggleWebpage = () => {
|
||||
if (this.state.loadWebpage) {
|
||||
this.setState({loadWebpage: false})
|
||||
|
@ -14,9 +14,9 @@ export namespace Card {
|
||||
showItem: (fid: string, item: RSSItem) => void
|
||||
}
|
||||
|
||||
const openInBrowser = (props: Props) => {
|
||||
const openInBrowser = (props: Props, e: React.MouseEvent) => {
|
||||
props.markRead(props.item)
|
||||
window.utils.openExternal(props.item.link)
|
||||
window.utils.openExternal(props.item.link, window.utils.platform === "darwin" ? e.metaKey : e.ctrlKey)
|
||||
}
|
||||
|
||||
export const bindEventsToProps = (props: Props) => ({
|
||||
@ -36,7 +36,7 @@ export namespace Card {
|
||||
break
|
||||
}
|
||||
case SourceOpenTarget.External: {
|
||||
openInBrowser(props)
|
||||
openInBrowser(props, e)
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -47,7 +47,7 @@ export namespace Card {
|
||||
e.stopPropagation()
|
||||
switch (e.button) {
|
||||
case 1:
|
||||
openInBrowser(props)
|
||||
openInBrowser(props, e)
|
||||
break
|
||||
case 2:
|
||||
props.contextMenu(props.feedId, props.item, e)
|
||||
|
@ -75,9 +75,9 @@ export class ContextMenu extends React.Component<ContextMenuProps> {
|
||||
key: "openInBrowser",
|
||||
text: intl.get("openExternal"),
|
||||
iconProps: { iconName: "NavigateExternalInline" },
|
||||
onClick: () => {
|
||||
onClick: (e) => {
|
||||
this.props.markRead(this.props.item)
|
||||
window.utils.openExternal(this.props.item.link)
|
||||
window.utils.openExternal(this.props.item.link, window.utils.platform === "darwin" ? e.metaKey : e.ctrlKey)
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -157,7 +157,13 @@ export class ContextMenu extends React.Component<ContextMenuProps> {
|
||||
key: "openInBrowser",
|
||||
text: intl.get("openExternal"),
|
||||
iconProps: { iconName: "NavigateExternalInline" },
|
||||
onClick: () => { window.utils.imageCallback(ImageCallbackTypes.OpenExternal) }
|
||||
onClick: (e) => {
|
||||
if (window.utils.platform === "darwin" ? e.metaKey : e.ctrlKey) {
|
||||
window.utils.imageCallback(ImageCallbackTypes.OpenExternalBg)
|
||||
} else {
|
||||
window.utils.imageCallback(ImageCallbackTypes.OpenExternal)
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "saveImageAs",
|
||||
|
@ -3,7 +3,6 @@ import { ThemeSettings, SchemaTypes } from "./schema-types"
|
||||
import { store } from "./main/settings"
|
||||
import performUpdate from "./main/update-scripts"
|
||||
import { WindowManager } from "./main/window"
|
||||
import { openExternal } from "./main/utils"
|
||||
|
||||
if (!process.mas) {
|
||||
const locked = app.requestSingleInstanceLock()
|
||||
@ -85,14 +84,3 @@ ipcMain.handle("import-all-settings", (_, configs: SchemaTypes) => {
|
||||
winManager.mainWindow.close()
|
||||
}, process.platform === "darwin" ? 1000 : 0); // Why ???
|
||||
})
|
||||
|
||||
app.on("web-contents-created", (_, contents) => {
|
||||
contents.on("new-window", (event, url) => {
|
||||
if (winManager.hasWindow()) event.preventDefault()
|
||||
if (contents.getType() === "webview") openExternal(url)
|
||||
})
|
||||
contents.on("will-navigate", (event, url) => {
|
||||
event.preventDefault()
|
||||
if (contents.getType() === "webview") openExternal(url)
|
||||
})
|
||||
})
|
||||
|
@ -1,20 +1,41 @@
|
||||
import { ipcMain, shell, dialog, app, session, webContents, clipboard } from "electron"
|
||||
import { ipcMain, shell, dialog, app, session, clipboard } from "electron"
|
||||
import { WindowManager } from "./window"
|
||||
import fs = require("fs")
|
||||
import { ImageCallbackTypes } from "../schema-types"
|
||||
|
||||
export function openExternal(url: string) {
|
||||
if (url.startsWith("https://") || url.startsWith("http://"))
|
||||
shell.openExternal(url)
|
||||
}
|
||||
|
||||
export function setUtilsListeners(manager: WindowManager) {
|
||||
async function openExternal(url: string, background=false) {
|
||||
if (url.startsWith("https://") || url.startsWith("http://")) {
|
||||
if (background && process.platform === "darwin") {
|
||||
shell.openExternal(url, { activate: false })
|
||||
} else if (background && manager.hasWindow()) {
|
||||
manager.mainWindow.setAlwaysOnTop(true)
|
||||
await shell.openExternal(url)
|
||||
setTimeout(() => manager.mainWindow.setAlwaysOnTop(false), 1000)
|
||||
} else {
|
||||
shell.openExternal(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
app.on("web-contents-created", (_, contents) => {
|
||||
contents.on("new-window", (event, url, _, disposition) => {
|
||||
if (manager.hasWindow()) event.preventDefault()
|
||||
if (contents.getType() === "webview") openExternal(url, disposition === "background-tab")
|
||||
})
|
||||
contents.on("will-navigate", (event, url) => {
|
||||
event.preventDefault()
|
||||
if (contents.getType() === "webview") openExternal(url)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
ipcMain.on("get-version", (event) => {
|
||||
event.returnValue = app.getVersion()
|
||||
})
|
||||
|
||||
ipcMain.handle("open-external", (_, url: string) => {
|
||||
openExternal(url)
|
||||
ipcMain.handle("open-external", (_, url: string, background: boolean) => {
|
||||
openExternal(url, background)
|
||||
})
|
||||
|
||||
ipcMain.handle("show-error-box", (_, title, content) => {
|
||||
@ -95,7 +116,8 @@ export function setUtilsListeners(manager: WindowManager) {
|
||||
ipcMain.handleOnce("image-callback", (_, type: ImageCallbackTypes) => {
|
||||
switch (type) {
|
||||
case ImageCallbackTypes.OpenExternal:
|
||||
openExternal(params.srcURL)
|
||||
case ImageCallbackTypes.OpenExternalBg:
|
||||
openExternal(params.srcURL, type === ImageCallbackTypes.OpenExternalBg)
|
||||
break
|
||||
case ImageCallbackTypes.SaveAs:
|
||||
contents.session.downloadURL(params.srcURL)
|
||||
@ -164,6 +186,10 @@ export function setUtilsListeners(manager: WindowManager) {
|
||||
if (manager.hasWindow()) {
|
||||
const win = manager.mainWindow
|
||||
if (win.isMinimized()) win.restore()
|
||||
if (process.platform === "win32") {
|
||||
win.setAlwaysOnTop(true)
|
||||
win.setAlwaysOnTop(false)
|
||||
}
|
||||
win.focus()
|
||||
}
|
||||
})
|
||||
|
@ -33,7 +33,7 @@ export const enum SearchEngines {
|
||||
}
|
||||
|
||||
export const enum ImageCallbackTypes {
|
||||
OpenExternal, SaveAs, Copy, CopyLink
|
||||
OpenExternal, OpenExternalBg, SaveAs, Copy, CopyLink
|
||||
}
|
||||
|
||||
export type SchemaTypes = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user