Merge pull request #122 from manojVivek/reload-css

shortcut to reload css only
This commit is contained in:
Manoj Vivek 2020-05-27 15:23:20 +05:30 committed by GitHub
commit 0072e86322
5 changed files with 43 additions and 2 deletions

View file

@ -10,7 +10,8 @@ import {
SCREENSHOT_ALL_DEVICES,
FLIP_ORIENTATION_ALL_DEVICES,
ENABLE_INSPECTOR_ALL_DEVICES,
DELETE_STORAGE,
RELOAD_CSS,
DELETE_STORAGE
} from '../constants/pubsubEvents';
export const NEW_ADDRESS = 'NEW_ADDRESS';
@ -387,3 +388,9 @@ export function deleteStorage() {
]);
};
}
export function reloadCSS() {
return (dispatch: Dispatch, getState: RootStateType) => {
pubsub.publish(RELOAD_CSS);
};
}

View file

@ -15,6 +15,7 @@ class NavigationControls extends Component {
componentDidMount() {
ipcRenderer.on('reload-url', this.props.triggerNavigationReload);
ipcRenderer.on('reload-css', this.props.reloadCSS);
}
render() {

View file

@ -17,7 +17,8 @@ import {
FLIP_ORIENTATION_ALL_DEVICES,
ENABLE_INSPECTOR_ALL_DEVICES,
DISABLE_INSPECTOR_ALL_DEVICES,
DELETE_STORAGE,
RELOAD_CSS,
DELETE_STORAGE
} from '../../constants/pubsubEvents';
import {CAPABILITIES} from '../../constants/devices';
@ -79,6 +80,9 @@ class WebView extends Component {
this.subscriptions.push(
pubsub.subscribe(NAVIGATION_RELOAD, this.processNavigationReloadEvent)
);
this.subscriptions.push(
pubsub.subscribe(RELOAD_CSS, this.processReloadCSSEvent)
);
this.subscriptions.push(
pubsub.subscribe(DELETE_STORAGE, this.processDeleteStorageEvent)
);
@ -219,6 +223,20 @@ class WebView extends Component {
this.webviewRef.current.reload();
};
processReloadCSSEvent = () => {
this.webviewRef.current.executeJavaScript(`
var elements = document.querySelectorAll('link[rel=stylesheet][href]');
elements.forEach(element=>{
var href = element.href;
if(href){
var href = href.replace(/[?&]invalidateCacheParam=([^&$]*)/,'');
element.href = href + (href.indexOf('?')>=0?'&':'?') + 'invalidateCacheParam=' + (new Date().valueOf());
}
})
`);
}
processDeleteStorageEvent = ({storages}) => {
this.getWebContents().session.clearStorageData({storages});
};

View file

@ -3,6 +3,7 @@ export const SCROLL_UP = 'SCROLL_UP';
export const NAVIGATION_BACK = 'NAVIGATION_BACK';
export const NAVIGATION_FORWARD = 'NAVIGATION_FORWARD';
export const NAVIGATION_RELOAD = 'NAVIGATION_RELOAD';
export const RELOAD_CSS = 'RELOAD_CSS';
export const DELETE_STORAGE = 'DELETE_STORAGE';
export const SCREENSHOT_ALL_DEVICES = 'SCREENSHOT_ALL_DEVICES';
export const FLIP_ORIENTATION_ALL_DEVICES = 'FLIP_ORIENTATION_ALL_DEVICES';

View file

@ -257,6 +257,13 @@ export default class MenuBuilder {
this.mainWindow.webContents.reload();
},
},
{
label: '&ReloadCSS',
accelerator: 'Alt+R',
click: () => {
this.mainWindow.webContents.send('reload-css');
}
},
{
label: 'Reload Ignoring Cache',
accelerator: 'CommandOrControl+Shift+R',
@ -291,6 +298,13 @@ export default class MenuBuilder {
this.mainWindow.webContents.send('reload-url');
},
},
{
label: '&ReloadCSS',
accelerator: 'Alt+R',
click: () => {
this.mainWindow.webContents.send('reload-css');
}
},
{
label: 'Reload Ignoring Cache',
accelerator: 'CommandOrControl+Shift+R',