所以我正在使用Atom-shell和AngularJS开发本机OSX / Windows应用程序。我试图打开文件保存对话框。
Atom-shell有一个"对话框" API:
https://github.com/atom/atom-shell/blob/master/docs/api/dialog.md
我可以在我的atom-shell setup JS文件(main.js)中使用这个API:
var app = require('app'); // Module to control application life.
var dialog = require('dialog');
var BrowserWindow = require('browser-window'); // Module to create native browser window.
// Report crashes to our server.
require('crash-reporter').start();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
});
// This method will be called when atom-shell has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 1200, height: 800});
// and load the index.html of the app.
mainWindow.loadUrl('file://' + __dirname + '/index.html');
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});
但这对我没什么好处 - 它只是在我第一次通过Atom-shell运行应用程序时打开一个文件对话框。如何从AngularJS应用程序中访问此对话框API?我基本上需要一个"下载CSV文件"按钮。当我试图要求对话时#39;在我的角度应用程序(app.js)中,我得到"模块未找到"错误。这是我的AngularJS app index.html:
<!DOCTYPE html>
<html ng-app="socialWorkerProApp">
<head>
<title>Social Worker Pro</title>
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-route/angular-route.js"></script>
<script src="node_modules/angular-sanitize/angular-sanitize.min.js"></script>
<script src="bower_components/angular-native-picker/build/angular-datepicker.js"></script>
<script src="js/app.js"></script>
...
当我尝试将此行添加到app.js时:
var dialog = require('dialog');
我找不到&#34;模块&#34;错误,这是有道理的,因为它不是nodejs模块,它在Atom-shell中。那么如何从我的AngularJS应用程序中访问这些方法呢?
这是下载CSV按钮:
<button ng-click="downloadClientsCSV()" class="btn btn-primary"><i class="icon ion-android-download"></i>Download CSV</button>
并且downloadClientsCSV()生成一个csv文件,并应弹出一个文件保存对话框。我尝试过使用&#34;隐藏的输入元素,点击()&#34;方法,并尝试了&#34; window.open(data ...)&#34;方法,在Web应用程序环境中工作,但Atom-shell不喜欢它 - 只需打开一个空白的浏览器窗口。
想法?
答案 0 :(得分:4)
啊,刚刚在atom-shell中发现了远程模块。 d&#39;!哦
https://github.com/atom/atom-shell/blob/master/docs/api/remote.md
答案 1 :(得分:0)
我发现Mooers存在同样的问题。 我的解决方案是这段代码:
var remote = require('remote');
var dialog = remote.require('dialog');