From 942b79c303530ff4f26e0551a12b560cc76205aa Mon Sep 17 00:00:00 2001 From: 4gray Date: Sat, 16 Nov 2024 23:54:26 +0100 Subject: [PATCH] build(tauri): resolve build issues --- angular.json | 6 ++-- src-tauri/Info.plist | 21 ++++++++++++++ src-tauri/tauri.conf.json | 58 +++++++++++++++++++++++++++++++++++++-- src/main.ts | 10 ++++++- 4 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 src-tauri/Info.plist diff --git a/angular.json b/angular.json index 1805e9685..77f009c33 100644 --- a/angular.json +++ b/angular.json @@ -59,7 +59,7 @@ }, "web": { "optimization": true, - "outputHashing": "all", + "outputHashing": "none", "sourceMap": false, "namedChunks": false, "aot": true, @@ -74,8 +74,8 @@ ] }, "production": { - "optimization": true, - "outputHashing": "all", + "optimization": false, + "outputHashing": "none", "sourceMap": false, "namedChunks": false, "aot": true, diff --git a/src-tauri/Info.plist b/src-tauri/Info.plist new file mode 100644 index 000000000..b7db7c92b --- /dev/null +++ b/src-tauri/Info.plist @@ -0,0 +1,21 @@ + + + + + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + NSExceptionDomains + + localhost + + NSExceptionAllowsInsecureHTTPLoads + + NSIncludesSubdomains + + + + + + diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 54b0c6418..29813c49c 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -22,7 +22,54 @@ } ], "security": { - "csp": "default-src 'self' 'unsafe-eval' 'unsafe-inline'; media-src *" + "csp": { + "default-src": [ + "'self'", + "data:", + "tauri:", + "asset:", + "blob:", + "https:", + "http:", + "'unsafe-eval'", + "'unsafe-inline'" + ], + "img-src": [ + "'self'", + "data:", + "asset:", + "https:", + "http:", + "blob:" + ], + "media-src": ["'self'", "https:", "http:", "blob:", "data:"], + "script-src": [ + "'self'", + "'unsafe-inline'", + "'unsafe-eval'", + "tauri:", + "asset:" + ], + "style-src": [ + "'self'", + "'unsafe-inline'", + "https:", + "http:", + "https://fonts.googleapis.com" + ], + "font-src": ["'self'", "https://fonts.gstatic.com", "data:"], + "connect-src": [ + "'self'", + "https:", + "http:", + "ws:", + "wss:", + "data:", + "tauri:" + ], + "frame-src": ["'self'", "https:", "http:", "blob:", "data:"], + "worker-src": ["'self'", "blob:", "data:"] + } } }, "bundle": { @@ -34,6 +81,13 @@ "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico" - ] + ], + "macOS": { + "entitlements": null, + "exceptionDomain": "*", + "frameworks": [], + "providerShortName": null, + "signingIdentity": null + } } } diff --git a/src/main.ts b/src/main.ts index 8ac612d9c..ed385e884 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,5 @@ import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; - import { AppModule } from './app/app.module'; import { AppConfig } from './environments/environment'; @@ -8,8 +7,17 @@ if (AppConfig.production) { enableProdMode(); } +// Detect if running in Tauri +const isTauri = window && (window as any).__TAURI__; + platformBrowserDynamic() .bootstrapModule(AppModule, { preserveWhitespaces: false, }) + .then(() => { + // Only register service worker for web builds + if (!isTauri && 'serviceWorker' in navigator) { + navigator.serviceWorker.register('/ngsw-worker.js'); + } + }) .catch((err) => console.error(err));