-
Notifications
You must be signed in to change notification settings - Fork 11
/
platformSpecific.js
132 lines (115 loc) · 4.65 KB
/
platformSpecific.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
'use strict';
var exec = require('child_process').exec;
var execSync = require('child_process').execSync;
var dbUpdateNotified = false;
module.exports = PlatformSpecific;
function PlatformSpecific(coreCommand) {
var self = this;
self.coreCommand = coreCommand;
}
PlatformSpecific.prototype.shutdown = function () {
var self = this;
execSync("/bin/sync", { uid: 1000, gid: 1000});
exec("/home/volumio/softshutdown.sh", function (error, stdout, stderr) {
if (error) {
self.coreCommand.pushConsoleMessage(error);
}
self.coreCommand.pushConsoleMessage('Shutting Down');
// Fallback in case above method does not work
setTimeout(function() {
execSync("/usr/bin/sudo /sbin/shutdown -h now", { uid: 1000, gid: 1000});
}, 3000)
});
};
PlatformSpecific.prototype.reboot = function () {
var self = this;
execSync("/bin/sync", { uid: 1000, gid: 1000});
exec("/home/volumio/softreboot.sh", function (error, stdout, stderr) {
if (error) {
self.coreCommand.pushConsoleMessage(error);
}
self.coreCommand.pushConsoleMessage('Rebooting');
// Fallback in case above method does not work
setTimeout(function() {
execSync("/usr/bin/sudo /sbin/reboot", { uid: 1000, gid: 1000});
}, 3000)
});
};
PlatformSpecific.prototype.networkRestart = function () {
var self = this;
exec("/usr/bin/sudo /bin/ip addr flush dev eth0 && /usr/bin/sudo /sbin/ifconfig eth0 down && /usr/bin/sudo /sbin/ifconfig eth0 up", function (error, stdout, stderr) {
if (error !== null) {
self.coreCommand.pushToastMessage('error',self.coreCommand.getI18nString('NETWORK.NETWORK_RESTART_TITLE'),
self.coreCommand.getI18nString('NETWORK.NETWORK_RESTART_ERROR')+error);
} else
self.coreCommand.pushToastMessage('success',self.coreCommand.getI18nString('NETWORK.NETWORK_RESTART_TITLE'),
self.coreCommand.getI18nString('NETWORK.NETWORK_RESTART_SUCCESS'));
// Restart Upmpdcli
setTimeout(function () {
self.coreCommand.executeOnPlugin('audio_interface', 'upnp', 'onRestart', '');
}, 10000);
});
};
PlatformSpecific.prototype.wirelessRestart = function () {
var self = this;
exec("sudo /bin/systemctl restart wireless.service", function (error, stdout, stderr) {
if (error !== null) {
self.coreCommand.pushToastMessage('error',self.coreCommand.getI18nString('NETWORK.WIRELESS_RESTART_TITLE'),
self.coreCommand.getI18nString('NETWORK.WIRELESS_RESTART_ERROR')+error);
} else {
self.coreCommand.pushToastMessage('success',self.coreCommand.getI18nString('NETWORK.WIRELESS_RESTART_TITLE'),
self.coreCommand.getI18nString('NETWORK.WIRELESS_RESTART_SUCCESS'));
setTimeout(function (){
self.coreCommand.executeOnPlugin('miscellanea', 'wizard', 'reportWirelessConnection', '');
}, 5000);
// Restart Upmpdcli
setTimeout(function () {
self.coreCommand.executeOnPlugin('audio_interface', 'upnp', 'onRestart', '');
}, 10000);
}
});
};
PlatformSpecific.prototype.startupSound = function () {
var self = this;
var outdev = self.coreCommand.sharedVars.get('alsa.outputdevice');
var startupSound = self.coreCommand.executeOnPlugin('system_controller', 'system', 'getConfigParam', 'startupSound');
if (startupSound){
var hwdev = '--device=plughw:' + outdev + ',0';
if (outdev === 'softvolume'){
hwdev = '-D softvolume';
}
exec('/usr/bin/aplay '+hwdev+' /volumio/app/startup.wav', function (error, stdout, stderr) {
if (error !== null) {
console.log(error);
}
self.coreCommand.closeModals();
setTimeout(function() {
self.coreCommand.executeOnPlugin('audio_interface', 'alsa_controller', 'checkAudioDeviceAvailable', '');
},1000)
});
}
}
PlatformSpecific.prototype.fileUpdate = function (data) {
var self = this;
self.coreCommand.pushConsoleMessage('Command Router : Notfying DB Update'+data);
if (data === true && !dbUpdateNotified) {
dbUpdateNotified = true;
var responseData = {
title: self.coreCommand.getI18nString('COMMON.SCAN_DB'),
message: self.coreCommand.getI18nString('COMMON.UPDATING_MUSIC_DB_WAIT_MESSAGE'),
size: 'lg',
buttons: [
{
name: self.coreCommand.getI18nString('COMMON.GOT_IT'),
class: 'btn btn-info ng-scope',
emit:'',
payload:''
}
]
}
self.coreCommand.broadcastMessage("openModal", responseData);
} else {
self.coreCommand.closeModals();
}
return self.coreCommand.broadcastMessage('dbUpdate', {'status':data});
}