Auto detect server

This commit is contained in:
Myx
2022-07-28 01:20:23 +02:00
parent 4ae248dfa0
commit 0a7442d908
34 changed files with 53196 additions and 47 deletions

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="ZY326S5BLL" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-02-06T22:33:46.214309800Z" />
</component>
</project>

View File

@@ -13,7 +13,7 @@ dependencies {
implementation project(':capacitor-haptics')
implementation project(':capacitor-keyboard')
implementation project(':capacitor-status-bar')
implementation "org.jmdns:jmdns:3.5.5"
}

View File

@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="op.ionic.starter">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true">
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:name="op.ionic.starter.MainActivity"
@@ -39,4 +41,7 @@
<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

View File

@@ -2,6 +2,11 @@
<widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<access origin="*" />
<feature name="ARP">
<param name="android-package" value="com.arvindr21.ARP"/>
<param name="onload" value="true"/>
</feature>
<feature name="CordovaHttpPlugin">
<param name="android-package" value="com.silkimen.cordovahttp.CordovaHttpPlugin"/>
</feature>
@@ -11,10 +16,19 @@
<param name="onload" value="true"/>
</feature>
<feature name="ZeroConf">
<param name="android-package" value="net.becvert.cordova.ZeroConf"/>
</feature>
<feature name="SQLitePlugin">
<param name="android-package" value="io.sqlc.SQLitePlugin"/>
</feature>
<feature name="WakeOnLan">
<param name="android-package" value="com.matlipe.WakeOnLan"/>
<param name="onload" value="true"/>
</feature>
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device"/>
</feature>

View File

@@ -1,6 +1,6 @@
{
"appId": "op.ionic.starter",
"appName": "MyApp",
"appName": "GoToBed",
"webDir": "www",
"bundledWebRuntime": false,
"cordova": {

View File

@@ -6,6 +6,15 @@
<param name="ios-package" value="CordovaHttpPlugin"/>
</feature>
<feature name="File">
<param name="ios-package" value="CDVFile"/>
<param name="onload" value="true"/>
</feature>
<feature name="ZeroConf">
<param name="ios-package" value="ZeroConf"/>
</feature>
<feature name="SQLitePlugin">
<param name="ios-package" value="SQLitePlugin"/>
</feature>

36867
Client/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -23,6 +23,7 @@
"@angular/router": "~12.1.1",
"@awesome-cordova-plugins/core": "^5.37.3",
"@awesome-cordova-plugins/http": "^5.37.3",
"@awesome-cordova-plugins/zeroconf": "^5.37.3",
"@capacitor/android": "3.3.3",
"@capacitor/app": "1.0.6",
"@capacitor/core": "3.3.0",
@@ -31,6 +32,7 @@
"@capacitor/keyboard": "1.1.3",
"@capacitor/status-bar": "1.0.6",
"@ionic-native/core": "^5.36.0",
"@ionic-native/zeroconf": "^5.36.0",
"@ionic/angular": "^5.5.2",
"@ionic/storage": "^3.0.6",
"@ionic/storage-angular": "^3.0.6",
@@ -38,12 +40,15 @@
"@ngrx/router-store": "^13.0.2",
"@ngrx/store": "^13.0.2",
"cordova-android": "9.1.0",
"cordova-arp-cache-fetch": "^0.3.2",
"cordova-plugin-advanced-http": "^3.2.2",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-zeroconf": "^1.4.2",
"cordova-sqlite-storage": "^6.0.0",
"eva-icons": "^1.1.3",
"localforage": "^1.10.0",
"localforage-cordovasqlitedriver": "^1.8.0",
"phonegap-wake-on-lan": "file:phonegap-wake-on-lan",
"rxjs": "^6.6.7",
"tslib": "^2.2.0",
"zone.js": "~0.11.4"

View File

@@ -0,0 +1,26 @@
# PhoneGap Wake On Lan
Very basic plugin for sending wake on lan requests from a phonegap app.
# Installation
1. phonegap plugin add https://github.com/lipemat/phonegap-wake-on-lan.git
2. Or add `<plugin spec="https://github.com/lipemat/phonegap-wake-on-lan.git" source="git"/>` to your main config.xml
# Usage in JS
~~~~
document.addEventListener( 'deviceready', function(){
//replace the broadcast ip and mac
var BROADCAST = '192.168.1.255';
var MAC = '48-2C-6A-1E-59-3D';
window.plugins.WakeOnLan.wake( BROADCAST, MAC, function( r ){
console.log( r )
}, function( r){
console.error( r )
} );
}, false );
~~~~
### That's it! Super straight forward.
Wake On Lan Plugin For Cordova/Phonegap

View File

@@ -0,0 +1,58 @@
{
"name": "phonegap-wake-on-lan",
"version": "8.1.1-dev",
"description": "You can use the BarcodeScanner plugin to scan different types of barcodes (using the device's camera) and get the metadata encoded in them for processing within your application.",
"cordova": {
"id": "phonegap-wake-on-lan",
"platforms": [
"ios",
"android",
"windows",
"browser"
]
},
"repository": {
"type": "local",
"url": "C:\\repos\\IonicGoToBed\\go-to-bed\\Client\\plugins\\phonegap-wake-on-lan"
},
"keywords": [
"ecosystem:cordova",
"ecosystem:phonegap",
"cordova-ios",
"cordova-android",
"cordova-windows",
"cordova-browser",
"cordova:plugin"
],
"engines": {
"cordovaDependencies": {
"<7.0.0": {
"cordova-android": "<6.3.0"
},
"7.0.0": {
"cordova-android": ">=6.3.0"
},
"7.1.0": {
"cordova-android": ">=6.3.0",
"cordova": ">=7.1.0"
},
"8.0.0": {
"cordova-android": ">=6.3.0",
"cordova": ">=7.1.0"
}
}
},
"author": "Adobe PhoneGap Team",
"license": "MIT",
"scripts": {
"test": "jasmine-node --color spec"
},
"devDependencies": {
"jasmine-node": "1.14.5",
"pluginpub": "^0.0.9"
},
"dependencies": {
"nopt": "^4.0.1",
"shelljs": "^0.8.3"
}
}

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.matlipe.WakeOnLan"
version="1.0.2">
<name>Wake On Lan</name>
<description>
Send Magic Packets to Wake Up Devices
</description>
<author>Mat Lipe</author>
<license>MIT</license>
<keywords>Wake On Lan</keywords>
<engines>
<engine name="cordova" version=">=3.0.0"/>
</engines>
<js-module src="www/WakeOnLan.js" name="WakeOnLan">
<clobbers target="window.plugins.WakeOnLan"/>
</js-module>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="WakeOnLan">
<param name="android-package" value="com.matlipe.WakeOnLan"/>
<param name="onload" value="true"/>
</feature>
</config-file>
<source-file src="src/WakeOnLan.java" target-dir="src/com/matlipe/WakeOnLan"/>
</platform>
</plugin>

View File

@@ -0,0 +1,89 @@
package com.matlipe;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class WakeOnLan extends CordovaPlugin {
private static final String WAKE_ACTION = "wake";
private static final int PORT = 9;
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
boolean result = false;
if( WAKE_ACTION.equals( action ) ){
if( wake( args ) ){
callbackContext.success( "Device has been woken up" );
result = true;
} else {
callbackContext.error( "Device did not wake up" );
}
} else {
callbackContext.error( "Invalid action : " + action + " passed" );
}
return result;
}
private Boolean wake( JSONArray args ) {
Boolean result = false;
try{
String ipStr = args.getString( 0 );
String macStr = args.getString( 1 );
byte[] macBytes = getMacBytes( macStr );
byte[] bytes = new byte[ 6 + 16 * macBytes.length ];
for( int i = 0; i < 6; i++ ){
bytes[ i ] = ( byte ) 0xff;
}
for( int i = 6; i < bytes.length; i += macBytes.length ){
System.arraycopy( macBytes, 0, bytes, i, macBytes.length );
}
InetAddress address = InetAddress.getByName( ipStr );
DatagramPacket packet = new DatagramPacket( bytes, bytes.length, address, PORT );
DatagramSocket socket = new DatagramSocket();
socket.send( packet );
socket.close();
System.out.println( "Wake-on-LAN packet sent." );
result = true;
} catch( Exception e ){
System.out.println( "WakeOnLan Exception thrown" + e.toString() );
}
return result;
}
private byte[] getMacBytes( String macStr ) throws IllegalArgumentException {
byte[] bytes = new byte[ 6 ];
String[] hex = macStr.split( "(\\:|\\-)" );
if( hex.length != 6 ){
throw new IllegalArgumentException( "Invalid MAC address." );
}
try{
for( int i = 0; i < 6; i++ ){
bytes[ i ] = ( byte ) Integer.parseInt( hex[ i ], 16 );
}
} catch( NumberFormatException e ){
throw new IllegalArgumentException( "Invalid hex digit in MAC address." );
}
return bytes;
}
}

View File

@@ -0,0 +1,24 @@
/*
Copyright 2011 Simon Yeldon
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var WakeOnLan = function(){}
WakeOnLan.prototype.wake = function(mac, ip, success, fail) {
return PhoneGap.exec( success, fail, "WakeOnLan", "wake", [mac, ip]);
}
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin('wol', new WakeOnLan());
});

View File

@@ -1,3 +1,5 @@
import { WOLService } from './services/WOL.service';
import { SearchHostPage } from './components/searchHost/searchHost.page';
import { ExploreContainerComponent } from './components/explore-container/explore-container.component';
import { ServerSettingsComponent } from './components/settings/serverSettings/serverSettings.component';
import { NgModule } from '@angular/core';
@@ -26,7 +28,8 @@ const components = [
MenuPage,
ServerSettingsComponent,
SettingsPage,
ExploreContainerComponent
ExploreContainerComponent,
SearchHostPage
];
@NgModule({
@@ -44,10 +47,10 @@ const components = [
GotobedStoreModule,
IonicStorageModule.forRoot({
name: 'gotobedStorage',
driverOrder: [CordovaSQLLiteDriver._driver, Drivers.IndexedDB]})
driverOrder: [CordovaSQLLiteDriver._driver, Drivers.IndexedDB]}),
],
providers: [HTTP, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy}],
bootstrap: [AppComponent],
exports: [NetworkRequestsService]
exports: [NetworkRequestsService, WOLService]
})
export class AppModule {}

View File

@@ -26,6 +26,19 @@
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<ion-card class="noselect" (click)="wakeUp()">
<ion-card-header>
<ion-card-title>Turn on</ion-card-title>
</ion-card-header>
<ion-card-content>
<ion-icon name="ice-cream-outline"></ion-icon>
</ion-card-content>
</ion-card>
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<ion-card class="noselect" (click)="commandAlert('sleep')">

View File

@@ -1,3 +1,4 @@
import { WOLService } from './../../services/WOL.service';
import { Component, OnInit } from '@angular/core';
import { AlertController } from '@ionic/angular';
import { Store } from '@ngrx/store';
@@ -20,7 +21,8 @@ export class HomePage implements OnInit{
constructor(
public alertController: AlertController,
private httpCommand: NetworkRequestsService,
private store: Store
private store: Store,
private WOLService: WOLService
) {}
ngOnInit() {
@@ -59,4 +61,8 @@ export class HomePage implements OnInit{
await alert.present();
}
wakeUp(){
this.WOLService.wakeUp();
}
}

View File

@@ -14,6 +14,7 @@ import { SearchHostPageRoutingModule } from './searchHost-routing.module';
ExploreContainerComponentModule,
SearchHostPageRoutingModule
],
exports: [SearchHostPage],
declarations: [SearchHostPage]
})
export class SearchHostPageModule {}

View File

@@ -5,11 +5,27 @@
</ion-header>
<ion-content [fullscreen]="true">
<ion-refresher slot="fixed" (ionRefresh)="refresh($event)">
<ion-refresher-content></ion-refresher-content>
</ion-refresher>
<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">WOL</ion-title>
</ion-toolbar>
</ion-header>
<app-explore-container name="WOL"></app-explore-container>
<!-- WOL -->
<ion-list>
<ion-item *ngIf="netWorkDevices.length == 0">
<ion-label>No Devices found</ion-label>
</ion-item>
<ion-item-sliding *ngFor="let device of netWorkDevices">
<ion-item>
<ion-label>{{device.ipv4Addresses[0]}}</ion-label>
</ion-item>
<ion-item-options>
<ion-item-option (click)="saveWolDevice(device)">Save</ion-item-option>
</ion-item-options>
</ion-item-sliding>
</ion-list>
<!-- wol end -->
</ion-content>

View File

@@ -1,8 +1,52 @@
import { Component } from '@angular/core';
import { WolAddressChanged } from './../../store/gotobed.actions';
import { Component, OnInit } from '@angular/core';
import { Zeroconf, ZeroconfResult, ZeroconfService } from "@ionic-native/zeroconf";
import { Store } from '@ngrx/store';
import { ServiceOptions } from 'src/app/gotobed.models';
import { MacSettingsChanged } from 'src/app/store/gotobed.actions';
import { GotobedState } from 'src/app/store/gotobed.state';
@Component({
selector: 'app-searchhost',
templateUrl: 'searchHost.page.html',
styleUrls: ['searchHost.page.scss']
})
export class SearchHostPage { }
export class SearchHostPage implements OnInit {
netWorkDevices: ZeroconfService[] = [];
constructor(private store: Store<GotobedState>) {}
ngOnInit(): void {
this.scanDevices();
}
scanDevices() {
Zeroconf.watchAddressFamily = 'ipv4';
Zeroconf.watch("_http._tcp.", "local.").subscribe(result => {
console.log("Zeroconf Service Changed:");
console.log(result.service);
if(result.service.ipv4Addresses.length > 0 && JSON.stringify(this.netWorkDevices).includes(result.service.ipv4Addresses[0]) == false) {
this.netWorkDevices.push(result.service);
}
});
}
saveWolDevice(device: ZeroconfService) {
this.store.dispatch(new MacSettingsChanged(device.txtRecord.mac));
this.store.dispatch(new WolAddressChanged(this.convertToBroadcast(device.ipv4Addresses[0])));
}
refresh(event) {
console.log('Begin async operation');
this.scanDevices();
setTimeout(() => {
console.log('Async operation has ended');
event.target.complete();
}, 2000);
}
private convertToBroadcast(ip: string) {
let subnetArray = ip.split('.');
subnetArray[3] = '255';
return subnetArray.join('.');
}
}

View File

@@ -17,4 +17,15 @@
<ion-label position="fixed">Port</ion-label>
<ion-input number placeholder="8080" (ionChange)="onPortChange($event)" [value]="port"></ion-input>
</ion-item>
<ion-list-header>
<ion-label> WOL Settings </ion-label>
</ion-list-header>
<ion-item>
<ion-label position="fixed">Mac Address</ion-label>
<ion-input placeholder="MM:MM:MM:SS:SS:SS" (ionChange)="onMacAdressChange($event)" [value]="macAddress"></ion-input>
</ion-item>
<ion-item>
<ion-label position="fixed">Wol Address</ion-label>
<ion-input placeholder="Ex: 192.168.1.255" (ionChange)="onWolAddressChange($event)" [value]="wolAddress"></ion-input>
</ion-item>
</ion-list>

View File

@@ -1,7 +1,7 @@
import { getAddress, getPort, getProtocol } from './../../../store/gotobed.selectors';
import { getAddress, getMacAddress, getPort, getProtocol, getWolAddress } from './../../../store/gotobed.selectors';
import { Store } from '@ngrx/store';
import { Component, OnInit } from '@angular/core';
import { PortSettingsChanged, ProtocolSettingsChanged, SaveAddressSettings } from 'src/app/store/gotobed.actions';
import { MacSettingsChanged, PortSettingsChanged, ProtocolSettingsChanged, SaveAddressSettings, WolAddressChanged } from 'src/app/store/gotobed.actions';
import { GotobedState } from 'src/app/store/gotobed.state';
import { InputCustomEvent } from 'src/app/gotobed.models';
@@ -14,6 +14,8 @@ export class ServerSettingsComponent implements OnInit{
port = null;
address = '';
protocol = '';
macAddress = '';
wolAddress = '';
constructor(private store: Store<GotobedState>) { }
@@ -30,6 +32,14 @@ export class ServerSettingsComponent implements OnInit{
this.store
.select(getProtocol)
.subscribe(protocol => (this.protocol = protocol));
this.store
.select(getMacAddress)
.subscribe(macAddress => (this.macAddress = macAddress));
this.store
.select(getWolAddress)
.subscribe(wolAddress => (this.wolAddress = wolAddress));
}
onProtocolChange(protocol: InputCustomEvent){
@@ -44,4 +54,12 @@ export class ServerSettingsComponent implements OnInit{
console.log(port.detail.value);
this.store.dispatch(new PortSettingsChanged(port.detail.value));
}
onMacAdressChange(macAddress: InputCustomEvent){
console.log(macAddress.detail.value);
this.store.dispatch(new MacSettingsChanged(macAddress.detail.value));
}
onWolAddressChange(wolAddress: InputCustomEvent){
console.log(wolAddress.detail.value);
this.store.dispatch(new WolAddressChanged(wolAddress.detail.value));
}
}

View File

@@ -2,7 +2,8 @@ export const addressStorageKey = 'AddressKey';
export const portStorageKey = 'PortKey';
export const protocolStorageKey = 'ProtocolKey';
export const commandStorageKey = 'CommandKey';
export const macStorageKey = 'MacKey';
export const wolStorageKey = 'WolKey';
export interface InputChangeEventDetail {
value: string | undefined | null;
@@ -16,3 +17,29 @@ export interface InputCustomEvent extends CustomEvent {
export interface NetRequest{
command: string;
}
export interface ServiceOptions {
name: string;
host?: string | undefined;
port: number;
type: string;
subtypes?: string[] | undefined;
protocol?: 'udp'|'tcp' | undefined;
txt?: { [key: string]: string } | undefined;
probe?: boolean | undefined;
}
export interface LocalZeroconf {
domain: string;
type: string;
name: string;
port: number;
hostname: string;
ipv4Addresses: string[];
ipv6Addresses: string[];
txtRecord: macAddress;
}
export interface macAddress {
mac: string;
}

View File

@@ -0,0 +1,34 @@
import { getWolAddress, getMacAddress } from './../store/gotobed.selectors';
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
declare var WakeOnLan: any;
@Injectable({
providedIn: 'root'
})
export class WOLService {
ipAddress = this.store.select(getWolAddress);
macAddress = this.store.select(getMacAddress);
constructor(private store: Store) {}
public wakeUp() {
WakeOnLan.wake(this.macAddress, this.ipAddress, function(response){
console.log(response)
}, function(response){
console.error(response)
});
}
// public start() {
// return new Promise((resolve, reject) => {
// WakeOnLan.wake(this.ipAddress, this.macAddress, function(response){
// console.log(response)
// },
// function(response){
// console.error(response)
// });
// });
// }
}

View File

@@ -7,6 +7,8 @@ export enum EGotobedActions {
protocolSettingsChanged = '[GOTOBED] Protocol settings changed',
portSettingsChanged = '[GOTOBED] Port settings changed',
appInitialized = '[GOTOBED] App initialized',
macSettingsChanged = '[GOTOBED] Mac settings changed',
WolAddressChanged = '[GOTOBED] Wake On Lan address changed',
}
export class SendCommandChanged implements Action {
@@ -24,6 +26,11 @@ export class ProtocolSettingsChanged implements Action {
constructor(public payload: string) { }
}
export class MacSettingsChanged implements Action {
public readonly type = EGotobedActions.macSettingsChanged;
constructor(public payload: string) { }
}
export class PortSettingsChanged implements Action {
public readonly type = EGotobedActions.portSettingsChanged;
constructor(public payload: string) { }
@@ -34,9 +41,16 @@ export class AppInitialized implements Action {
constructor(public payload: LoadSettingsState) { }
}
export class WolAddressChanged implements Action {
public readonly type = EGotobedActions.WolAddressChanged;
constructor(public payload: string) { }
}
export type GotobedActions =
SendCommandChanged |
ProtocolSettingsChanged |
PortSettingsChanged |
SaveAddressSettings |
AppInitialized;
AppInitialized |
MacSettingsChanged |
WolAddressChanged;

View File

@@ -1,3 +1,4 @@
import { macStorageKey, wolStorageKey } from './../gotobed.models';
import { portStorageKey } from '../gotobed.models';
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType, concatLatestFrom, ROOT_EFFECTS_INIT } from '@ngrx/effects';
@@ -5,7 +6,7 @@ import { Store } from '@ngrx/store';
import { map, tap, withLatestFrom } from 'rxjs/operators';
import { addressStorageKey, protocolStorageKey } from '../gotobed.models';
import { StorageService } from '../services/storage.service';
import { AppInitialized, EGotobedActions, ProtocolSettingsChanged, SaveAddressSettings } from './gotobed.actions';
import { AppInitialized, EGotobedActions, MacSettingsChanged, ProtocolSettingsChanged, SaveAddressSettings, WolAddressChanged } from './gotobed.actions';
@Injectable()
export class GotobedEffects {
@@ -49,6 +50,22 @@ export class GotobedEffects {
})
), { dispatch: false });
macAddressSettings$ = createEffect(() => this.actions$.pipe(
ofType<MacSettingsChanged>(EGotobedActions.macSettingsChanged),
withLatestFrom(this.store),
tap(([action]) => {
localStorage.setItem(macStorageKey, action.payload);
})
), { dispatch: false });
wolAddressSettings$ = createEffect(() => this.actions$.pipe(
ofType<WolAddressChanged>(EGotobedActions.WolAddressChanged),
withLatestFrom(this.store),
tap(([action]) => {
localStorage.setItem(wolStorageKey, action.payload);
})
), { dispatch: false });
constructor(
private readonly actions$: Actions,
private readonly store: Store,

View File

@@ -23,6 +23,16 @@ export function gotobedReducer(state = initialGotoBedState, action: GotobedActio
...state,
port: action.payload,
};
case EGotobedActions.macSettingsChanged:
return {
...state,
macAddress: action.payload,
};
case EGotobedActions.WolAddressChanged:
return {
...state,
wolAddress: action.payload,
};
default:
return state;
}

View File

@@ -25,3 +25,13 @@ export const getPort = createSelector(
(state: GotobedState) => state.port
);
export const getMacAddress = createSelector(
gotobedState,
(state: GotobedState) => state.macAddress
);
export const getWolAddress = createSelector(
gotobedState,
(state: GotobedState) => state.wolAddress
);

View File

@@ -1,3 +1,4 @@
import { macStorageKey, wolStorageKey } from './../gotobed.models';
import { addressStorageKey, portStorageKey, protocolStorageKey } from '../gotobed.models';
export const storeName = 'Gotobed';
@@ -9,6 +10,8 @@ export interface GotobedState {
port: string;
address: string;
isConnected: boolean;
macAddress: string;
wolAddress: string;
}
export const initialGotoBedState: GotobedState = {
@@ -16,8 +19,10 @@ export const initialGotoBedState: GotobedState = {
isLoading: false,
protocol: localStorage.getItem(protocolStorageKey) ?? 'http',
port: localStorage.getItem(portStorageKey) ?? '3000',
address: localStorage.getItem(addressStorageKey) ?? 'localhost:8080',
address: localStorage.getItem(addressStorageKey) ?? 'localhost',
isConnected: false,
macAddress: localStorage.getItem(macStorageKey) ?? '',
wolAddress: localStorage.getItem(wolStorageKey) ?? '',
};
export interface LoadSettingsState {

11483
Client/yarn.lock Normal file

File diff suppressed because it is too large Load Diff