Skip to content

Commit bc73712

Browse files
committed
Code refactoring app startup, angular http.get methods to latest version, user data/localstorage cleaning and closing
1 parent d716ee0 commit bc73712

File tree

14 files changed

+303
-375
lines changed

14 files changed

+303
-375
lines changed

app/index.html

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,14 @@
1919

2020
</head>
2121

22-
<script>
23-
// expose accessToken and clientId
24-
</script>
25-
2622
<body data-isVisible="false" ng-controller="AppCtrl">
2723

28-
<!-- loading gif -->
24+
<!-- loading -->
2925
<div class="box-loader loading">
30-
<h4>Authenticating your Soundcloud account.</h4>
31-
26+
<h4>Starting application.</h4>
3227
<div class="loader"></div>
3328
</div>
34-
<!-- loading gif / end -->
29+
<!-- loading / end -->
3530

3631
<!-- UI App -->
3732
<div id="app" class="ui_app" ng-class="{ songPlaying: isSongPlaying }">
@@ -220,10 +215,8 @@ <h4 id="playerUser" class="player_user" ng-click="goToUser($event)"></h4>
220215
<script>
221216
const srcPath = './public/js';
222217
require(`${srcPath}/system/settings`);
223-
require(`${srcPath}/system/authentication`);
224-
require(`${srcPath}/system/userConfig`);
225218
require(`${srcPath}/system/guiConfig`);
226-
require(`${srcPath}/system/core`);
219+
require(`${srcPath}/system/startup`);
227220
</script>
228221

229222
<script src="public/js/app.js"></script>

app/public/js/about/aboutCtrl.js

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,58 @@
11
'use strict';
22

33
app.controller('AboutCtrl', function (
4-
$scope,
5-
$http,
6-
$rootScope,
7-
ngDialog,
8-
$window
4+
$scope,
5+
$http,
6+
$rootScope,
7+
ngDialog,
8+
$window
99
) {
10-
var urlAbout = 'https://api.github.com/repos/Soundnode/soundnode-about/contents/about.html';
11-
var urlRelease = 'https://api.github.com/repos/Soundnode/soundnode-app/releases';
12-
var config = {
13-
headers: {
14-
'Accept': 'application/vnd.github.v3.raw+json'
15-
}
16-
};
10+
var urlAbout = 'https://api.github.com/repos/Soundnode/soundnode-about/contents/about.html';
11+
var urlRelease = 'https://api.github.com/repos/Soundnode/soundnode-app/releases';
12+
var config = {
13+
headers: {
14+
'Accept': 'application/vnd.github.v3.raw+json'
15+
}
16+
};
1717

18-
$scope.appVersion = $window.settings.appVersion;
19-
$scope.appLatestVersion = '';
20-
$scope.content = '';
21-
$scope.isLatest = ($scope.appVersion >= $scope.appLatestVersion);
18+
$scope.appVersion = $window.settings.appVersion;
19+
$scope.appLatestVersion = '';
20+
$scope.content = '';
21+
$scope.isLatest = ($scope.appVersion >= $scope.appLatestVersion);
2222

23-
$scope.openModal = function() {
24-
ngDialog.open({
25-
showClose: false,
26-
template: 'views/about/about.html',
27-
scope: $scope
28-
});
29-
};
23+
$scope.openModal = function () {
24+
ngDialog.open({
25+
showClose: false,
26+
template: 'views/about/about.html',
27+
scope: $scope
28+
});
29+
};
3030

31-
/**
32-
* Get Soundnode about.html from Github
33-
*/
34-
$http.get(urlAbout, config)
35-
.success(function (data) {
36-
$scope.content = data;
37-
})
38-
.error(function (error) {
39-
console.log('Error', error)
40-
});
31+
/**
32+
* Get Soundnode about.html from Github
33+
*/
34+
$http({
35+
method: 'GET',
36+
url: urlAbout,
37+
config: config
38+
}).then(function successCallback(response) {
39+
$scope.content = response;
40+
}, function errorCallback(error) {
41+
console.log('Error retrieving about', error)
42+
});
4143

42-
43-
/**
44-
* Get App version from latest release from Github
45-
*/
46-
$http.get(urlRelease, config)
47-
.success(function (data) {
48-
var release = data[0];
49-
$scope.appLatestVersion = release.tag_name;
50-
})
51-
.error(function (error) {
52-
console.log('Error on getting latest release', error);
53-
});
44+
/**
45+
* Get App version from latest release from Github
46+
*/
47+
$http({
48+
method: 'GET',
49+
url: urlRelease,
50+
config: config
51+
}).then(function successCallback(response) {
52+
var release = response[0];
53+
$scope.appLatestVersion = release.tag_name;
54+
}, function errorCallback(error) {
55+
console.log('Error retrieving latest release', error);
56+
});
5457

5558
});

app/public/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const guiConfig = require('../../system/guiConfig').guiConfig;
3+
const guiConfig = require(`${__dirname}/public/js/system/guiConfig.js`).guiConfig;
44

55
var app = angular.module('App', [
66
'ui.router',

app/public/js/settings/settingsCtrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ app.controller('SettingsCtrl', function ($scope, notificationFactory) {
2121
*/
2222
$scope.cleanStorage = function() {
2323
window.localStorage.clear();
24-
notificationFactory.success('Your local storage is clean.');
24+
guiConfig.logOut();
2525
}
2626

2727
});

app/public/js/system/authentication.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

app/public/js/system/core.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/public/js/system/guiConfig.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const {
44
ipcRenderer
55
} = require('electron');
6+
const fs = require('fs-extra');
67

78
let guiConfig = {};
89

@@ -11,6 +12,11 @@ guiConfig.close = function () {
1112
ipcRenderer.send('closeApp');
1213
};
1314

15+
// quit hard
16+
guiConfig.destroy = function () {
17+
ipcRenderer.send('destroyApp');
18+
};
19+
1420
// minimize the App
1521
guiConfig.minimize = function () {
1622
ipcRenderer.send('minimizeApp');
@@ -21,6 +27,11 @@ guiConfig.maximize = function () {
2127
ipcRenderer.send('maximizeApp');
2228
};
2329

30+
guiConfig.logOut = function () {
31+
fs.removeSync(`${__dirname}/userConfig.json`);
32+
this.destroy();
33+
};
34+
2435
module.exports = {
2536
guiConfig: guiConfig
2637
}

app/public/js/system/settings.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"use strict";
22

33
const ua = require('universal-analytics');
4+
const fs = require('fs');
5+
const userConfig = JSON.parse(fs.readFileSync(`${__dirname}/userConfig.json`, 'utf-8'));
46

57
// Set up some core settings
68
window.settings = {};
@@ -9,4 +11,10 @@ window.settings = {};
911
window.settings.appVersion = '0.6.5';
1012

1113
// GA >> DO NOT CHANGE OR USE THIS CODE <<
12-
window.settings.visitor = ua('UA-67310953-1');
14+
window.settings.visitor = ua('UA-67310953-1');
15+
16+
// set window access token
17+
window.scAccessToken = userConfig.accessToken;
18+
19+
// set window clientId
20+
window.scClientId = userConfig.clientId;

app/public/js/system/startup.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
3+
function startApp() {
4+
setTimeout(function () {
5+
angular.bootstrap(document, ['App']);
6+
document.body.setAttribute('data-isVisible', 'true');
7+
}, 2000);
8+
}
9+
10+
startApp();

app/public/js/system/userConfig.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)