Skip to content

Commit

Permalink
Features jun2014 (#24)
Browse files Browse the repository at this point in the history
* [webpage] Add DevTools

* [webpage] Reload improvements + Hard reload
  • Loading branch information
alexk111 authored Jun 28, 2024
1 parent d5adaf6 commit 3e1fa29
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 24 deletions.
24 changes: 12 additions & 12 deletions src/renderer/widgets/webpage/actionBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ export function createActionBarItems(
return []
}

let reloadItem: ActionBarItem;
if (autoReload > 0) {
reloadItem = {
enabled: canReload(),
icon: autoReloadStopped ? reloadStartSvg : reloadStopSvg,
id: 'RELOAD',
title: autoReloadStopped ? labelAutoReloadStart : labelAutoReloadStop,
doAction: async () => setAutoReloadStopped(!autoReloadStopped)
}
} else {
reloadItem = {
let reloadItems: ActionBarItem[] = [
{
enabled: canReload(),
icon: reloadSvg,
id: 'RELOAD',
title: labelReload,
doAction: async () => reload(elWebview)
}
];
if (autoReload > 0) {
reloadItems = [{
enabled: canReload(),
icon: autoReloadStopped ? reloadStartSvg : reloadStopSvg,
id: 'AUTO-RELOAD',
title: autoReloadStopped ? labelAutoReloadStart : labelAutoReloadStop,
doAction: async () => setAutoReloadStopped(!autoReloadStopped)
}, ...reloadItems]
}

return [
Expand All @@ -61,7 +61,7 @@ export function createActionBarItems(
title: labelGoForward,
doAction: async () => goForward(elWebview)
},
reloadItem,
...reloadItems,
{
enabled: true,
icon: openInBrowserSvg,
Expand Down
16 changes: 16 additions & 0 deletions src/renderer/widgets/webpage/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const labelGoHome = 'Go to start page';
export const labelGoBack = 'Go Back';
export const labelGoForward = 'Go Forward';
export const labelReload = 'Reload this page';
export const labelHardReload = 'Hard reload this page';
export const labelAutoReloadStart = 'Start auto-reload';
export const labelAutoReloadStop = 'Stop auto-reload';
export const labelOpenInBrowser = 'Open in web browser';
Expand All @@ -29,6 +30,7 @@ export const labelCopy = 'Copy';
export const labelPaste = 'Paste';
export const labelPasteAsPlainText = 'Paste as plain text';
export const labelSelectAll = 'Select All';
export const labelDevTools = 'Developer tools'


export function canReload() {
Expand All @@ -42,6 +44,13 @@ export function reload(elWebview: Electron.WebviewTag) {
elWebview.reload();
}

export function hardReload(elWebview: Electron.WebviewTag) {
if (elWebview.isLoading()) {
elWebview.stop();
}
elWebview.reloadIgnoringCache();
}

export function canGoBack(elWebview: Electron.WebviewTag) {
return elWebview.canGoBack();
}
Expand Down Expand Up @@ -103,3 +112,10 @@ export function saveLink(url: string, elWebview: Electron.WebviewTag) {
export function copyLinkAddress(title: string, url: string, widgetApi: WidgetApi) {
widgetApi.clipboard.writeBookmark(title, url);
}

export function openDevTools(elWebview: Electron.WebviewTag) {
if (elWebview.isDevToolsOpened()) {
elWebview.closeDevTools();
}
elWebview.openDevTools();
}
36 changes: 26 additions & 10 deletions src/renderer/widgets/webpage/contextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* GNU General Public License v3.0 or later (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
*/

import { canGoBack, canGoForward, canGoHome, copyCurrentAddress, copyLinkAddress, goBack, goForward, goHome, labelAutoReloadStart, labelAutoReloadStop, labelCopy, labelCopyCurrentAddress, labelCopyImageAddress, labelCopyLinkAddress, labelCut, labelGoBack, labelGoForward, labelGoHome, labelOpenInBrowser, labelOpenLinkInBrowser, labelPaste, labelPasteAsPlainText, labelPrintPage, labelRedo, labelReload, labelSaveAs, labelSaveImageAs, labelSaveLinkAs, labelSelectAll, labelUndo, openCurrentInBrowser, openLinkInBrowser, printPage, reload, saveLink, savePage } from './actions';
import { canGoBack, canGoForward, canGoHome, copyCurrentAddress, copyLinkAddress, goBack, goForward, goHome, hardReload, labelAutoReloadStart, labelAutoReloadStop, labelCopy, labelCopyCurrentAddress, labelCopyImageAddress, labelCopyLinkAddress, labelCut, labelDevTools, labelGoBack, labelGoForward, labelGoHome, labelHardReload, labelOpenInBrowser, labelOpenLinkInBrowser, labelPaste, labelPasteAsPlainText, labelPrintPage, labelRedo, labelReload, labelSaveAs, labelSaveImageAs, labelSaveLinkAs, labelSelectAll, labelUndo, openCurrentInBrowser, openDevTools, openLinkInBrowser, printPage, reload, saveLink, savePage } from './actions';
import { WidgetApi, WidgetContextMenuFactory, WidgetMenuItem } from '@/widgets/appModules';
import { ContextMenuParams } from 'electron';

Expand All @@ -26,17 +26,21 @@ export function createContextMenuFactory(
return (_contextId, contextData) => {
const items: WidgetMenuItem[] = []
if (elWebview && homeUrl) {
let reloadItem: WidgetMenuItem;
if (autoReload > 0) {
reloadItem = {
doAction: async () => setAutoReloadStopped(!autoReloadStopped),
label: autoReloadStopped ? labelAutoReloadStart : labelAutoReloadStop
}
} else {
reloadItem = {
let reloadItems: WidgetMenuItem[] = [
{
doAction: async () => reload(elWebview),
label: labelReload
},
{
doAction: async () => hardReload(elWebview),
label: labelHardReload
}
];
if (autoReload > 0) {
reloadItems = [{
doAction: async () => setAutoReloadStopped(!autoReloadStopped),
label: autoReloadStopped ? labelAutoReloadStart : labelAutoReloadStop
}, ...reloadItems]
}
const defaultItems: WidgetMenuItem[] = [
{
Expand All @@ -52,7 +56,7 @@ export function createContextMenuFactory(
enabled: canGoForward(elWebview),
label: labelGoForward
},
reloadItem,
...reloadItems,
{
type: 'separator'
}, {
Expand All @@ -70,6 +74,13 @@ export function createContextMenuFactory(
}
]

const devItems: WidgetMenuItem[] = [
{
doAction: async () => openDevTools(elWebview),
label: labelDevTools
}
]

if (!contextData) {
items.push(...defaultItems);
} else if (isElectronContextMenuParams(contextData)) {
Expand Down Expand Up @@ -184,6 +195,11 @@ export function createContextMenuFactory(
}
}
}

if (items.length > 0) {
items.push({ type: 'separator' })
}
items.push(...devItems);
}

return items;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/widgets/webpage/icons/reload-start.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/renderer/widgets/webpage/icons/reload-stop.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3e1fa29

Please sign in to comment.