Skip to content

Commit

Permalink
Make AlwaysOnTop action configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgDangl committed Jul 4, 2024
1 parent d95194d commit 77cd648
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 11 deletions.
22 changes: 14 additions & 8 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,20 @@ class Build : NukeBuild
.Executes(() =>
{
WriteFileVersionProvider();

DotNetBuild(s => s
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemVer)
.SetInformationalVersion(GitVersion.InformationalVersion)
.EnableNoRestore());
CompileBackend();
});

private void CompileBackend()
{
DotNetBuild(s => s
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemVer)
.SetInformationalVersion(GitVersion.InformationalVersion)
.EnableNoRestore());
}

private void WriteFileVersionProvider()
{
var fileVersionPath = RootDirectory / "src" / "IPA.BCFier" / "FileVersionProvider.cs";
Expand Down Expand Up @@ -505,6 +509,8 @@ await PublishRelease(x => x
.DependsOn(Restore)
.Executes(() =>
{
CompileBackend();

var nSwagConfigPath = SourceDirectory / "ipa-bcfier-ui" / "src" / "nswag.json";
var nSwagToolPath = NuGetToolPathResolver.GetPackageExecutable("NSwag.MSBuild", "tools/Net80/dotnet-nswag.dll");
DotNetRun(x => x
Expand Down
28 changes: 28 additions & 0 deletions src/IPA.Bcfier.App/Controllers/SettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,33 @@ public async Task<IActionResult> SaveSettingsAsync([FromBody] Settings settings)
await _settingsService.SaveSettingsAsync(settings);
return NoContent();
}

[HttpGet("always-on-top")]
[ProducesResponseType(typeof(bool), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetIsAlwaysOnTopAsync()
{
var electronWindow = _electronWindowProvider.BrowserWindow;
if (electronWindow == null)
{
return BadRequest();
}

var isAlwaysOnTop = await electronWindow.IsAlwaysOnTopAsync();
return Ok(isAlwaysOnTop);
}

[HttpPut("always-on-top")]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
public async Task<IActionResult> SetIsAlwaysOnTopAsync(bool isAlwaysOnTop)
{
var electronWindow = _electronWindowProvider.BrowserWindow;
if (electronWindow == null)
{
return BadRequest();
}

electronWindow.SetAlwaysOnTop(isAlwaysOnTop);
return NoContent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
<mat-icon>support</mat-icon>
Help
</button>
<mat-checkbox
[(ngModel)]="alwaysOnTop"
[disabled]="alwaysOnTopRequestRunning"
>
Always On Top
</mat-checkbox>
</div>
<div class="project-name">
<span>{{ (selectedProject$ | async)?.name | uppercase }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {
BcfFileWrapper,
LastOpenedFileGet,
LastOpenedFilesClient,
SettingsClient,
} from '../../generated-client/generated-client';
import { Component, OnDestroy, inject } from '@angular/core';
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import {
Subject,
Expand All @@ -19,8 +20,10 @@ import {

import { BackendService } from '../../services/BackendService';
import { BcfFilesMessengerService } from '../../services/bcf-files-messenger.service';
import { FormsModule } from '@angular/forms';
import { LastOpenedFilesComponent } from '../last-opened-files/last-opened-files.component';
import { MatButtonModule } from '@angular/material/button';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatIconModule } from '@angular/material/icon';
import { MatMenuModule } from '@angular/material/menu';
import { NotificationsService } from '../../services/notifications.service';
Expand All @@ -39,26 +42,77 @@ import { version } from '../../version';
AsyncPipe,
MatMenuModule,
LastOpenedFilesComponent,
MatCheckboxModule,
FormsModule,
],
templateUrl: './top-menu.component.html',
styleUrl: './top-menu.component.scss',
})
export class TopMenuComponent implements OnDestroy {
export class TopMenuComponent implements OnDestroy, OnInit {
private destroyed$ = new Subject<void>();
version = version.version;
selectedProject$ = inject(SelectedProjectMessengerService).selectedProject;
lastFileMenuOpened = false;
lastOpenedFiles: LastOpenedFileGet[] = [];
alwaysOnTopRequestRunning = false;
private _alwaysOnTop = true;
set alwaysOnTop(value: boolean) {
this._alwaysOnTop = value;
this.changeAlwaysOnTopInBackend();
}
get alwaysOnTop(): boolean {
return this._alwaysOnTop;
}

constructor(
private backendService: BackendService,
private notificationsService: NotificationsService,
private bcfFilesMessengerService: BcfFilesMessengerService,
private matDialog: MatDialog,
private lastOpenedFilesClient: LastOpenedFilesClient
private lastOpenedFilesClient: LastOpenedFilesClient,
private settingsClient: SettingsClient
) {
this.checkOpenedFileAndSendInfo();
}

private changeAlwaysOnTopInBackend(): void {
const isAlwaysOnTop = this._alwaysOnTop;
this.alwaysOnTopRequestRunning = true;

this.settingsClient.getIsAlwaysOnTop().subscribe({
next: (serverIsAlwaysOnTop) => {
if (serverIsAlwaysOnTop === isAlwaysOnTop) {
this.alwaysOnTopRequestRunning = false;
return;
}

this.settingsClient.setIsAlwaysOnTop(isAlwaysOnTop).subscribe({
next: () => {
this.alwaysOnTopRequestRunning = false;
},
error: () => {
this.notificationsService.error(
'Could not change always on top setting.'
);
this.alwaysOnTopRequestRunning = false;
},
});
},
error: () => {
this.notificationsService.error(
'Could not change always on top setting.'
);
this.alwaysOnTopRequestRunning = false;
},
});
}

ngOnInit(): void {
this.settingsClient.getIsAlwaysOnTop().subscribe((isAlwaysOnTop) => {
this._alwaysOnTop = isAlwaysOnTop;
});
}

ngOnDestroy(): void {
this.destroyed$.next();
this.destroyed$.complete();
Expand Down
97 changes: 97 additions & 0 deletions src/ipa-bcfier-ui/src/app/generated-client/generated-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,8 @@ export interface ISettingsClient {
getSettings(): Observable<Settings>;
saveSettings(settings: Settings): Observable<void>;
choseMainDatabaseLocation(): Observable<void>;
getIsAlwaysOnTop(): Observable<boolean>;
setIsAlwaysOnTop(isAlwaysOnTop: boolean | undefined): Observable<void>;
}

@Injectable({
Expand Down Expand Up @@ -1165,6 +1167,101 @@ export class SettingsClient implements ISettingsClient {
}
return _observableOf(null as any);
}

getIsAlwaysOnTop(): Observable<boolean> {
let url_ = this.baseUrl + "/api/settings/always-on-top";
url_ = url_.replace(/[?&]$/, "");

let options_ : any = {
observe: "response",
responseType: "blob",
headers: new HttpHeaders({
"Accept": "application/json"
})
};

return this.http.request("get", url_, options_).pipe(_observableMergeMap((response_ : any) => {
return this.processGetIsAlwaysOnTop(response_);
})).pipe(_observableCatch((response_: any) => {
if (response_ instanceof HttpResponseBase) {
try {
return this.processGetIsAlwaysOnTop(response_ as any);
} catch (e) {
return _observableThrow(e) as any as Observable<boolean>;
}
} else
return _observableThrow(response_) as any as Observable<boolean>;
}));
}

protected processGetIsAlwaysOnTop(response: HttpResponseBase): Observable<boolean> {
const status = response.status;
const responseBlob =
response instanceof HttpResponse ? response.body :
(response as any).error instanceof Blob ? (response as any).error : undefined;

let _headers: any = {}; if (response.headers) { for (let key of response.headers.keys()) { _headers[key] = response.headers.get(key); }}
if (status === 200) {
return blobToText(responseBlob).pipe(_observableMergeMap((_responseText: string) => {
let result200: any = null;
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as boolean;
return _observableOf(result200);
}));
} else if (status !== 200 && status !== 204) {
return blobToText(responseBlob).pipe(_observableMergeMap((_responseText: string) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}));
}
return _observableOf(null as any);
}

setIsAlwaysOnTop(isAlwaysOnTop: boolean | undefined): Observable<void> {
let url_ = this.baseUrl + "/api/settings/always-on-top?";
if (isAlwaysOnTop === null)
throw new Error("The parameter 'isAlwaysOnTop' cannot be null.");
else if (isAlwaysOnTop !== undefined)
url_ += "isAlwaysOnTop=" + encodeURIComponent("" + isAlwaysOnTop) + "&";
url_ = url_.replace(/[?&]$/, "");

let options_ : any = {
observe: "response",
responseType: "blob",
headers: new HttpHeaders({
})
};

return this.http.request("put", url_, options_).pipe(_observableMergeMap((response_ : any) => {
return this.processSetIsAlwaysOnTop(response_);
})).pipe(_observableCatch((response_: any) => {
if (response_ instanceof HttpResponseBase) {
try {
return this.processSetIsAlwaysOnTop(response_ as any);
} catch (e) {
return _observableThrow(e) as any as Observable<void>;
}
} else
return _observableThrow(response_) as any as Observable<void>;
}));
}

protected processSetIsAlwaysOnTop(response: HttpResponseBase): Observable<void> {
const status = response.status;
const responseBlob =
response instanceof HttpResponse ? response.body :
(response as any).error instanceof Blob ? (response as any).error : undefined;

let _headers: any = {}; if (response.headers) { for (let key of response.headers.keys()) { _headers[key] = response.headers.get(key); }}
if (status === 204) {
return blobToText(responseBlob).pipe(_observableMergeMap((_responseText: string) => {
return _observableOf(null as any);
}));
} else if (status !== 200 && status !== 204) {
return blobToText(responseBlob).pipe(_observableMergeMap((_responseText: string) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}));
}
return _observableOf(null as any);
}
}

export interface ITeamsMessagesClient {
Expand Down

0 comments on commit 77cd648

Please sign in to comment.