3

所以我正在使用 Atom-shell 和 AngularJS 开发本机 OSX/Windows 应用程序。我正在尝试打开文件保存对话框。

Atom-shell 有一个“对话框”API:

https://github.com/atom/atom-shell/blob/master/docs/api/dialog.md

我可以从我的 atom-shell 设置 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 文件”按钮。当我尝试在我的 Angular 应用程序(app.js)中要求“对话”时,出现“找不到模块”错误。这是我的 AngularJS 应用 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');

我收到“找不到模块”错误,这是有道理的,因为它不是 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 文件,并且应该会弹出一个文件保存对话框。我尝试过使用“隐藏的输入元素,click()”方法,还尝试了“window.open(data...)”方法,该方法适用于 web 应用程序环境,但 Atom-shell 不喜欢它 - 只是打开一个空白的浏览器窗口。

想法?

4

2 回答 2

4

Ah, just discovered the remote module in atom-shell. D'oh!

https://github.com/atom/atom-shell/blob/master/docs/api/remote.md

于 2015-01-20T23:31:34.170 回答
0

我在 Mooers 上发现了同样的问题。我的解决方案是这段代码:

var remote = require('remote');
var dialog = remote.require('dialog');
于 2015-10-06T19:33:14.887 回答