设置窗口当前文件路径,并且将这个文件的图标放在窗口标题栏上(只在mac系统下有效)
win.setRepresentedFilename(filename)
例子如下:
const {app,BrowserWindow} = require('electron');
function createWindow(){
win = new BrowserWindow({
show:false,
webPreferences: {
nodeIntegration: true
}
});
win.loadFile('index.html');
win.setRepresentedFilename('/Users/zhibo/Documents/test.zip');
win.on('ready-to-show',()=>{
win.show()
});
win.on('closed',()=>{
console.log('closed');
win = null;
});
}
app.allowRendererProcessReuse = true;
app.on('ready',createWindow);
app.on('window-all-closed',()=>{
console.log('window-all-closed');
if(process.platform != 'darwin'){
app.quit();
}
});
app.on('activate',()=>{
console.log('activate');
if(win == null) {
createWindow();
}
});
function createWindow(){
win = new BrowserWindow({
show:false,
webPreferences: {
nodeIntegration: true
}
});
win.loadFile('index.html');
win.setRepresentedFilename('/Users/zhibo/Documents/test.zip');
win.on('ready-to-show',()=>{
win.show()
});
win.on('closed',()=>{
console.log('closed');
win = null;
});
}
app.allowRendererProcessReuse = true;
app.on('ready',createWindow);
app.on('window-all-closed',()=>{
console.log('window-all-closed');
if(process.platform != 'darwin'){
app.quit();
}
});
app.on('activate',()=>{
console.log('activate');
if(win == null) {
createWindow();
}
});