Skip to content

Commit

Permalink
Desktop version working on linux using electron
Browse files Browse the repository at this point in the history
  • Loading branch information
renatopp committed Nov 1, 2015
1 parent da0707e commit 99e1eef
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 30 deletions.
76 changes: 48 additions & 28 deletions src/app/services/dialog.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ angular
.module('app')
.factory('dialogService', dialogService);

dialogService.$inject = ['$window', '$q', '$document'];
dialogService.$inject = ['$window', '$q', '$document', 'nodejsService'];

function dialogService($window, $q, $document) {
function dialogService($window, $q, $document, nodejsService) {
var service = {
alert : alert,
confirm : confirm,
Expand Down Expand Up @@ -71,37 +71,57 @@ function dialogService($window, $q, $document) {
});
}
function saveAs(placeholder, types) {
var dialog = $document[0].createElement('input');
dialog.type = 'file';
dialog.nwsaveas = placeholder || '';
if (angular.isArray(types)) {
dialog.accept = types.join(',');
} else if (angular.isString(types)) {
dialog.accept = types;
}

return _callFileDialog(dialog);
return $q(function(resolve, reject) {
var value = nodejsService.dialog.showSaveDialog({
title: 'Save project as...',
defaultPath: placeholder + '.b3',
filters : [
{name: 'Behavior3 File', extensions: ['b3', 'json']},
{name: 'All Files', extensions: ['*']}
]
});
if (value) {
resolve(value);
} else {
reject();
}
});
}
function openFile(multiple, types) {
var dialog = $document[0].createElement('input');
dialog.type = 'file';
if (multiple) {
dialog.multiple = 'multiple';
}

if (angular.isArray(types)) {
dialog.accept = types.join(',');
} else if (angular.isString(types)) {
dialog.accept = types;
}
return $q(function(resolve, reject) {
var value = nodejsService.dialog.showOpenDialog({
title: 'Open file...',
multiSelections: multiple,
properties: ['openFile'],
filters : [
{name: 'Behavior3 File', extensions: ['b3', 'json']},
{name: 'All Files', extensions: ['*']}
]
});

return _callFileDialog(dialog);
if (value) {
if (!multiple) {
value = value[0];
}
console.log(value);
resolve(value);
} else {
reject();
}
});
}
function openDirectory() {
var dialog = $document[0].createElement('input');
dialog.type = 'file';
dialog.nwdirectory = 'nwdirectory';
return _callFileDialog(dialog);
return $q(function(resolve, reject) {
var value = nodejsService.dialog.showOpenDialog({
title: 'Open directory...',
properties: ['openDirectory']
});
if (value) {
resolve(value);
} else {
reject();
}
});
}

}
2 changes: 2 additions & 0 deletions src/app/services/nodejs.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ nodejsService.$inject = ['$window'];

function nodejsService($window) {
var ok = !!$window.require;
var remote = (ok?$window.require('remote'):null);
var service = {
ok : ok,
fs : (ok?$window.require('fs'):null),
path : (ok?$window.require('path'):null),
dialog : (ok?remote.require('dialog'):null),
};
return service;

Expand Down
8 changes: 7 additions & 1 deletion src/app/services/system.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ function systemService($window, nodejsService) {
}
function getDataPath() {
if (isDesktop) {
var path = join(process.env.APPDATA, 'b3editor');
var datapath = process.env.APPDATA;
if (!datapath) {
datapath = process.env.HOME + '/.behavior3';
}

var path = join(datapath, 'b3editor');
_createIfNonExist(datapath);
_createIfNonExist(path);
return path;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ app.on('ready', function() {
mainWindow.loadUrl('file://' + __dirname + '/index.html');

// Open the DevTools.
// mainWindow.openDevTools();
mainWindow.openDevTools();

// Emitted when the window is closed.
mainWindow.on('closed', function() {
Expand Down

0 comments on commit 99e1eef

Please sign in to comment.