Skip to content

Commit

Permalink
Merge pull request #2773 from cmgustavo/feat/copay-desktop
Browse files Browse the repository at this point in the history
Feat/copay desktop
  • Loading branch information
matiu committed May 28, 2015
2 parents b1da581 + 56699a2 commit decca68
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 81 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ src/js/version.js
cordova/project/*
cordova/*.keystore

# node-webkit
cache
webkitbuilds/*
!webkitbuilds/README.md

# chrome extensions
browser-extensions/chrome/copay-chrome-extension
browser-extensions/chrome/copay-chrome-extension.zip
Expand Down
13 changes: 12 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ module.exports = function(grunt) {
force: true,
recursive: false
}
},
nodewebkit: {
options: {
platforms: ['win','osx','linux'],
buildDir: './webkitbuilds',
version: '0.12.2',
macIcns: './public/img/icons/icon.icns',
exeIco: './public/img/icons/icon.ico'
},
src: ['./package.json', './public/**/*']
}
});

Expand All @@ -197,7 +207,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-karma-coveralls');

grunt.loadNpmTasks('grunt-node-webkit-builder');

grunt.registerTask('default', [
'nggettext_compile', 'exec:version', 'concat', 'copy'
Expand All @@ -208,4 +218,5 @@ module.exports = function(grunt) {
grunt.registerTask('translate', ['nggettext_extract']);
grunt.registerTask('test', ['karma:unit']);
grunt.registerTask('test-coveralls', ['karma:prod', 'coveralls']);
grunt.registerTask('desktop', ['prod', 'nodewebkit']);
};
67 changes: 0 additions & 67 deletions atom-shell.md

This file was deleted.

3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"foundation": "zurb/bower-foundation#~5.5.1",
"foundation-icon-fonts": "*",
"ng-lodash": "~0.2.0",
"angular-moment": "~0.9.0",
"angular-moment": "~0.10.1",
"moment": "~2.10.3",
"angular-bitcore-wallet-client": "^0.0.23",
"angular-ui-router": "~0.2.13",
"qrcode-decoder-js": "*",
Expand Down
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,23 @@
"bitcoin",
"bitcore"
],
"main": "app.js",
"main": "public/index.html",
"window": {
"toolbar": false,
"show": true,
"visible": true,
"resizable": false,
"frame": true,
"width": 400,
"height": 600,
"position": "center",
"fullscreen": false
},
"webkit": {
"page-cache": false,
"java": false,
"plugin": false
},
"id": "jid1-x7bV5evAaI1P9Q",
"homepage": "https://github.com/bitpay/copay",
"license": "MIT",
Expand Down Expand Up @@ -45,6 +61,7 @@
"angular-mocks": "^1.3.14",
"grunt-karma": "^0.10.1",
"grunt-karma-coveralls": "^2.5.3",
"grunt-node-webkit-builder": "^1.0.2",
"karma": "^0.12.31",
"karma-cli": "0.0.4",
"karma-coverage": "^0.2.7",
Expand Down
Binary file added public/img/icons/icon.icns
Binary file not shown.
Binary file added public/img/icons/icon.ico
Binary file not shown.
4 changes: 3 additions & 1 deletion src/js/controllers/walletHome.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog) {
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit) {

var self = this;
$rootScope.hideMenuBar = false;
Expand Down Expand Up @@ -381,6 +381,8 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
if (isCordova) {
window.cordova.plugins.clipboard.copy('bitcoin:' + addr);
window.plugins.toast.showShortCenter('Copied to clipboard');
} else if (nodeWebkit.isDefined()) {
nodeWebkit.writeToClipboard(addr);
}
};

Expand Down
14 changes: 13 additions & 1 deletion src/js/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ angular
needProfile: false
});
})
.run(function($rootScope, $state, $log, gettextCatalog, uriHandler, isCordova, amMoment, profileService, $timeout) {
.run(function($rootScope, $state, $log, gettextCatalog, uriHandler, isCordova, amMoment, profileService, $timeout, nodeWebkit) {
FastClick.attach(document.body);

// Auto-detect browser language
Expand All @@ -396,6 +396,18 @@ angular
uriHandler.register();
}

if (nodeWebkit.isDefined()) {
var gui = require('nw.gui');
var win = gui.Window.get();
var nativeMenuBar = new gui.Menu({ type: "menubar" });
try {
nativeMenuBar.createMacBuiltin("Copay");
} catch(e) {
$log.debug('This is not OSX');
}
win.menu = nativeMenuBar;
}

var pageWeight = {
walletHome: 0,
copayers: -1,
Expand Down
9 changes: 7 additions & 2 deletions src/js/services/go.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

angular.module('copayApp.services').factory('go', function($window, $rootScope, $location, $state, profileService) {
angular.module('copayApp.services').factory('go', function($window, $rootScope, $location, $state, profileService, nodeWebkit) {
var root = {};

var hideSidebars = function() {
Expand Down Expand Up @@ -30,7 +30,12 @@ angular.module('copayApp.services').factory('go', function($window, $rootScope,
};

root.openExternalLink = function(url) {
var ref = window.open(url, '_blank', 'location=no');
if (nodeWebkit.isDefined()) {
nodeWebkit.openExternalLink(url);
}
else {
var ref = window.open(url, '_blank', 'location=no');
}
};

root.path = function(path, cb) {
Expand Down
10 changes: 5 additions & 5 deletions src/js/services/localStorage.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

angular.module('copayApp.services')
.factory('localStorageService', function(isChromeApp, $timeout) {
.factory('localStorageService', function(isChromeApp, nodeWebkit, $timeout) {
var root = {};
var ls = ((typeof window.localStorage !== "undefined") ? window.localStorage : null);

if (isChromeApp && !ls) {
if (isChromeApp && !nodeWebkit.isDefined() && !ls) {
ls = localStorage = chrome.storage.local;
window.localStorage = chrome.storage.local;
}
Expand All @@ -14,7 +14,7 @@ angular.module('copayApp.services')
throw new Error('localstorage not available');

root.get = function(k, cb) {
if (isChromeApp) {
if (isChromeApp && !nodeWebkit.isDefined()) {
chrome.storage.local.get(k,
function(data) {
//TODO check for errors
Expand All @@ -40,7 +40,7 @@ angular.module('copayApp.services')
};

root.set = function(k, v, cb) {
if (isChromeApp) {
if (isChromeApp && !nodeWebkit.isDefined()) {
var obj = {};
obj[k] = v;

Expand All @@ -53,7 +53,7 @@ angular.module('copayApp.services')
};

root.remove = function(k, cb) {
if (isChromeApp) {
if (isChromeApp && !nodeWebkit.isDefined()) {
chrome.storage.local.remove(k, cb);
} else {
ls.removeItem(k);
Expand Down
4 changes: 2 additions & 2 deletions src/js/services/logHeader.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
angular.module('copayApp.services')
.factory('logHeader', function($log, isChromeApp, isCordova) {
.factory('logHeader', function($log, isChromeApp, isCordova, nodeWebkit) {
$log.info('Starting Copay v' + window.version + ' #' + window.commitHash);
$log.info('Client: isCordova:', isCordova, 'isChromeApp:', isChromeApp);
$log.info('Client: isCordova:', isCordova, 'isChromeApp:', isChromeApp, 'isNodeWebkit:', nodeWebkit.isDefined());
$log.info('Navigator:', navigator.userAgent);
return {};
});
42 changes: 42 additions & 0 deletions src/js/services/nodeWebkit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

angular.module('copayApp.services').factory('nodeWebkit', function nodeWebkitFactory() {
var root = {};

var isNodeWebkit = function() {
var isNode = (typeof process !== "undefined" && typeof require !== "undefined");
if(isNode) {
try {
return (typeof require('nw.gui') !== "undefined");
} catch(e) {
return false;
}
}
};

root.isDefined = function() {
return isNodeWebkit();
};

root.readFromClipboard = function() {
if (!isNodeWebkit()) return;
var gui = require('nw.gui');
var clipboard = gui.Clipboard.get();
return clipboard.get();
};

root.writeToClipboard = function(text) {
if (!isNodeWebkit()) return;
var gui = require('nw.gui');
var clipboard = gui.Clipboard.get();
return clipboard.set(text);
};

root.openExternalLink = function(url) {
if (!isNodeWebkit()) return;
var gui = require('nw.gui');
return gui.Shell.openExternal(url);
};

return root;
});
14 changes: 14 additions & 0 deletions webkitbuilds/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copay NW.js

NW.js (also know as node-webkit) is an app runtime based on `Chromium` and `node.js`. To build desktop native application, Copay uses NW.js.

## Building Copay for OSX, Linux and Windows versions

**Requirements**

- Install NW.js in your system from [nw.js](http://nwjs.io/)

**Builder**

- Try `grunt desktop` (*)

0 comments on commit decca68

Please sign in to comment.