电子不使用更新的CSS文件 [英] Electron not using updated css file

查看:66
本文介绍了电子不使用更新的CSS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用电子制作应用程序。到现在为止,我已经能够加载我的CSS文件(更新版本)。但是突然我发现,如果我对css文件进行任何更改,这些更改将不再反映在电子中。万一我曾经在Chrome浏览器中运行相同的东西时发生了类似的事情,但是我通过清除缓存使它起作用。
我认为清除电子缓存可能也对我有帮助,但我不知道该怎么办。
我从某处获得了这段代码,但是我不知道如何使用它:(

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 .

已更新:

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();
});


推荐答案

从文档站点开始:

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

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

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

因此,以下函数将返回您拥有的窗口并将其保存在win变量中。

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.
}

您将清除当前窗口中的缓存。如果您之前将窗口的值存储在某个变量中,您不需要使用 getCurrentWindow()函数

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

这篇关于电子不使用更新的CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆