Electron not using updated css file

久未见 提交于 2020-03-06 04:06:44

问题


I am using electron for making an app . Till Now I was able to load my css file (updated version) . But suddenly I have found that if I make any change in my css file , the changes are no longer reflected in electron . Similar thing was happening in case wjen I used to run same thing in Chrome browser but I got it working by clearing cache . I think clearing cache in electron might help me as well but I dont know how can I do that . I got this piece of code from somewhere , but I dont know how to use this :(

var remote = require('remote'); 
var win = remote.getCurrentWindow();
win.webContents.session.clearCache(function(){
//some callback.
}

Can some one guide me on how can I rectify my problem .

UPDATED :

const electron = require('electron');
const app = electron.app;  
const BrowserWindow = electron.BrowserWindow;  
var mainWindow = null;

app.on('window-all-closed', function() {
app.quit();
 });


 app.on('ready', function() {
 var subpy = require('child_process').spawn('python', ['./index.py']);

 var rq = require('request-promise');
 var mainAddr = 'http://localhost:5000';

var openWindow = function(){
mainWindow = new BrowserWindow({width:1200, height: 700});

mainWindow.loadURL('http://localhost:5000');
mainWindow.webContents.openDevTools();
mainWindow.on('closed', function() {
  mainWindow = null;
  subpy.kill('SIGINT');
  });
};

var startUp = function(){
rq(mainAddr)
  .then(function(htmlString){
    console.log('server started!');
    openWindow();
  })
  .catch(function(err){
    startUp();
  });
 };

startUp();
});

回答1:


From the documentation site:

const {BrowserWindow} = require('electron');

let win = new BrowserWindow({width: 800, height: 600});
win.loadURL('http://github.com');

const ses = win.webContents.session.clearCache(function() {
});

So, the following function will return the window you have and save it on the win variable.

var remote = require('remote'); 
var win = remote.getCurrentWindow();

And then, using the same function that you have like on the doc site:

win.webContents.session.clearCache(function(){
//some callback.
}

You will clean the cache from the current window you have. If you have stored the value of your windows before on some variable, you don't need to get it with the "getCurrentWindow() function



来源:https://stackoverflow.com/questions/37691304/electron-not-using-updated-css-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!