我正在尝试学习如何使用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变量ipcRenderer =需要(‘电子’).ipcRenderer;
angular
.module('Utils', [])
.directive('toggleInsertView', function() {
return function(scope, el) {
el.bind('click', function(e) {
e.preventDefault();
ipcRenderer.send('toggle-insert-view');
});
};
});当主窗口出现时,我点击“添加”按钮&&没有任何变化。
发布于 2016-04-14 17:29:53
您应该将ipc.on('toggle-insert-view', function...)移到app.on('ready', function...)之外
https://stackoverflow.com/questions/34948153
复制相似问题