Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local IP address to About screen: Resolves #622, #1202, #1320, #4128 #4633

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './job.model';
export * from './printer-profile.model';
export * from './printer.model';
export * from './system.model';
export * from './util-test.model';
5 changes: 5 additions & 0 deletions src/app/model/util-test.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface TestAddress {
address: string;
is_lan_address: boolean;
subnet: string;
}
12 changes: 11 additions & 1 deletion src/app/services/system/system.octoprint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Observable, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';

import { ConfigService } from '../../config/config.service';
import { NotificationType, SocketAuth } from '../../model';
import { NotificationType, SocketAuth, TestAddress } from '../../model';
import { ConnectCommand, OctoprintLogin } from '../../model/octoprint';
import { NotificationService } from '../../notification/notification.service';
import { SystemService } from './system.service';
Expand Down Expand Up @@ -74,4 +74,14 @@ export class SystemOctoprintService implements SystemService {
)
.subscribe();
}

public getLocalIpAddress() {
const payload = {
command: 'address',
};

return this.http
.post<TestAddress>(this.configService.getApiURL('util/test'), payload, this.configService.getHTTPHeaders())
.pipe(map(result => (result?.is_lan_address && result?.address ? result.address : null)));
}
}
2 changes: 2 additions & 0 deletions src/app/services/system/system.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { SocketAuth } from '../../model';

@Injectable()
export abstract class SystemService {
abstract getLocalIpAddress(): Observable<string | null>;

abstract getSessionKey(): Observable<SocketAuth>;

abstract sendCommand(command: string): void;
Expand Down
4 changes: 4 additions & 0 deletions src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,10 @@
install v{{ service.latestVersion }}
</button>
<span class="settings__about-copyright">&#169; 2019-2020 UnchartedBull</span>
<span class="settings__heading-2" i18n="@@connection">Connection</span>
<p class="settings__text" *ngIf="{address: localIpAddress$ | async} as vm">
{{vm.address ? 'IP Address: ' + vm.address : 'Could not detect your IP address' }}
</p>
<span class="settings__heading-2" i18n="@@licence">License</span>
<p class="settings__text">
Licensed under the Apache 2.0 License.
Expand Down
4 changes: 4 additions & 0 deletions src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ConfigService } from '../config/config.service';
import { ElectronService } from '../electron.service';
import { NotificationType } from '../model';
import { NotificationService } from '../notification/notification.service';
import { SystemService } from '../services/system/system.service';

@Component({
selector: 'app-settings',
Expand Down Expand Up @@ -34,10 +35,13 @@ export class SettingsComponent implements OnInit, OnDestroy {
private pages = [];
public update = false;

public localIpAddress$ = this.systemService.getLocalIpAddress();

public constructor(
private configService: ConfigService,
private notificationService: NotificationService,
private electronService: ElectronService,
private systemService: SystemService,
public service: AppService,
) {
this.config = this.configService.getCurrentConfig();
Expand Down
Loading