Atom-shell + AngularJS - how to open a file save dialog?

Question!

So I'm developing a native OSX/Windows app using Atom-shell and AngularJS. I'm trying to open a file save dialog.

Atom-shell has a "dialog" API:

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

I can use this API from my atom-shell setup JS file (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;
  });
});

But that doesn't do me any good - it just opens a file dialog when I first run the app through Atom-shell. How do I access this dialog API from within my AngularJS app? I'm basically needing a "download CSV file" button. When I try to require 'dialog' in my angular app (app.js), I get "module not found" error. This is my 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>
        ...

When I try adding this line to app.js:

var dialog = require('dialog');

I get the "module not found" error, which makes sense because it's not a nodejs module, it's within Atom-shell. So how do I access those methods from within my AngularJS app?

Here's the download CSV button:

<button ng-click="downloadClientsCSV()" class="btn btn-primary"><i class="icon ion-android-download"></i>Download CSV</button>

And downloadClientsCSV() generates a csv file, and should pop open a file save dialog. I've tried using the "hidden input element, click()" method, and also tried the "window.open(data...)" method, which works in a web app environment, but Atom-shell doesn't like it - just opens a blank browser window.

Ideas?



Answers

I found the same problem with Mooers. My solution is this code:

var remote = require('remote');
var dialog = remote.require('dialog');
By : Simon


This video can help you solving your question :)
By: admin