diff --git a/.editorconfig b/.editorconfig index 95e2beb..daf3ec5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -102,7 +102,7 @@ csharp_style_conditional_delegate_call = true:suggestion # Modifier preferences csharp_prefer_static_local_function = true:suggestion -csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async +csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async # Code-block preferences csharp_prefer_braces = true:suggestion @@ -198,26 +198,26 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case dotnet_naming_symbols.interface.applicable_kinds = interface dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.interface.required_modifiers = +dotnet_naming_symbols.interface.required_modifiers = dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.types.required_modifiers = +dotnet_naming_symbols.types.required_modifiers = dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.non_field_members.required_modifiers = +dotnet_naming_symbols.non_field_members.required_modifiers = # Naming styles -dotnet_naming_style.pascal_case.required_prefix = -dotnet_naming_style.pascal_case.required_suffix = -dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = dotnet_naming_style.pascal_case.capitalization = pascal_case dotnet_naming_style.begins_with_i.required_prefix = I -dotnet_naming_style.begins_with_i.required_suffix = -dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = dotnet_naming_style.begins_with_i.capitalization = pascal_case csharp_style_prefer_method_group_conversion = true:suggestion csharp_style_prefer_parameter_null_checking = true:suggestion diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 88dc5ff..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Launch and Debug Standalone Blazor WebAssembly App", - "type": "blazorwasm", - "request": "launch", - "cwd": "${workspaceFolder}/SoundTest" - } - ] -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index f6bcb59..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/SoundTest/SoundTest.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/SoundTest/SoundTest.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "${workspaceFolder}/SoundTest/SoundTest.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/SoundTest.code-workspace b/SoundTest.code-workspace deleted file mode 100644 index 876a149..0000000 --- a/SoundTest.code-workspace +++ /dev/null @@ -1,8 +0,0 @@ -{ - "folders": [ - { - "path": "." - } - ], - "settings": {} -} \ No newline at end of file diff --git a/SoundTest.sln b/SoundTest.sln deleted file mode 100644 index 2d7f60e..0000000 --- a/SoundTest.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31710.8 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EFED9F50-B827-4097-875C-A2AA85F69403}" - ProjectSection(SolutionItems) = preProject - .editorconfig = .editorconfig - global.json = global.json - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoundTest", "SoundTest\SoundTest.csproj", "{0BC06B08-73F8-4A3F-802D-C641B2BFD7A7}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0BC06B08-73F8-4A3F-802D-C641B2BFD7A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0BC06B08-73F8-4A3F-802D-C641B2BFD7A7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0BC06B08-73F8-4A3F-802D-C641B2BFD7A7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0BC06B08-73F8-4A3F-802D-C641B2BFD7A7}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {0B9C045E-F681-447E-B97B-4BDCF49F4F80} - EndGlobalSection -EndGlobal diff --git a/SoundTest.slnx b/SoundTest.slnx new file mode 100644 index 0000000..36c65ad --- /dev/null +++ b/SoundTest.slnx @@ -0,0 +1,7 @@ + + + + + + + diff --git a/SoundTest/App.razor b/SoundTest/App.razor new file mode 100644 index 0000000..cc1cd15 --- /dev/null +++ b/SoundTest/App.razor @@ -0,0 +1,9 @@ + + + + + + diff --git a/SoundTest/Components/App.razor b/SoundTest/Components/App.razor deleted file mode 100644 index 79ecbc6..0000000 --- a/SoundTest/Components/App.razor +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - Not found - - -

- Sorry, there's nothing at this address. -

-
-
-
diff --git a/SoundTest/Components/SoundComponent.razor.cs b/SoundTest/Components/SoundComponent.razor.cs index 6458203..5e52f81 100644 --- a/SoundTest/Components/SoundComponent.razor.cs +++ b/SoundTest/Components/SoundComponent.razor.cs @@ -1,12 +1,12 @@ -namespace SoundTest.Components; +namespace SoundTest.Components; public partial class SoundComponent(IJSRuntime jsRuntime, ISnackbar snackbar, NavigationManager navigation) { + private bool isJsInitialized; private bool isPlaying; - private string? soundLink; private IJSObjectReference? module; - private bool isJsInitialized; + private string? soundLink; private List? AudioDevices { get; set; } @@ -33,7 +33,7 @@ public int Frequency { < MinFrequency => MinFrequency, > MaxFrequency => MaxFrequency, - _ => value, + _ => value }; _ = SetParametersAndUpdate(); } @@ -47,7 +47,7 @@ private async Task SetParametersAndUpdate() private void UpdateUri() { - var uri = navigation.GetUriWithQueryParameters(new Dictionary() { [nameof(Type)] = (int)Type, [nameof(Frequency)] = Frequency, }); + var uri = navigation.GetUriWithQueryParameters(new Dictionary { [nameof(Type)] = (int)Type, [nameof(Frequency)] = Frequency }); soundLink = uri; } diff --git a/SoundTest/Components/SoundComponent.razor.js b/SoundTest/Components/SoundComponent.razor.js index 5699c01..de063cb 100644 --- a/SoundTest/Components/SoundComponent.razor.js +++ b/SoundTest/Components/SoundComponent.razor.js @@ -1,4 +1,4 @@ -let context = null; +let context = null; let osc = null; let oscType = null; let oscFreq = null; @@ -42,14 +42,14 @@ export async function GetAudioOutputDevices() { devices = (await navigator.mediaDevices.enumerateDevices()).filter(function (entry) { return entry.kind === 'audiooutput' && entry.deviceId !== null && entry.deviceId !== ""; }); - ; + if (devices === null || devices.length === 0) { await navigator.mediaDevices.getUserMedia({audio: true}); devices = (await navigator.mediaDevices.enumerateDevices()).filter(function (entry) { return entry.kind === 'audiooutput' && entry.deviceId !== null && entry.deviceId !== ""; }); - ; + } return devices; diff --git a/SoundTest/Constants.cs b/SoundTest/Constants.cs index 4bfe60b..887a460 100644 --- a/SoundTest/Constants.cs +++ b/SoundTest/Constants.cs @@ -2,6 +2,14 @@ public static class Constants { + public enum Types + { + Sine, + Square, + Triangle, + Sawtooth + } + public const int MinFrequency = 1; public const int MaxFrequency = 1500; // 20154; @@ -11,12 +19,4 @@ public static class Constants public const int NeuroFrequency = 852; public const decimal PerfectCFrequency = 261.63M; // C4 - - public enum Types - { - Sine, - Square, - Triangle, - Sawtooth, - } } diff --git a/SoundTest/GlobalUsings.cs b/SoundTest/GlobalUsings.cs index cb703b6..37410d7 100644 --- a/SoundTest/GlobalUsings.cs +++ b/SoundTest/GlobalUsings.cs @@ -4,7 +4,9 @@ global using Microsoft.JSInterop; global using MudBlazor; global using MudBlazor.Services; -global using SoundTest.Components; +global using SoundTest.Layout; +global using SoundTest.Pages; global using System.Diagnostics; global using System.Runtime.InteropServices.JavaScript; global using static SoundTest.Constants; +global using SoundTest; diff --git a/SoundTest/Components/Layout/MainLayout.razor b/SoundTest/Layout/MainLayout.razor similarity index 100% rename from SoundTest/Components/Layout/MainLayout.razor rename to SoundTest/Layout/MainLayout.razor diff --git a/SoundTest/Components/Layout/MainLayout.razor.cs b/SoundTest/Layout/MainLayout.razor.cs similarity index 94% rename from SoundTest/Components/Layout/MainLayout.razor.cs rename to SoundTest/Layout/MainLayout.razor.cs index a380e77..eb7e196 100644 --- a/SoundTest/Components/Layout/MainLayout.razor.cs +++ b/SoundTest/Layout/MainLayout.razor.cs @@ -1,4 +1,4 @@ -namespace SoundTest.Components.Layout; +namespace SoundTest.Layout; public partial class MainLayout { diff --git a/SoundTest/Components/Pages/Home.razor b/SoundTest/Pages/Home.razor similarity index 68% rename from SoundTest/Components/Pages/Home.razor rename to SoundTest/Pages/Home.razor index 2591b33..ee003ab 100644 --- a/SoundTest/Components/Pages/Home.razor +++ b/SoundTest/Pages/Home.razor @@ -5,4 +5,4 @@ + Frequency="@Frequency"/> diff --git a/SoundTest/Components/Pages/Home.razor.cs b/SoundTest/Pages/Home.razor.cs similarity index 83% rename from SoundTest/Components/Pages/Home.razor.cs rename to SoundTest/Pages/Home.razor.cs index a291927..15b2a00 100644 --- a/SoundTest/Components/Pages/Home.razor.cs +++ b/SoundTest/Pages/Home.razor.cs @@ -1,4 +1,4 @@ -namespace SoundTest.Components.Pages; +namespace SoundTest.Pages; public partial class Home { diff --git a/SoundTest/Pages/NotFound.razor b/SoundTest/Pages/NotFound.razor new file mode 100644 index 0000000..917ada1 --- /dev/null +++ b/SoundTest/Pages/NotFound.razor @@ -0,0 +1,5 @@ +@page "/not-found" +@layout MainLayout + +

Not Found

+

Sorry, the content you are looking for does not exist.

\ No newline at end of file diff --git a/SoundTest/Properties/launchSettings.json b/SoundTest/Properties/launchSettings.json index 86dcd87..c8a976d 100644 --- a/SoundTest/Properties/launchSettings.json +++ b/SoundTest/Properties/launchSettings.json @@ -1,20 +1,12 @@ { - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:38548", - "sslPort": 44368 - } - }, + "$schema": "https://json.schemastore.org/launchsettings.json", "profiles": { "http": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "http://localhost:5046", + "applicationUrl": "http://localhost:5129", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } @@ -24,15 +16,7 @@ "dotnetRunMessages": true, "launchBrowser": true, "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "https://localhost:7095;http://localhost:5046", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "applicationUrl": "https://localhost:7079;http://localhost:5129", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/SoundTest/SoundTest.csproj b/SoundTest/SoundTest.csproj index b6e5cdb..ca1a56d 100644 --- a/SoundTest/SoundTest.csproj +++ b/SoundTest/SoundTest.csproj @@ -4,6 +4,7 @@ net10.0 enable enable + true false false true @@ -18,7 +19,7 @@ - + diff --git a/SoundTest/_Imports.razor b/SoundTest/_Imports.razor index 3fe648b..86051d8 100644 --- a/SoundTest/_Imports.razor +++ b/SoundTest/_Imports.razor @@ -6,8 +6,10 @@ @using Microsoft.AspNetCore.Components.Web.Virtualization @using Microsoft.AspNetCore.Components.WebAssembly.Http @using Microsoft.JSInterop -@using MudBlazor @using SoundTest @using SoundTest.Components -@using SoundTest.Components.Layout -@using static SoundTest.Constants +@using SoundTest.Layout +@using SoundTest.Pages +@using MudBlazor + +@using static Constants diff --git a/SoundTest/wwwroot/css/app.css b/SoundTest/wwwroot/css/app.css index 2f5fbaf..7c91049 100644 --- a/SoundTest/wwwroot/css/app.css +++ b/SoundTest/wwwroot/css/app.css @@ -1,9 +1,10 @@ .loading-progress { - position: relative; + position: absolute; display: block; width: 8rem; height: 8rem; - margin: 20vh auto 1rem auto; + inset: 20vh 0 auto 0; + margin: 0 auto 0 auto; } .loading-progress circle { diff --git a/SoundTest/wwwroot/index.html b/SoundTest/wwwroot/index.html index 6564f10..2b667cf 100644 --- a/SoundTest/wwwroot/index.html +++ b/SoundTest/wwwroot/index.html @@ -3,36 +3,44 @@ - + Sound Test + - - - + + + +
- - + +
- +
An unhandled error has occurred. - Reload - 🗙 + Reload + 🗙
- + - + + diff --git a/SoundTest/wwwroot/manifest.json b/SoundTest/wwwroot/manifest.webmanifest similarity index 80% rename from SoundTest/wwwroot/manifest.json rename to SoundTest/wwwroot/manifest.webmanifest index 197f273..f54f85a 100644 --- a/SoundTest/wwwroot/manifest.json +++ b/SoundTest/wwwroot/manifest.webmanifest @@ -1,10 +1,12 @@ { "name": "Sound Test", - "short_name": "SoundTest", + "short_name": "Sound Test", + "id": "./", "start_url": "./", "display": "standalone", "background_color": "#ffffff", "theme_color": "#03173d", + "prefer_related_applications": false, "icons": [ { "src": "icon-512.png", diff --git a/SoundTest/wwwroot/service-worker.js b/SoundTest/wwwroot/service-worker.js index fe614da..4882765 100644 --- a/SoundTest/wwwroot/service-worker.js +++ b/SoundTest/wwwroot/service-worker.js @@ -1,4 +1,5 @@ // In development, always fetch from the network and do not enable offline support. // This is because caching would make development more difficult (changes would not // be reflected on the first load after each change). -self.addEventListener('fetch', () => { }); +self.addEventListener('fetch', () => { +}); diff --git a/SoundTest/wwwroot/service-worker.published.js b/SoundTest/wwwroot/service-worker.published.js index 18209f3..9de510d 100644 --- a/SoundTest/wwwroot/service-worker.published.js +++ b/SoundTest/wwwroot/service-worker.published.js @@ -8,9 +8,14 @@ self.addEventListener('fetch', event => event.respondWith(onFetch(event))); const cacheNamePrefix = 'offline-cache-'; const cacheName = `${cacheNamePrefix}${self.assetsManifest.version}`; -const offlineAssetsInclude = [/\.dll$/, /\.pdb$/, /\.wasm/, /\.html/, /\.js$/, /\.json$/, /\.css$/, /\.woff$/, /\.png$/, /\.jpe?g$/, /\.gif$/, /\.ico$/, /\.blat$/, /\.dat$/]; +const offlineAssetsInclude = [/\.dll$/, /\.pdb$/, /\.wasm/, /\.html/, /\.js$/, /\.json$/, /\.css$/, /\.woff$/, /\.png$/, /\.jpe?g$/, /\.gif$/, /\.ico$/, /\.blat$/, /\.dat$/, /\.webmanifest$/]; const offlineAssetsExclude = [/^service-worker\.js$/]; +// Replace with your base path if you are hosting on a subfolder. Ensure there is a trailing '/'. +const base = "/"; +const baseUrl = new URL(base, self.origin); +const manifestUrlList = self.assetsManifest.assets.map(asset => new URL(asset.url, baseUrl).href); + async function onInstall(event) { console.info('Service worker: Install'); @@ -18,7 +23,7 @@ async function onInstall(event) { const assetsRequests = self.assetsManifest.assets .filter(asset => offlineAssetsInclude.some(pattern => pattern.test(asset.url))) .filter(asset => !offlineAssetsExclude.some(pattern => pattern.test(asset.url))) - .map(asset => new Request(asset.url, { integrity: asset.hash })); + .map(asset => new Request(asset.url, {integrity: asset.hash, cache: 'no-cache'})); await caches.open(cacheName).then(cache => cache.addAll(assetsRequests)); } @@ -35,9 +40,11 @@ async function onActivate(event) { async function onFetch(event) { let cachedResponse = null; if (event.request.method === 'GET') { - // For all navigation requests, try to serve index.html from cache + // For all navigation requests, try to serve index.html from cache, + // unless that request is for an offline resource. // If you need some URLs to be server-rendered, edit the following check to exclude those URLs - const shouldServeIndexHtml = event.request.mode === 'navigate'; + const shouldServeIndexHtml = event.request.mode === 'navigate' + && !manifestUrlList.some(url => url === event.request.url); const request = shouldServeIndexHtml ? 'index.html' : event.request; const cache = await caches.open(cacheName);