Skip to content

Commit

Permalink
Auto-populate name on Remote Control page.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Apr 16, 2021
1 parent 5e5bfd6 commit e605f17
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 11 deletions.
8 changes: 3 additions & 5 deletions Server/Pages/RemoteControl.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@page
@using Remotely.Shared.Models
@inject Remotely.Server.Services.IApplicationConfig AppConfig
@inject UserManager<RemotelyUser> UserManager
@model Remotely.Server.Pages.RemoteControlModel
@{
Layout = null;
Expand Down Expand Up @@ -30,10 +29,9 @@
<link href="~/css/remote-control-dark.css" rel="stylesheet" asp-append-version="true" />
}

@if (User.Identity.IsAuthenticated)
@if (Model.RemotelyUser is not null)
{
var user = await UserManager.GetUserAsync(User);
switch (user.UserOptions.Theme)
switch (Model.RemotelyUser.UserOptions.Theme)
{
case Remotely.Shared.Enums.Theme.Light:
<link href="~/css/remote-control-light.css" rel="stylesheet" asp-append-version="true" />
Expand Down Expand Up @@ -214,7 +212,7 @@
<div class="form-block">
<label>Your Name (shown to client): </label>
<br />
<input id="nameInput" type="text" />
<input id="nameInput" type="text" value="@Model.RemotelyUser?.UserOptions?.DisplayName" />
</div>
<div class="form-block">
<label>Session ID: </label>
Expand Down
13 changes: 13 additions & 0 deletions Server/Pages/RemoteControl.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Remotely.Server.Auth;
using Remotely.Server.Services;
using Remotely.Shared.Models;

namespace Remotely.Server.Pages
{
[ServiceFilter(typeof(RemoteControlFilterAttribute))]
public class RemoteControlModel : PageModel
{
private readonly IDataService _dataService;
public RemoteControlModel(IDataService dataService)
{
_dataService = dataService;
}

public RemotelyUser RemotelyUser { get; private set; }
public void OnGet()
{
if (User.Identity.IsAuthenticated)
{
RemotelyUser = _dataService.GetUserByNameWithOrg(base.User.Identity.Name);
}
}
}
}
11 changes: 10 additions & 1 deletion Server/wwwroot/src/RemoteControl/App.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Server/wwwroot/src/RemoteControl/App.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion Server/wwwroot/src/RemoteControl/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MessageSender } from "./MessageSender.js";
import { SessionRecorder } from "./SessionRecorder.js";
import { ApplyInputHandlers } from "./InputEventHandlers.js";
import { ViewerHubConnection } from "./ViewerHubConnection.js";
import { GetSettings } from "./SettingsService.js";
import { GetSettings, SetSettings } from "./SettingsService.js";


var queryString = Utilities.ParseSearchString();
Expand Down Expand Up @@ -37,6 +37,14 @@ export const ViewerApp = {

ApplyInputHandlers();

if (UI.RequesterNameInput.value) {
ViewerApp.RequesterName = UI.RequesterNameInput.value;
}
else if (ViewerApp.Settings.displayName) {
UI.RequesterNameInput.value = ViewerApp.Settings.displayName;
ViewerApp.RequesterName = ViewerApp.Settings.displayName;
}

if (ViewerApp.CasterID) {
ViewerApp.Mode = RemoteControlMode.Unattended;
ViewerApp.ViewerHubConnection.Connect();
Expand All @@ -60,6 +68,9 @@ export const ViewerApp = {
ViewerApp.Mode = RemoteControlMode.Normal;
ViewerApp.ViewerHubConnection.Connect();
UI.StatusMessage.innerHTML = "Sending connection request...";

ViewerApp.Settings.displayName = ViewerApp.RequesterName;
SetSettings(ViewerApp.Settings);
}
}

Expand Down
1 change: 1 addition & 0 deletions Server/wwwroot/src/RemoteControl/Interfaces/Settings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export interface Settings {
streamModeEnabled: boolean;
displayName: string;
}
3 changes: 2 additions & 1 deletion Server/wwwroot/src/RemoteControl/SettingsService.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Server/wwwroot/src/RemoteControl/SettingsService.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Server/wwwroot/src/RemoteControl/SettingsService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Settings } from "./Interfaces/Settings.js";

const defaultSettings = {
streamModeEnabled: false
streamModeEnabled: false,
displayName: ""
};


Expand Down

0 comments on commit e605f17

Please sign in to comment.