From f86d7f1ea5374ca7f422ae10f40889169b13ae4f Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 26 Nov 2024 23:40:49 -0600 Subject: [PATCH] Switch to Tauri (Typescript/Preact template) --- .github/workflows/build.yaml | 43 ------- .gitignore | 30 ++++- .vscode/extensions.json | 3 + factorio-achievements-fixer.sln | 25 ---- factorio-achievements-fixer/App.xaml | 9 -- factorio-achievements-fixer/App.xaml.cs | 12 -- factorio-achievements-fixer/AssemblyInfo.cs | 17 --- .../InitialWindow.xaml | 45 ------- .../InitialWindow.xaml.cs | 71 ----------- .../factorio-achievements-fixer.csproj | 20 --- index.html | 14 +++ package.json | 23 ++++ public/tauri.svg | 6 + public/vite.svg | 1 + src-tauri/.gitignore | 7 ++ src-tauri/Cargo.toml | 25 ++++ src-tauri/build.rs | 3 + src-tauri/capabilities/default.json | 10 ++ src-tauri/icons/128x128.png | Bin 0 -> 3512 bytes src-tauri/icons/128x128@2x.png | Bin 0 -> 7012 bytes src-tauri/icons/32x32.png | Bin 0 -> 974 bytes src-tauri/icons/Square107x107Logo.png | Bin 0 -> 2863 bytes src-tauri/icons/Square142x142Logo.png | Bin 0 -> 3858 bytes src-tauri/icons/Square150x150Logo.png | Bin 0 -> 3966 bytes src-tauri/icons/Square284x284Logo.png | Bin 0 -> 7737 bytes src-tauri/icons/Square30x30Logo.png | Bin 0 -> 903 bytes src-tauri/icons/Square310x310Logo.png | Bin 0 -> 8591 bytes src-tauri/icons/Square44x44Logo.png | Bin 0 -> 1299 bytes src-tauri/icons/Square71x71Logo.png | Bin 0 -> 2011 bytes src-tauri/icons/Square89x89Logo.png | Bin 0 -> 2468 bytes src-tauri/icons/StoreLogo.png | Bin 0 -> 1523 bytes src-tauri/icons/icon.icns | Bin 0 -> 98451 bytes src-tauri/icons/icon.ico | Bin 0 -> 86642 bytes src-tauri/icons/icon.png | Bin 0 -> 14183 bytes src-tauri/src/lib.rs | 14 +++ src-tauri/src/main.rs | 6 + src-tauri/tauri.conf.json | 35 ++++++ src/App.css | 116 ++++++++++++++++++ src/App.tsx | 51 ++++++++ src/assets/preact.svg | 1 + src/main.tsx | 4 + src/vite-env.d.ts | 1 + tsconfig.json | 26 ++++ tsconfig.node.json | 10 ++ vite.config.ts | 32 +++++ 45 files changed, 412 insertions(+), 248 deletions(-) delete mode 100644 .github/workflows/build.yaml create mode 100644 .vscode/extensions.json delete mode 100644 factorio-achievements-fixer.sln delete mode 100644 factorio-achievements-fixer/App.xaml delete mode 100644 factorio-achievements-fixer/App.xaml.cs delete mode 100644 factorio-achievements-fixer/AssemblyInfo.cs delete mode 100644 factorio-achievements-fixer/InitialWindow.xaml delete mode 100644 factorio-achievements-fixer/InitialWindow.xaml.cs delete mode 100644 factorio-achievements-fixer/factorio-achievements-fixer.csproj create mode 100644 index.html create mode 100644 package.json create mode 100644 public/tauri.svg create mode 100644 public/vite.svg create mode 100644 src-tauri/.gitignore create mode 100644 src-tauri/Cargo.toml create mode 100644 src-tauri/build.rs create mode 100644 src-tauri/capabilities/default.json create mode 100644 src-tauri/icons/128x128.png create mode 100644 src-tauri/icons/128x128@2x.png create mode 100644 src-tauri/icons/32x32.png create mode 100644 src-tauri/icons/Square107x107Logo.png create mode 100644 src-tauri/icons/Square142x142Logo.png create mode 100644 src-tauri/icons/Square150x150Logo.png create mode 100644 src-tauri/icons/Square284x284Logo.png create mode 100644 src-tauri/icons/Square30x30Logo.png create mode 100644 src-tauri/icons/Square310x310Logo.png create mode 100644 src-tauri/icons/Square44x44Logo.png create mode 100644 src-tauri/icons/Square71x71Logo.png create mode 100644 src-tauri/icons/Square89x89Logo.png create mode 100644 src-tauri/icons/StoreLogo.png create mode 100644 src-tauri/icons/icon.icns create mode 100644 src-tauri/icons/icon.ico create mode 100644 src-tauri/icons/icon.png create mode 100644 src-tauri/src/lib.rs create mode 100644 src-tauri/src/main.rs create mode 100644 src-tauri/tauri.conf.json create mode 100644 src/App.css create mode 100644 src/App.tsx create mode 100644 src/assets/preact.svg create mode 100644 src/main.tsx create mode 100644 src/vite-env.d.ts create mode 100644 tsconfig.json create mode 100644 tsconfig.node.json create mode 100644 vite.config.ts diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index bb8c585..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,43 +0,0 @@ -name: Build - -env: - SLN_PATH: factorio-achievements-fixer/ - -on: - workflow_dispatch: - push: - paths-ignore: - - "README.md" - - "LICENSE" - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Setup Dotnet - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - - - name: Install Application Dependencies - run: dotnet restore ${{ env.SLN_PATH }} - - - name: Build Application - run: dotnet publish ${{ env.SLN_PATH }} --no-restore - - - name: Get Version - id: get_version - run: | - VERSION=$(grep -oP '(?<=\[assembly: AssemblyVersion\(")[^"]+' ${{ env.SLN_PATH }}/AssemblyInfo.cs) - echo "result=$VERSION" >> $GITHUB_OUTPUT - - - name: Upload Artifact - uses: actions/upload-artifact@v4 - with: - name: factorio-achievements-fixer-${{ steps.get_version.outputs.result }} - if-no-files-found: error - path: ${{ env.SLN_PATH }}/bin/Release/net8.0-windows/win-x86/publish/factorio-achievements-fixer.exe diff --git a/.gitignore b/.gitignore index 7366976..4108b33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,24 @@ -.idea -bin/ -obj/ -/packages/ -riderModule.iml -/_ReSharper.Caches/ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..d4fef4e --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"] +} diff --git a/factorio-achievements-fixer.sln b/factorio-achievements-fixer.sln deleted file mode 100644 index 4b1b87b..0000000 --- a/factorio-achievements-fixer.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.9.34728.123 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "factorio-achievements-fixer", "factorio-achievements-fixer\factorio-achievements-fixer.csproj", "{52CBAB79-17D2-4BBF-98B2-4A19864C7FAF}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {52CBAB79-17D2-4BBF-98B2-4A19864C7FAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {52CBAB79-17D2-4BBF-98B2-4A19864C7FAF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {52CBAB79-17D2-4BBF-98B2-4A19864C7FAF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {52CBAB79-17D2-4BBF-98B2-4A19864C7FAF}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {970EF005-D589-4FEA-8466-86C65F557263} - EndGlobalSection -EndGlobal diff --git a/factorio-achievements-fixer/App.xaml b/factorio-achievements-fixer/App.xaml deleted file mode 100644 index 50e7915..0000000 --- a/factorio-achievements-fixer/App.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - diff --git a/factorio-achievements-fixer/App.xaml.cs b/factorio-achievements-fixer/App.xaml.cs deleted file mode 100644 index 1163219..0000000 --- a/factorio-achievements-fixer/App.xaml.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Configuration; -using System.Data; -using System.Windows; - -namespace factorio_achievements_fixer; - -/// -/// Interaction logic for App.xaml -/// -public partial class App : Application -{ -} \ No newline at end of file diff --git a/factorio-achievements-fixer/AssemblyInfo.cs b/factorio-achievements-fixer/AssemblyInfo.cs deleted file mode 100644 index 41fe54d..0000000 --- a/factorio-achievements-fixer/AssemblyInfo.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Reflection; -using System.Windows; - -[assembly: AssemblyVersion("0.1.0.0")] -[assembly: AssemblyFileVersion("0.1.0.0")] -[assembly: AssemblyProduct("Factorio Achievements Fixer")] -[assembly: AssemblyCopyright("Ryan Walters © 2024")] -[assembly: AssemblyTitle("Factorio Achievements Fixer")] - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] \ No newline at end of file diff --git a/factorio-achievements-fixer/InitialWindow.xaml b/factorio-achievements-fixer/InitialWindow.xaml deleted file mode 100644 index b4f9fcb..0000000 --- a/factorio-achievements-fixer/InitialWindow.xaml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - + +

{greetMsg}

+ + ); +} + +export default App; diff --git a/src/assets/preact.svg b/src/assets/preact.svg new file mode 100644 index 0000000..c7fda77 --- /dev/null +++ b/src/assets/preact.svg @@ -0,0 +1 @@ + diff --git a/src/main.tsx b/src/main.tsx new file mode 100644 index 0000000..99647f5 --- /dev/null +++ b/src/main.tsx @@ -0,0 +1,4 @@ +import { render } from "preact"; +import App from "./App"; + +render(, document.getElementById("root")!); diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts new file mode 100644 index 0000000..7d0ff9e --- /dev/null +++ b/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..4ea355c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }] +} diff --git a/tsconfig.node.json b/tsconfig.node.json new file mode 100644 index 0000000..165a9ba --- /dev/null +++ b/tsconfig.node.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000..63d31cc --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,32 @@ +import { defineConfig } from "vite"; +import preact from "@preact/preset-vite"; + +// @ts-expect-error process is a nodejs global +const host = process.env.TAURI_DEV_HOST; + +// https://vitejs.dev/config/ +export default defineConfig(async () => ({ + plugins: [preact()], + + // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build` + // + // 1. prevent vite from obscuring rust errors + clearScreen: false, + // 2. tauri expects a fixed port, fail if that port is not available + server: { + port: 1420, + strictPort: true, + host: host || false, + hmr: host + ? { + protocol: "ws", + host, + port: 1421, + } + : undefined, + watch: { + // 3. tell vite to ignore watching `src-tauri` + ignored: ["**/src-tauri/**"], + }, + }, +}));