我试图学习如何使用Electron开发桌面应用程序。 我发现那个指南: http://www.toptal.com/javascript/electron-cross-platform-desktop-apps-easy
但很多事情都有所改变('icp'模块现已弃用,例如) 现在:
这是我的代码
app.js
var app = require('app'),
ipc = require('electron').ipcMain,
BrowserWindow = require('browser-window');
var mainWindow = null,
insertWindow = null;
function createInsertWindow() {
insertWindow = new BrowserWindow({
width: 640,
height: 480,
show: false
});
insertWindow.loadURL('file://' + __dirname + '/windows/insert/insert.html');
insertWindow.on('closed',function() {
insertWindow = null;
});
insertWindow.show();
}
app.on('ready', function() {
mainWindow = new BrowserWindow({
width: 1024,
height: 768
});
mainWindow.loadURL('file://' + __dirname + '/windows/main/main.html');
mainWindow.openDevTools();
ipc.on('toggle-insert-view', function() {
if(! insertWindow) {
createInsertWindow();
} else {
return ( insertWindow.isVisible() ) ? insertWindow.hide() : insertWindow.show();
}
});
});
main.html中
<!DOCTYPE html>
<html>
<head>
<script src="../../bower_components/angular/angular.min.js"></script>
<script src="./main.view.js"></script>
<meta charset="utf-8">
<title>Electron Desktop App</title>
</head>
<body>
<h1>EDA</h1>
<div ng-controller="MainCtrl as vm">
<button toggle-insert-view class="mdl-button">
add
</button>
</div>
</body>
</html>
main.view.js var ipcRenderer = require('electron')。ipcRenderer;
angular
.module('Utils', [])
.directive('toggleInsertView', function() {
return function(scope, el) {
el.bind('click', function(e) {
e.preventDefault();
ipcRenderer.send('toggle-insert-view');
});
};
});
当主窗口显示时,我点击“添加”按钮&amp;&amp;没什么变化。
答案 0 :(得分:0)
您应该将ipc.on('toggle-insert-view', function...)
移到app.on('ready', function...)