@@ -2,12 +2,17 @@ import { Component } from '@angular/core';
|
|||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { ReplaySubject } from 'rxjs/ReplaySubject';
|
||||||
import 'rxjs/add/observable/of';
|
import 'rxjs/add/observable/of';
|
||||||
import 'rxjs/add/observable/throw';
|
import 'rxjs/add/observable/throw';
|
||||||
import 'rxjs/add/operator/distinctUntilChanged';
|
import 'rxjs/add/operator/distinctUntilChanged';
|
||||||
import 'rxjs/add/operator/ignoreElements';
|
import 'rxjs/add/operator/ignoreElements';
|
||||||
import 'rxjs/add/operator/takeWhile';
|
import 'rxjs/add/operator/takeWhile';
|
||||||
|
|
||||||
|
import { remote } from 'electron';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as sudo from 'sudo-prompt';
|
||||||
|
|
||||||
import { UhkDeviceService } from './../../services/uhk-device.service';
|
import { UhkDeviceService } from './../../services/uhk-device.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -27,13 +32,44 @@ export class PrivilegeCheckerComponent {
|
|||||||
router.navigate(['/detection']);
|
router.navigate(['/detection']);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPermissions(): Observable<boolean> {
|
setUpPermissions(): void {
|
||||||
return Observable.of(true);
|
let permissionSetter: Observable<void>;
|
||||||
|
switch (process.platform) {
|
||||||
|
case 'linux':
|
||||||
|
permissionSetter = this.setUpPermissionsOnLinux();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
permissionSetter = Observable.throw('Permissions couldn\'t be set. Invalid platform: ' + process.platform);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
permissionSetter.subscribe({
|
||||||
|
error: e => console.error(e),
|
||||||
|
complete: () => {
|
||||||
|
console.log('Permissions has been successfully set');
|
||||||
|
this.uhkDevice.initialize();
|
||||||
|
this.router.navigate(['/']);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setUpPermissions() { }
|
private setUpPermissionsOnLinux(): Observable<void> {
|
||||||
|
const subject = new ReplaySubject<void>();
|
||||||
|
const rootDir = path.resolve(path.join(remote.process.cwd(), remote.process.argv[1]), '..');
|
||||||
|
const scriptPath = path.resolve(rootDir, 'rules/setup-rules.sh');
|
||||||
|
const options = {
|
||||||
|
name: 'Setting UHK access rules'
|
||||||
|
};
|
||||||
|
sudo.exec(`sh ${scriptPath}`, options, (error: any) => {
|
||||||
|
if (error) {
|
||||||
|
subject.error(error);
|
||||||
|
} else {
|
||||||
|
subject.complete();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return subject.asObservable();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
declare module 'sudo-prompt';
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import './shared/vendor.ts';
|
||||||
|
|
||||||
|
import 'sudo-prompt';
|
||||||
@@ -10,7 +10,7 @@ var rootDir = path.resolve(__dirname, '../');
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
entry: {
|
entry: {
|
||||||
polyfills: path.resolve(rootDir, 'src/shared/polyfills.ts'),
|
polyfills: path.resolve(rootDir, 'src/shared/polyfills.ts'),
|
||||||
vendor: path.resolve(rootDir, 'src/shared/vendor.ts'),
|
vendor: path.resolve(rootDir, 'src/vendor.ts'),
|
||||||
app: path.resolve(rootDir, 'src/main.ts')
|
app: path.resolve(rootDir, 'src/main.ts')
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
@@ -75,6 +75,10 @@ module.exports = {
|
|||||||
from: 'images',
|
from: 'images',
|
||||||
to: 'images'
|
to: 'images'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
from: 'rules',
|
||||||
|
to: 'rules'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
from: 'node_modules/usb',
|
from: 'node_modules/usb',
|
||||||
to: 'vendor/usb'
|
to: 'vendor/usb'
|
||||||
|
|||||||
@@ -59,6 +59,7 @@
|
|||||||
"ng2-select2": "1.0.0-beta.10",
|
"ng2-select2": "1.0.0-beta.10",
|
||||||
"rxjs": "5.1.1",
|
"rxjs": "5.1.1",
|
||||||
"select2": "^4.0.3",
|
"select2": "^4.0.3",
|
||||||
|
"sudo-prompt": "^6.2.1",
|
||||||
"typescript": "2.1.6",
|
"typescript": "2.1.6",
|
||||||
"usb": "git+https://github.com/aktary/node-usb.git",
|
"usb": "git+https://github.com/aktary/node-usb.git",
|
||||||
"xml-loader": "^1.1.0",
|
"xml-loader": "^1.1.0",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# These are the udev rules for accessing the USB interfaces of the UHK as non-root users.
|
# These are the udev rules for accessing the USB interfaces of the UHK as non-root users.
|
||||||
# Copy this file to /etc/udev/rules.d and physically reconnect the UHK afterwards.
|
# Copy this file to /etc/udev/rules.d and physically reconnect the UHK afterwards.
|
||||||
# TODO: Restore VID to 16d0 for the latest prototype.
|
# TODO: Restore VID to 16d0 for the latest prototype.
|
||||||
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16d2", ATTRS{idProduct}=="05e[abcd]", MODE:="0666"
|
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16d3", ATTRS{idProduct}=="05e[abcd]", MODE:="0666"
|
||||||
KERNEL=="ttyACM*", ATTRS{idVendor}=="16d2", ATTRS{idProduct}=="05ec", MODE:="0666", SYMLINK+="uhk-right-bootloader"
|
KERNEL=="ttyACM*", ATTRS{idVendor}=="16d3", ATTRS{idProduct}=="05ec", MODE:="0666", SYMLINK+="uhk-right-bootloader"
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
cd $(dirname $0)
|
||||||
|
cp 50-uhk-write-access.rules /etc/udev/rules.d
|
||||||
|
udevadm trigger
|
||||||
|
udevadm settle
|
||||||
Reference in New Issue
Block a user