そこで、Atom-shell と AngularJS を使用してネイティブ OSX/Windows アプリを開発しています。ファイル保存ダイアログを開こうとしています。
Atom-shell には「ダイアログ」API があります。
https://github.com/atom/atom-shell/blob/master/docs/api/dialog.md
この API は、atom-shell セットアップ JS ファイル (main.js) から使用できます。
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()」メソッドを使用してみました。また、Web アプリ環境で動作する「window.open(data...)」メソッドも試しましたが、Atom-shell が気に入らないそれ - 空白のブラウザ ウィンドウを開くだけです。
アイデア?