fix(device): check privilege on Linux (#519)
* fix(device): check privilege on Linux * device connected if also have permission * fix rules sh path * refactor permission detection * fic hasPermission condition * fix return value
This commit is contained in:
committed by
László Monda
parent
969c36561b
commit
c11658f1fc
@@ -1,7 +1,7 @@
|
||||
import { Injectable, NgZone } from '@angular/core';
|
||||
import { Action, Store } from '@ngrx/store';
|
||||
|
||||
import { IpcEvents, IpcResponse, LogService } from 'uhk-common';
|
||||
import { DeviceConnectionState, IpcEvents, IpcResponse, LogService } from 'uhk-common';
|
||||
import { AppState } from '../store';
|
||||
import { IpcCommonRenderer } from './ipc-common-renderer';
|
||||
import {
|
||||
@@ -47,7 +47,7 @@ export class DeviceRendererService {
|
||||
}
|
||||
|
||||
private registerEvents(): void {
|
||||
this.ipcRenderer.on(IpcEvents.device.deviceConnectionStateChanged, (event: string, arg: boolean) => {
|
||||
this.ipcRenderer.on(IpcEvents.device.deviceConnectionStateChanged, (event: string, arg: DeviceConnectionState) => {
|
||||
this.dispachStoreAction(new ConnectionStateChangedAction(arg));
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Action } from '@ngrx/store';
|
||||
import { IpcResponse, type } from 'uhk-common';
|
||||
import { DeviceConnectionState, IpcResponse, type } from 'uhk-common';
|
||||
|
||||
const PREFIX = '[device] ';
|
||||
|
||||
@@ -8,7 +8,6 @@ export const ActionTypes = {
|
||||
SET_PRIVILEGE_ON_LINUX: type(PREFIX + 'set privilege on linux'),
|
||||
SET_PRIVILEGE_ON_LINUX_REPLY: type(PREFIX + 'set privilege on linux reply'),
|
||||
CONNECTION_STATE_CHANGED: type(PREFIX + 'connection state changed'),
|
||||
PERMISSION_STATE_CHANGED: type(PREFIX + 'permission state changed'),
|
||||
SAVE_CONFIGURATION: type(PREFIX + 'save configuration'),
|
||||
SAVE_CONFIGURATION_REPLY: type(PREFIX + 'save configuration reply'),
|
||||
SAVING_CONFIGURATION: type(PREFIX + 'saving configuration'),
|
||||
@@ -39,14 +38,7 @@ export class SetPrivilegeOnLinuxReplyAction implements Action {
|
||||
export class ConnectionStateChangedAction implements Action {
|
||||
type = ActionTypes.CONNECTION_STATE_CHANGED;
|
||||
|
||||
constructor(public payload: boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
export class PermissionStateChangedAction implements Action {
|
||||
type = ActionTypes.PERMISSION_STATE_CHANGED;
|
||||
|
||||
constructor(public payload: boolean) {
|
||||
constructor(public payload: DeviceConnectionState) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +113,6 @@ export type Actions
|
||||
= SetPrivilegeOnLinuxAction
|
||||
| SetPrivilegeOnLinuxReplyAction
|
||||
| ConnectionStateChangedAction
|
||||
| PermissionStateChangedAction
|
||||
| ShowSaveToKeyboardButtonAction
|
||||
| SaveConfigurationAction
|
||||
| SaveConfigurationReplyAction
|
||||
|
||||
@@ -26,7 +26,6 @@ import { AppUpdateRendererService } from '../../services/app-update-renderer.ser
|
||||
import {
|
||||
ActionTypes as DeviceActions,
|
||||
ConnectionStateChangedAction,
|
||||
PermissionStateChangedAction,
|
||||
SaveToKeyboardSuccessAction
|
||||
} from '../actions/device';
|
||||
import { AppState, autoWriteUserConfiguration } from '../index';
|
||||
@@ -64,8 +63,10 @@ export class ApplicationEffects {
|
||||
this.logService.debug('[AppEffect][processStartInfo] payload:', appInfo);
|
||||
return [
|
||||
new ApplyCommandLineArgsAction(appInfo.commandLineArgs),
|
||||
new ConnectionStateChangedAction(appInfo.deviceConnected),
|
||||
new PermissionStateChangedAction(appInfo.hasPermission),
|
||||
new ConnectionStateChangedAction({
|
||||
connected: appInfo.deviceConnected,
|
||||
hasPermission: appInfo.hasPermission
|
||||
}),
|
||||
new UpdateAgentVersionInformationAction(appInfo.agentVersionInfo)
|
||||
];
|
||||
});
|
||||
|
||||
@@ -13,12 +13,11 @@ import 'rxjs/add/operator/mergeMap';
|
||||
import 'rxjs/add/operator/withLatestFrom';
|
||||
import 'rxjs/add/operator/switchMap';
|
||||
|
||||
import { IpcResponse, NotificationType, UhkBuffer, UserConfiguration } from 'uhk-common';
|
||||
import { DeviceConnectionState, IpcResponse, NotificationType, UhkBuffer, UserConfiguration } from 'uhk-common';
|
||||
import {
|
||||
ActionTypes,
|
||||
ConnectionStateChangedAction,
|
||||
HideSaveToKeyboardButton,
|
||||
PermissionStateChangedAction,
|
||||
SaveConfigurationAction,
|
||||
SaveConfigurationReplyAction,
|
||||
SaveToKeyboardSuccessAction,
|
||||
@@ -47,35 +46,25 @@ export class DeviceEffects {
|
||||
deviceConnectionStateChange$: Observable<Action> = this.actions$
|
||||
.ofType<ConnectionStateChangedAction>(ActionTypes.CONNECTION_STATE_CHANGED)
|
||||
.map(action => action.payload)
|
||||
.do((connected: boolean) => {
|
||||
if (connected) {
|
||||
.do((state: DeviceConnectionState) => {
|
||||
if (!state.hasPermission) {
|
||||
this.router.navigate(['/privilege']);
|
||||
}
|
||||
else if (state.connected) {
|
||||
this.router.navigate(['/']);
|
||||
}
|
||||
else {
|
||||
this.router.navigate(['/detection']);
|
||||
}
|
||||
})
|
||||
.switchMap((connected: boolean) => {
|
||||
if (connected) {
|
||||
.switchMap((state: DeviceConnectionState) => {
|
||||
if (state.connected && state.hasPermission) {
|
||||
return Observable.of(new LoadConfigFromDeviceAction());
|
||||
}
|
||||
|
||||
return Observable.empty();
|
||||
});
|
||||
|
||||
@Effect({dispatch: false})
|
||||
permissionStateChange$: Observable<boolean> = this.actions$
|
||||
.ofType<PermissionStateChangedAction>(ActionTypes.PERMISSION_STATE_CHANGED)
|
||||
.map(action => action.payload)
|
||||
.do((hasPermission: boolean) => {
|
||||
if (hasPermission) {
|
||||
this.router.navigate(['/detection']);
|
||||
}
|
||||
else {
|
||||
this.router.navigate(['/privilege']);
|
||||
}
|
||||
});
|
||||
|
||||
@Effect({dispatch: false})
|
||||
setPrivilegeOnLinux$: Observable<Action> = this.actions$
|
||||
.ofType(ActionTypes.SET_PRIVILEGE_ON_LINUX)
|
||||
@@ -90,8 +79,10 @@ export class DeviceEffects {
|
||||
.mergeMap((response: any) => {
|
||||
if (response.success) {
|
||||
return [
|
||||
new ConnectionStateChangedAction(true),
|
||||
new PermissionStateChangedAction(true)
|
||||
new ConnectionStateChangedAction({
|
||||
connected: true,
|
||||
hasPermission: true
|
||||
})
|
||||
];
|
||||
}
|
||||
return [
|
||||
|
||||
@@ -3,8 +3,8 @@ import { Action } from '@ngrx/store';
|
||||
import {
|
||||
ActionTypes,
|
||||
ConnectionStateChangedAction,
|
||||
PermissionStateChangedAction,
|
||||
SaveConfigurationAction, UpdateFirmwareFailedAction
|
||||
SaveConfigurationAction,
|
||||
UpdateFirmwareFailedAction
|
||||
} from '../actions/device';
|
||||
import { ActionTypes as AppActions, ElectronMainLogReceivedAction } from '../actions/app';
|
||||
import { initProgressButtonState, ProgressButtonState } from './progress-button-state';
|
||||
@@ -30,17 +30,14 @@ export const initialState: State = {
|
||||
|
||||
export function reducer(state = initialState, action: Action) {
|
||||
switch (action.type) {
|
||||
case ActionTypes.CONNECTION_STATE_CHANGED:
|
||||
case ActionTypes.CONNECTION_STATE_CHANGED: {
|
||||
const data = (<ConnectionStateChangedAction>action).payload;
|
||||
return {
|
||||
...state,
|
||||
connected: (<ConnectionStateChangedAction>action).payload
|
||||
};
|
||||
|
||||
case ActionTypes.PERMISSION_STATE_CHANGED:
|
||||
return {
|
||||
...state,
|
||||
hasPermission: (<PermissionStateChangedAction>action).payload
|
||||
connected: data.connected,
|
||||
hasPermission: data.hasPermission
|
||||
};
|
||||
}
|
||||
|
||||
case ActionTypes.SAVING_CONFIGURATION: {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user