How to access atom-shell APIs within AngularJS? (For opening a file save dialog)


#1

I posted this question on StackOverflow, just wondering if anyone here has any ideas/feedback about how to access atom-shell APIs (like ‘dialog’) from within an AngularJS app:

Thanks,
Devin


#2

Oh, just found the remote module, d’oh!


#3

Hi @dkmooers Can you outline how you went about setting up the save to CSV functionality using the remote module? Did you open a new BrowserWindow and update it’s contents to be something like encodeURI('data:text/csv;charset=utf-8' + CSVString); ?


#4

Sure!

// app.js

var fs = require('fs');
var csv = require('csv');
var remote = require('remote');


// CSV download code, after you've built the csv as a string

remote.require('dialog').showSaveDialog( { 
	title:'Export Clients Spreadsheet',
	filters: [
		{ name: 'Spreadsheet', extensions: ['csv'] },
	]
}, function(filePathAndName) {
	fs.writeFile(filePathAndName, csv, function(err) {
		if (!err) {
			alert('Clients spreadsheet exported successfully!');
		}
	});
});

#5

Perfect, thank you!


#6

@joshcarr Yeah definitely!