Skip to content
Merged
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
4 changes: 2 additions & 2 deletions PKVault.Backend/ExceptionHandlingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public async Task Invoke(HttpContext context)
}
}

private static async Task WriteExceptionResponse(HttpContext context, Exception ex)
public static async Task WriteExceptionResponse(HttpContext context, Exception ex)
{
Log.Error(ex.ToString());
Log.Error(ex, "Exception during web request");
var response = context.Response;
if (response.HasStarted)
{
Expand Down
2 changes: 1 addition & 1 deletion PKVault.Backend/backup/services/BackupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public async Task PrepareBackupThenRun(string backupName, DataUpdateFlags flags,
}
catch (Exception ex)
{
log.LogError(ex.ToString());
log.LogError(ex, "Exception during action run");

await RestoreBackup(bkpDateTime, withSafeBackup: false, flags);

Expand Down
5 changes: 2 additions & 3 deletions PKVault.Backend/db/loader/PkmFileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static async Task<PkmFileEntity> LoadPkmFile(IFileIOService fileIOService
}
catch (Exception ex)
{
Log.Warning(ex.ToString());
Log.Warning(ex, "Exception during PKM file load");

pkmFile.Data = [];
pkmFile.Error = GetPKMLoadError(ex);
Expand Down Expand Up @@ -216,8 +216,7 @@ public ImmutablePKM CreatePKM(PkmFileEntity entity, EntityContext context)
}
catch (Exception ex)
{
Log.Error($"PKM file load failure with PkmFileEntity.Filepath=${filepath}");
Log.Error(ex.ToString());
Log.Error(ex, $"PKM file load failure with PkmFileEntity.Filepath=${filepath}");

pkm = GetPlaceholderPKM();
loadError = GetPKMLoadError(ex);
Expand Down
2 changes: 1 addition & 1 deletion PKVault.Backend/db/loader/save/SavesLoadersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private async Task<IDictionary<uint, SaveLoadersRecord>> ReadSaveFiles()
}
catch (Exception ex)
{
log.LogError(ex.ToString());
log.LogError(ex, $"Exception during save load, path={path}");
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion PKVault.Backend/db/services/SessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private async Task<bool> CheckDataToNormalize(IServiceScope scope, DataUpdateFla
}
catch (Exception ex)
{
log.LogError(ex.ToString());
log.LogError(ex, "Exception during external-pkms check/update");
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions PKVault.Backend/settings/services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static bool IsSteamDeck()
}
catch (Exception ex)
{
Log.Error(ex.ToString());
Log.Error(ex, "Exception during is-steamdeck check");
}

try
Expand All @@ -325,7 +325,7 @@ static bool IsSteamDeck()
}
catch (Exception ex)
{
Log.Error(ex.ToString());
Log.Error(ex, "Exception during is-steamdeck hostname check");
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion PKVault.Backend/storage/services/ActionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ await scope.ServiceProvider.GetRequiredService<SessionDbContext>()
}
catch (Exception ex)
{
log.LogError(ex.ToString());
log.LogError(ex, "Exception during action add");

await RemoveDataActionsAndReset(sessionService.Actions.Count);

Expand Down
3 changes: 1 addition & 2 deletions PKVault.Backend/storage/services/PkmLegalityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ private PkmLegalityDTO CreateDTO(
}
catch (Exception ex)
{
Log.Error($"ValidityReport exception, id={id}");
Log.Error(ex.ToString());
Log.Error(ex, $"Exception during ValidityReport, id={id}");
ValidityReport = ex.ToString();
}

Expand Down
83 changes: 49 additions & 34 deletions PKVault.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,16 @@ static void Main(string[] args)
{
Log.Logger.Debug("CREATED");

var backendServerPostRun = await SetupBackendServer(server, args);
await backendServerPostRun();
try
{
var backendServerPostRun = await SetupBackendServer(server, args);
await backendServerPostRun();
}
catch (Exception ex)
{
Log.Fatal(ex, "An unhandled exception occurred post window created");
throw;
}

});
window.RegisterWindowClosingHandler((sender, e) =>
Expand Down Expand Up @@ -140,40 +148,47 @@ private static Func<Task> SetupStaticAssetsServer(out string baseUrl)

server.Map("{**catchAll}", async context =>
{
// log.LogInformation("GET => " + context.Request.Path.Value);
// log.LogInformation(context.Request.GetDisplayUrl());
// log.LogInformation(context.Request.GetEncodedUrl());

// http://localhost:8000/api/storage/main/pkm-version
// http://localhost:8000/index.html?server=http://localhost:57471
var uri = context.Request.GetDisplayUrl();
// log.LogInformation($"DEBUG {uri}");

var uriParts = uri.Split('?')[0].Split('/');

var uriActionAndRest = uriParts.Skip(3);
var uriAction = uriActionAndRest.First();
var uriDirectories = uriActionAndRest.SkipLast(1);
var uriFilename = uriActionAndRest.Last();
var uriFilenameExt = Path.GetExtension(uriFilename);
var assemblyActionAndRest = string.Join('.', [
..uriDirectories.Select(part => part.Replace('-', '_')),
uriFilename
]);

var streamKey = $"{AssemblyStaticPrefix}{assemblyActionAndRest}";
var stream = Assembly.GetManifestResourceStream(streamKey);
if (stream == null)
try
{
Log.Error($"Stream not found for key {streamKey}");
// args.Response = webView.CoreWebView2.Environment.CreateWebResourceResponse(stream, 404, "Not Found", "");
return;
}
// log.LogInformation("GET => " + context.Request.Path.Value);
// log.LogInformation(context.Request.GetDisplayUrl());
// log.LogInformation(context.Request.GetEncodedUrl());

contentTypeProvider.Mappings.TryGetValue(uriFilenameExt, out var contentType);
// http://localhost:8000/api/storage/main/pkm-version
// http://localhost:8000/index.html?server=http://localhost:57471
var uri = context.Request.GetDisplayUrl();
// log.LogInformation($"DEBUG {uri}");

context.Response.ContentType = contentType;
await stream.CopyToAsync(context.Response.Body);
if (uri.EndsWith("/.well-known/appspecific/com.chrome.devtools.json"))
{
context.Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status404NotFound;
return;
}

var uriParts = uri.Split('?')[0].Split('/');

var uriActionAndRest = uriParts.Skip(3);
var uriAction = uriActionAndRest.First();
var uriDirectories = uriActionAndRest.SkipLast(1);
var uriFilename = uriActionAndRest.Last();
var uriFilenameExt = Path.GetExtension(uriFilename);
var assemblyActionAndRest = string.Join('.', [
..uriDirectories.Select(part => part.Replace('-', '_')),
uriFilename
]);

var streamKey = $"{AssemblyStaticPrefix}{assemblyActionAndRest}";
var stream = Assembly.GetManifestResourceStream(streamKey)
?? throw new ArgumentException($"Stream not found for key {streamKey}, uri {uri}");
contentTypeProvider.Mappings.TryGetValue(uriFilenameExt, out var contentType);

context.Response.ContentType = contentType;
await stream.CopyToAsync(context.Response.Body);
}
catch (Exception ex)
{
await ExceptionHandlingMiddleware.WriteExceptionResponse(context, ex);
}
});

return () => server.RunAsync();
Expand Down Expand Up @@ -383,7 +398,7 @@ async Task<FileExploreResponseMessage> GetDialogResponse()
}
catch (JsonException ex)
{
Log.Error(ex.ToString());
Log.Error(ex, "JsonException during frontend message recept");
}
});
}
Expand Down
28 changes: 28 additions & 0 deletions frontend/package-lock.json

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

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"typescript-eslint": "^8.59.0",
"vite": "^8.0.3",
"vite-css-modules": "^1.16.0",
"vite-plugin-devtools-json": "^1.1.0",
"vite-plugin-image-optimizer": "^2.0.3",
"vite-plugin-svgr": "^5.2.0",
"vitest": "^4.1.8"
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/notification/hooks/use-check-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export const useCheckUpdate = (): string | undefined => {
const updateQuery = useQuery({
queryKey: [ 'check-update' ],
queryFn: () => fetch('https://api.github.com/repos/chnapy/PKVault/releases/latest')
.then<{
.then<Partial<{
name: string;
draft: boolean;
prerelease: boolean;
}>(res => res.json()),
}> | undefined>(res => res.json()),
});

if (!updateQuery.data || !settingsQuery.data) {
if (!updateQuery.data?.name || !settingsQuery.data) {
return;
}

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/notification/notification-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BellIcon } from 'lucide-react';
import React from 'react';
import { BackendErrorsContext } from '../data/backend-errors-context';
import { useWarningsGetWarnings } from '../data/sdk/warnings/warnings.gen';
import { withErrorCatcher } from '../error/with-error-catcher';
import { useTranslate } from '../translate/i18n';
import { UIActionIcon } from '../ui/form/button/ui-action-icon';
import type { PopoverContext } from '../ui/interaction/focus-controls/components/popover/context/popover-context';
Expand Down Expand Up @@ -40,7 +41,7 @@ const useOpened = () => {
};
};

export const NotificationButton: React.FC = () => {
export const NotificationButton: React.FC = withErrorCatcher('item', () => {
const { t } = useTranslate();

const { hasAlerts, opened, setOpened } = useOpened();
Expand Down Expand Up @@ -75,4 +76,4 @@ export const NotificationButton: React.FC = () => {
}}
/>
);
};
});
28 changes: 16 additions & 12 deletions frontend/src/settings/about/settings-about-right.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ export const SettingsAboutRight: React.FC = () => {
const releasesQuery = useQuery({
queryKey: [ 'release-list' ],
queryFn: () => fetch('https://api.github.com/repos/chnapy/PKVault/releases')
.then<{
url: string;
.then<Partial<{
// url: string;
html_url: string;
id: number;
name: string;
draft: boolean;
prerelease: boolean;
created_at: string;
updated_at: string;
// draft: boolean;
// prerelease: boolean;
// created_at: string;
// updated_at: string;
published_at: string;
body: string;
}[]>(res => res.json())
.then(data => data.sort((r1, r2) => {
const state = getReleaseVersionState(r1.name.substring(1), r2.name.substring(1));
}>[] | undefined>(res => res.json())
.then(data => (data ?? []).sort((r1, r2) => {
const state = r1.name && r2.name
? getReleaseVersionState(r1.name.substring(1), r2.name.substring(1))
: 'same';
return switchUtil(state, {
new: -1,
old: 1,
Expand All @@ -61,7 +63,9 @@ export const SettingsAboutRight: React.FC = () => {
{isPending && <Skeleton h='100vh' mt='md' />}

{!isPending && releasesQuery.data?.map(r => {
const releaseState = getReleaseVersionState(r.name.substring(1), settingsVersion ?? '');
const releaseState = r.name
? getReleaseVersionState(r.name.substring(1), settingsVersion ?? '')
: 'same';

return <CardSection key={r.id} withBorder inheritPadding py='inherit'
style={{
Expand Down Expand Up @@ -89,7 +93,7 @@ export const SettingsAboutRight: React.FC = () => {
{r.name}
</UIButton>
<Badge variant='light' size='lg'>
{renderDate(new Date(r.published_at))}
{r.published_at && renderDate(new Date(r.published_at))}
</Badge>

{releaseState === 'same' && <Badge variant='filled' size='lg' ml='auto'>
Expand All @@ -105,7 +109,7 @@ export const SettingsAboutRight: React.FC = () => {
<UIMarkdownRenderer
titleReduce={3}
>
{r.body
{(r.body ?? '')
.replaceAll(/@(\w+)/g, (match, name) => {
return `[@${name}](https://github.com/${name})`;
})
Expand Down
2 changes: 2 additions & 0 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { tanstackRouter } from "@tanstack/router-plugin/vite";
import react, { reactCompilerPreset } from '@vitejs/plugin-react';
import { defineConfig } from "vite";
import { patchCssModules } from 'vite-css-modules';
import devtoolsJson from 'vite-plugin-devtools-json';
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer';
import svgr from "vite-plugin-svgr";
import { prepareDocs } from './src/help/prepare-docs';
Expand All @@ -25,6 +26,7 @@ export default defineConfig({
generateSourceTypes: true,
declarationMap: true
}),
devtoolsJson(),
tanstackRouter({
target: "react",
autoCodeSplitting: true,
Expand Down
Loading