electron-vite-react-template 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +15 -0
- package/.github/workflows/ci.yml +77 -0
- package/CONTRIBUTING.md +58 -0
- package/LICENSE +21 -0
- package/README.md +157 -0
- package/SECURITY.md +29 -0
- package/docs/PROJECT.md +249 -0
- package/electron.vite.config.ts +46 -0
- package/eslint.config.js +28 -0
- package/package.json +57 -0
- package/postcss.config.js +6 -0
- package/src/main/index.ts +110 -0
- package/src/preload/index.ts +33 -0
- package/src/renderer/env.d.ts +16 -0
- package/src/renderer/index.html +16 -0
- package/src/renderer/src/components/mode-toggle.tsx +31 -0
- package/src/renderer/src/components/theme-provider.tsx +140 -0
- package/src/renderer/src/components/ui/button.tsx +50 -0
- package/src/renderer/src/components/ui/dropdown-menu.tsx +188 -0
- package/src/renderer/src/components/use-theme.ts +12 -0
- package/src/renderer/src/hooks/use-sample.ts +7 -0
- package/src/renderer/src/i18n/index.ts +27 -0
- package/src/renderer/src/i18n/locales/en.json +8 -0
- package/src/renderer/src/i18n/locales/fr.json +8 -0
- package/src/renderer/src/index.css +59 -0
- package/src/renderer/src/lib/utils.ts +6 -0
- package/src/renderer/src/main.tsx +66 -0
- package/src/renderer/src/stores/app-store.ts +20 -0
- package/tailwind.config.js +53 -0
- package/template/.github/workflows/ci.yml +77 -0
- package/template/electron.vite.config.ts +46 -0
- package/template/eslint.config.js +28 -0
- package/template/package.json +31 -0
- package/template/postcss.config.js +6 -0
- package/template/src/main/index.ts +110 -0
- package/template/src/preload/index.ts +33 -0
- package/template/src/renderer/env.d.ts +16 -0
- package/template/src/renderer/index.html +16 -0
- package/template/src/renderer/src/components/mode-toggle.tsx +31 -0
- package/template/src/renderer/src/components/theme-provider.tsx +140 -0
- package/template/src/renderer/src/components/ui/button.tsx +50 -0
- package/template/src/renderer/src/components/ui/dropdown-menu.tsx +188 -0
- package/template/src/renderer/src/components/use-theme.ts +12 -0
- package/template/src/renderer/src/hooks/use-sample.ts +7 -0
- package/template/src/renderer/src/i18n/index.ts +27 -0
- package/template/src/renderer/src/i18n/locales/en.json +8 -0
- package/template/src/renderer/src/i18n/locales/fr.json +8 -0
- package/template/src/renderer/src/index.css +59 -0
- package/template/src/renderer/src/lib/utils.ts +6 -0
- package/template/src/renderer/src/main.tsx +66 -0
- package/template/src/renderer/src/stores/app-store.ts +20 -0
- package/template/tailwind.config.js +53 -0
- package/template/template-package.json +57 -0
- package/template/tsconfig.json +7 -0
- package/template/tsconfig.node.json +20 -0
- package/template/tsconfig.web.json +25 -0
- package/template/vitest.config.ts +17 -0
- package/tests/renderer/sample.test.ts +7 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +20 -0
- package/tsconfig.web.json +25 -0
- package/vitest.config.ts +17 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import i18n from 'i18next'
|
|
2
|
+
import { initReactI18next } from 'react-i18next'
|
|
3
|
+
import en from './locales/en.json'
|
|
4
|
+
import fr from './locales/fr.json'
|
|
5
|
+
|
|
6
|
+
// Get system locale
|
|
7
|
+
const getSystemLocale = (): string => {
|
|
8
|
+
if (typeof navigator !== 'undefined') {
|
|
9
|
+
const lang = navigator.language || 'en'
|
|
10
|
+
return lang.split('-')[0]
|
|
11
|
+
}
|
|
12
|
+
return 'en'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
i18n.use(initReactI18next).init({
|
|
16
|
+
resources: {
|
|
17
|
+
en: { translation: en },
|
|
18
|
+
fr: { translation: fr }
|
|
19
|
+
},
|
|
20
|
+
lng: getSystemLocale(),
|
|
21
|
+
fallbackLng: 'en',
|
|
22
|
+
interpolation: {
|
|
23
|
+
escapeValue: false
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export default i18n
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
@tailwind base;
|
|
2
|
+
@tailwind components;
|
|
3
|
+
@tailwind utilities;
|
|
4
|
+
|
|
5
|
+
@layer base {
|
|
6
|
+
:root {
|
|
7
|
+
--background: 0 0% 100%;
|
|
8
|
+
--foreground: 222.2 84% 4.9%;
|
|
9
|
+
--card: 0 0% 100%;
|
|
10
|
+
--card-foreground: 222.2 84% 4.9%;
|
|
11
|
+
--popover: 0 0% 100%;
|
|
12
|
+
--popover-foreground: 222.2 84% 4.9%;
|
|
13
|
+
--primary: 222.2 47.4% 11.2%;
|
|
14
|
+
--primary-foreground: 210 40% 98%;
|
|
15
|
+
--secondary: 210 40% 96.1%;
|
|
16
|
+
--secondary-foreground: 222.2 47.4% 11.2%;
|
|
17
|
+
--muted: 210 40% 96.1%;
|
|
18
|
+
--muted-foreground: 215.4 16.3% 46.9%;
|
|
19
|
+
--accent: 210 40% 96.1%;
|
|
20
|
+
--accent-foreground: 222.2 47.4% 11.2%;
|
|
21
|
+
--destructive: 0 84.2% 60.2%;
|
|
22
|
+
--destructive-foreground: 210 40% 98%;
|
|
23
|
+
--border: 214.3 31.8% 91.4%;
|
|
24
|
+
--input: 214.3 31.8% 91.4%;
|
|
25
|
+
--ring: 222.2 84% 4.9%;
|
|
26
|
+
--radius: 0.5rem;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.dark {
|
|
30
|
+
--background: 222.2 84% 4.9%;
|
|
31
|
+
--foreground: 210 40% 98%;
|
|
32
|
+
--card: 222.2 84% 4.9%;
|
|
33
|
+
--card-foreground: 210 40% 98%;
|
|
34
|
+
--popover: 222.2 84% 4.9%;
|
|
35
|
+
--popover-foreground: 210 40% 98%;
|
|
36
|
+
--primary: 210 40% 98%;
|
|
37
|
+
--primary-foreground: 222.2 47.4% 11.2%;
|
|
38
|
+
--secondary: 217.2 32.6% 17.5%;
|
|
39
|
+
--secondary-foreground: 210 40% 98%;
|
|
40
|
+
--muted: 217.2 32.6% 17.5%;
|
|
41
|
+
--muted-foreground: 215 20.2% 65.1%;
|
|
42
|
+
--accent: 217.2 32.6% 17.5%;
|
|
43
|
+
--accent-foreground: 210 40% 98%;
|
|
44
|
+
--destructive: 0 62.8% 30.6%;
|
|
45
|
+
--destructive-foreground: 210 40% 98%;
|
|
46
|
+
--border: 217.2 32.6% 17.5%;
|
|
47
|
+
--input: 217.2 32.6% 17.5%;
|
|
48
|
+
--ring: 212.7 26.8% 83.9%;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@layer base {
|
|
53
|
+
* {
|
|
54
|
+
@apply border-border;
|
|
55
|
+
}
|
|
56
|
+
body {
|
|
57
|
+
@apply bg-background text-foreground;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import './index.css'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import ReactDOM from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { ThemeProvider } from './components/theme-provider'
|
|
6
|
+
import { RouterProvider, createRouter, createRootRoute, createRoute, Outlet } from '@tanstack/react-router'
|
|
7
|
+
import './i18n'
|
|
8
|
+
|
|
9
|
+
const queryClient = new QueryClient({
|
|
10
|
+
defaultOptions: {
|
|
11
|
+
queries: {
|
|
12
|
+
staleTime: 5 * 60 * 1000
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// Define routes
|
|
18
|
+
const rootRoute = createRootRoute({
|
|
19
|
+
component: () => (
|
|
20
|
+
<div className="min-h-screen bg-background text-foreground">
|
|
21
|
+
<header className="border-b">
|
|
22
|
+
<div className="container mx-auto flex items-center justify-between p-4">
|
|
23
|
+
<h1 className="text-2xl font-bold">Electron Vite React Template</h1>
|
|
24
|
+
</div>
|
|
25
|
+
</header>
|
|
26
|
+
<main className="container mx-auto p-4">
|
|
27
|
+
<Outlet />
|
|
28
|
+
</main>
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const indexRoute = createRoute({
|
|
34
|
+
getParentRoute: () => rootRoute,
|
|
35
|
+
path: '/',
|
|
36
|
+
component: function Index() {
|
|
37
|
+
return <p>Welcome to your Electron app!</p>
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const routeTree = rootRoute.addChildren([indexRoute])
|
|
42
|
+
|
|
43
|
+
const router = createRouter({
|
|
44
|
+
routeTree,
|
|
45
|
+
context: {
|
|
46
|
+
queryClient
|
|
47
|
+
},
|
|
48
|
+
defaultPreload: 'intent'
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
// Declare router for type-safe routing
|
|
52
|
+
declare module '@tanstack/react-router' {
|
|
53
|
+
interface Register {
|
|
54
|
+
router: typeof router
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
59
|
+
<React.StrictMode>
|
|
60
|
+
<QueryClientProvider client={queryClient}>
|
|
61
|
+
<ThemeProvider defaultTheme="system" storageKey="vite-ui-theme">
|
|
62
|
+
<RouterProvider router={router} />
|
|
63
|
+
</ThemeProvider>
|
|
64
|
+
</QueryClientProvider>
|
|
65
|
+
</React.StrictMode>
|
|
66
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { create } from 'zustand'
|
|
2
|
+
import { persist } from 'zustand/middleware'
|
|
3
|
+
|
|
4
|
+
interface AppState {
|
|
5
|
+
// User preferences
|
|
6
|
+
language: string
|
|
7
|
+
setLanguage: (language: string) => void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const useAppStore = create<AppState>()(
|
|
11
|
+
persist(
|
|
12
|
+
(set) => ({
|
|
13
|
+
language: 'en',
|
|
14
|
+
setLanguage: (language) => set({ language })
|
|
15
|
+
}),
|
|
16
|
+
{
|
|
17
|
+
name: 'app-storage'
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** @type {import('tailwindcss').Config} */
|
|
2
|
+
export default {
|
|
3
|
+
darkMode: ['class'],
|
|
4
|
+
content: [
|
|
5
|
+
'./src/renderer/index.html',
|
|
6
|
+
'./src/renderer/src/**/*.{js,ts,jsx,tsx}'
|
|
7
|
+
],
|
|
8
|
+
theme: {
|
|
9
|
+
extend: {
|
|
10
|
+
colors: {
|
|
11
|
+
border: 'hsl(var(--border))',
|
|
12
|
+
input: 'hsl(var(--input))',
|
|
13
|
+
ring: 'hsl(var(--ring))',
|
|
14
|
+
background: 'hsl(var(--background))',
|
|
15
|
+
foreground: 'hsl(var(--foreground))',
|
|
16
|
+
primary: {
|
|
17
|
+
DEFAULT: 'hsl(var(--primary))',
|
|
18
|
+
foreground: 'hsl(var(--primary-foreground))'
|
|
19
|
+
},
|
|
20
|
+
secondary: {
|
|
21
|
+
DEFAULT: 'hsl(var(--secondary))',
|
|
22
|
+
foreground: 'hsl(var(--secondary-foreground))'
|
|
23
|
+
},
|
|
24
|
+
destructive: {
|
|
25
|
+
DEFAULT: 'hsl(var(--destructive))',
|
|
26
|
+
foreground: 'hsl(var(--destructive-foreground))'
|
|
27
|
+
},
|
|
28
|
+
muted: {
|
|
29
|
+
DEFAULT: 'hsl(var(--muted))',
|
|
30
|
+
foreground: 'hsl(var(--muted-foreground))'
|
|
31
|
+
},
|
|
32
|
+
accent: {
|
|
33
|
+
DEFAULT: 'hsl(var(--accent))',
|
|
34
|
+
foreground: 'hsl(var(--accent-foreground))'
|
|
35
|
+
},
|
|
36
|
+
popover: {
|
|
37
|
+
DEFAULT: 'hsl(var(--popover))',
|
|
38
|
+
foreground: 'hsl(var(--popover-foreground))'
|
|
39
|
+
},
|
|
40
|
+
card: {
|
|
41
|
+
DEFAULT: 'hsl(var(--card))',
|
|
42
|
+
foreground: 'hsl(var(--card-foreground))'
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
borderRadius: {
|
|
46
|
+
lg: 'var(--radius)',
|
|
47
|
+
md: 'calc(var(--radius) - 2px)',
|
|
48
|
+
sm: 'calc(var(--radius) - 4px)'
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
plugins: []
|
|
53
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, develop]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main, develop]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout code
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Setup pnpm
|
|
17
|
+
uses: pnpm/action-setup@v4
|
|
18
|
+
with:
|
|
19
|
+
version: 9
|
|
20
|
+
|
|
21
|
+
- name: Setup Node.js
|
|
22
|
+
uses: actions/setup-node@v4
|
|
23
|
+
with:
|
|
24
|
+
node-version: 20
|
|
25
|
+
cache: 'pnpm'
|
|
26
|
+
|
|
27
|
+
- name: Install dependencies
|
|
28
|
+
run: pnpm install --frozen-lockfile
|
|
29
|
+
|
|
30
|
+
- name: Run linter
|
|
31
|
+
run: pnpm lint
|
|
32
|
+
|
|
33
|
+
typecheck:
|
|
34
|
+
runs-on: ubuntu-latest
|
|
35
|
+
steps:
|
|
36
|
+
- name: Checkout code
|
|
37
|
+
uses: actions/checkout@v4
|
|
38
|
+
|
|
39
|
+
- name: Setup pnpm
|
|
40
|
+
uses: pnpm/action-setup@v4
|
|
41
|
+
with:
|
|
42
|
+
version: 9
|
|
43
|
+
|
|
44
|
+
- name: Setup Node.js
|
|
45
|
+
uses: actions/setup-node@v4
|
|
46
|
+
with:
|
|
47
|
+
node-version: 20
|
|
48
|
+
cache: 'pnpm'
|
|
49
|
+
|
|
50
|
+
- name: Install dependencies
|
|
51
|
+
run: pnpm install --frozen-lockfile
|
|
52
|
+
|
|
53
|
+
- name: Run typecheck
|
|
54
|
+
run: pnpm typecheck
|
|
55
|
+
|
|
56
|
+
test:
|
|
57
|
+
runs-on: ubuntu-latest
|
|
58
|
+
steps:
|
|
59
|
+
- name: Checkout code
|
|
60
|
+
uses: actions/checkout@v4
|
|
61
|
+
|
|
62
|
+
- name: Setup pnpm
|
|
63
|
+
uses: pnpm/action-setup@v4
|
|
64
|
+
with:
|
|
65
|
+
version: 9
|
|
66
|
+
|
|
67
|
+
- name: Setup Node.js
|
|
68
|
+
uses: actions/setup-node@v4
|
|
69
|
+
with:
|
|
70
|
+
node-version: 20
|
|
71
|
+
cache: 'pnpm'
|
|
72
|
+
|
|
73
|
+
- name: Install dependencies
|
|
74
|
+
run: pnpm install --frozen-lockfile
|
|
75
|
+
|
|
76
|
+
- name: Run tests
|
|
77
|
+
run: pnpm test
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { resolve } from 'path'
|
|
2
|
+
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
|
|
3
|
+
import react from '@vitejs/plugin-react'
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
main: {
|
|
7
|
+
plugins: [externalizeDepsPlugin()],
|
|
8
|
+
build: {
|
|
9
|
+
rollupOptions: {
|
|
10
|
+
input: {
|
|
11
|
+
index: resolve(__dirname, 'src/main/index.ts')
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
preload: {
|
|
17
|
+
plugins: [externalizeDepsPlugin()],
|
|
18
|
+
build: {
|
|
19
|
+
rollupOptions: {
|
|
20
|
+
input: {
|
|
21
|
+
index: resolve(__dirname, 'src/preload/index.ts')
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
renderer: {
|
|
27
|
+
root: resolve(__dirname, 'src/renderer'),
|
|
28
|
+
server: {
|
|
29
|
+
port: 8888,
|
|
30
|
+
host: '127.0.0.1'
|
|
31
|
+
},
|
|
32
|
+
build: {
|
|
33
|
+
rollupOptions: {
|
|
34
|
+
input: {
|
|
35
|
+
index: resolve(__dirname, 'src/renderer/index.html')
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
plugins: [react()],
|
|
40
|
+
resolve: {
|
|
41
|
+
alias: {
|
|
42
|
+
'@': resolve(__dirname, 'src/renderer/src')
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import js from '@eslint/js'
|
|
2
|
+
import globals from 'globals'
|
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks'
|
|
4
|
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
|
5
|
+
import tseslint from 'typescript-eslint'
|
|
6
|
+
|
|
7
|
+
export default tseslint.config(
|
|
8
|
+
{ ignores: ['dist', 'out', 'node_modules'] },
|
|
9
|
+
{
|
|
10
|
+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
|
11
|
+
files: ['**/*.{ts,tsx}'],
|
|
12
|
+
languageOptions: {
|
|
13
|
+
ecmaVersion: 2020,
|
|
14
|
+
globals: globals.browser
|
|
15
|
+
},
|
|
16
|
+
plugins: {
|
|
17
|
+
'react-hooks': reactHooks,
|
|
18
|
+
'react-refresh': reactRefresh
|
|
19
|
+
},
|
|
20
|
+
rules: {
|
|
21
|
+
...reactHooks.configs.recommended.rules,
|
|
22
|
+
'react-refresh/only-export-components': [
|
|
23
|
+
'warn',
|
|
24
|
+
{ allowConstantExport: true }
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nesalia/template-electron-vite-react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Desktop app template with Electron, Vite, React, TypeScript",
|
|
5
|
+
"nesalia": {
|
|
6
|
+
"id": "electron-vite-react",
|
|
7
|
+
"displayName": "Electron + Vite + React",
|
|
8
|
+
"description": "Desktop application template with Electron, Vite, React, TypeScript, Tailwind CSS, shadcn/ui, i18n, and TanStack",
|
|
9
|
+
"tags": ["electron", "desktop", "react", "vite", "typescript", "tailwind"]
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"templatePackageJson": {
|
|
15
|
+
"name": "{{name}}",
|
|
16
|
+
"description": "Electron + Vite + React template with TypeScript",
|
|
17
|
+
"main": "./out/main/index.js",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"author": "Nesalia",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"scripts": {
|
|
22
|
+
"dev": "electron-vite dev",
|
|
23
|
+
"build": "electron-vite build",
|
|
24
|
+
"preview": "electron-vite preview",
|
|
25
|
+
"lint": "eslint .",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:ui": "vitest"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { app, shell, BrowserWindow, nativeTheme, ipcMain } from 'electron'
|
|
2
|
+
import { join } from 'path'
|
|
3
|
+
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
|
4
|
+
import log from 'electron-log/main.js'
|
|
5
|
+
|
|
6
|
+
// Initialize logging
|
|
7
|
+
log.initialize()
|
|
8
|
+
log.transports.file.level = 'info'
|
|
9
|
+
log.transports.console.level = 'debug'
|
|
10
|
+
|
|
11
|
+
// Log app start
|
|
12
|
+
log.info('Application starting...')
|
|
13
|
+
log.info(`Electron version: ${process.versions.electron}`)
|
|
14
|
+
log.info(`Chrome version: ${process.versions.chrome}`)
|
|
15
|
+
log.info(`Node version: ${process.versions.node}`)
|
|
16
|
+
|
|
17
|
+
function createWindow(): void {
|
|
18
|
+
log.info('Creating main window...')
|
|
19
|
+
|
|
20
|
+
const mainWindow = new BrowserWindow({
|
|
21
|
+
width: 1200,
|
|
22
|
+
height: 800,
|
|
23
|
+
minWidth: 800,
|
|
24
|
+
minHeight: 600,
|
|
25
|
+
show: false,
|
|
26
|
+
autoHideMenuBar: false,
|
|
27
|
+
webPreferences: {
|
|
28
|
+
preload: join(__dirname, '../preload/index.js'),
|
|
29
|
+
sandbox: false,
|
|
30
|
+
contextIsolation: true,
|
|
31
|
+
nodeIntegration: false
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
mainWindow.on('ready-to-show', () => {
|
|
36
|
+
log.info('Window ready to show')
|
|
37
|
+
mainWindow.show()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
mainWindow.webContents.setWindowOpenHandler((details) => {
|
|
41
|
+
shell.openExternal(details.url)
|
|
42
|
+
return { action: 'deny' }
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// Load the app
|
|
46
|
+
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
|
47
|
+
log.info(`Loading dev URL: ${process.env['ELECTRON_RENDERER_URL']}`)
|
|
48
|
+
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
|
49
|
+
} else {
|
|
50
|
+
log.info('Loading production build')
|
|
51
|
+
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Listen for system theme changes
|
|
56
|
+
nativeTheme.on('updated', () => {
|
|
57
|
+
const theme = nativeTheme.shouldUseDarkColors ? 'dark' : 'light'
|
|
58
|
+
log.info(`System theme changed to: ${theme}`)
|
|
59
|
+
// Broadcast to all windows
|
|
60
|
+
BrowserWindow.getAllWindows().forEach((window) => {
|
|
61
|
+
window.webContents.send('theme-changed', theme)
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
// Handle uncaught exceptions
|
|
66
|
+
process.on('uncaughtException', (error) => {
|
|
67
|
+
log.error('Uncaught exception:', error)
|
|
68
|
+
app.quit()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
process.on('unhandledRejection', (reason) => {
|
|
72
|
+
log.error('Unhandled rejection:', reason)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
// App lifecycle
|
|
76
|
+
app.whenReady().then(() => {
|
|
77
|
+
log.info('App ready')
|
|
78
|
+
|
|
79
|
+
// Set app user model id for windows
|
|
80
|
+
electronApp.setAppUserModelId('com.nesalia.electron-vite-react')
|
|
81
|
+
|
|
82
|
+
// Default open or close DevTools by F12 in development
|
|
83
|
+
// and ignore CommandOrControl + R in production
|
|
84
|
+
app.on('browser-window-created', (_, window) => {
|
|
85
|
+
optimizer.watchWindowShortcuts(window)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
createWindow()
|
|
89
|
+
|
|
90
|
+
app.on('activate', () => {
|
|
91
|
+
// On macOS it's common to re-create a window in the app
|
|
92
|
+
// when the dock icon is clicked and there are no other windows open
|
|
93
|
+
if (BrowserWindow.getAllWindows().length === 0) {
|
|
94
|
+
createWindow()
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// Quit when all windows are closed, except on macOS
|
|
100
|
+
app.on('window-all-closed', () => {
|
|
101
|
+
log.info('All windows closed')
|
|
102
|
+
if (process.platform !== 'darwin') {
|
|
103
|
+
app.quit()
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
// IPC handlers for theme
|
|
108
|
+
ipcMain.handle('get-system-theme', () => {
|
|
109
|
+
return nativeTheme.shouldUseDarkColors ? 'dark' : 'light'
|
|
110
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { contextBridge, ipcRenderer } from 'electron'
|
|
2
|
+
import { electronAPI } from '@electron-toolkit/preload'
|
|
3
|
+
|
|
4
|
+
// Custom APIs for renderer
|
|
5
|
+
const api = {
|
|
6
|
+
// Theme
|
|
7
|
+
getSystemTheme: (): Promise<'dark' | 'light'> => ipcRenderer.invoke('get-system-theme'),
|
|
8
|
+
onThemeChange: (callback: (theme: 'dark' | 'light') => void): (() => void) => {
|
|
9
|
+
const handler = (_event: Electron.IpcRendererEvent, theme: 'dark' | 'light'): void => {
|
|
10
|
+
callback(theme)
|
|
11
|
+
}
|
|
12
|
+
ipcRenderer.on('theme-changed', handler)
|
|
13
|
+
return () => {
|
|
14
|
+
ipcRenderer.removeListener('theme-changed', handler)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Use `contextBridge` APIs to expose Electron APIs to
|
|
20
|
+
// renderer only if context isolation is enabled
|
|
21
|
+
if (process.contextIsolated) {
|
|
22
|
+
try {
|
|
23
|
+
contextBridge.exposeInMainWorld('electron', electronAPI)
|
|
24
|
+
contextBridge.exposeInMainWorld('api', api)
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(error)
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
// @ts-expect-error (define in dts)
|
|
30
|
+
window.electron = electronAPI
|
|
31
|
+
// @ts-expect-error (define in dts)
|
|
32
|
+
window.api = api
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
interface Window {
|
|
4
|
+
electron: {
|
|
5
|
+
ipcRenderer: {
|
|
6
|
+
send: (channel: string, ...args: unknown[]) => void
|
|
7
|
+
on: (channel: string, func: (...args: unknown[]) => void) => void
|
|
8
|
+
removeListener: (channel: string, func: (...args: unknown[]) => void) => void
|
|
9
|
+
invoke: <T = unknown>(channel: string, ...args: unknown[]) => Promise<T>
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
api: {
|
|
13
|
+
getSystemTheme: () => Promise<'dark' | 'light'>
|
|
14
|
+
onThemeChange: (callback: (theme: 'dark' | 'light') => void) => () => void
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<meta
|
|
7
|
+
http-equiv="Content-Security-Policy"
|
|
8
|
+
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'"
|
|
9
|
+
/>
|
|
10
|
+
<title>Electron Vite React Template</title>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<div id="root"></div>
|
|
14
|
+
<script type="module" src="./src/main.tsx"></script>
|
|
15
|
+
</body>
|
|
16
|
+
</html>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Moon, Sun } from 'lucide-react'
|
|
2
|
+
|
|
3
|
+
import { Button } from './ui/button'
|
|
4
|
+
import {
|
|
5
|
+
DropdownMenu,
|
|
6
|
+
DropdownMenuContent,
|
|
7
|
+
DropdownMenuItem,
|
|
8
|
+
DropdownMenuTrigger
|
|
9
|
+
} from './ui/dropdown-menu'
|
|
10
|
+
import { useTheme } from './use-theme'
|
|
11
|
+
|
|
12
|
+
export function ModeToggle(): JSX.Element {
|
|
13
|
+
const { setTheme } = useTheme()
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<DropdownMenu>
|
|
17
|
+
<DropdownMenuTrigger asChild>
|
|
18
|
+
<Button variant="outline" size="icon" className="relative">
|
|
19
|
+
<Sun className="h-[1.2rem] w-[1.2rem] scale-100 rotate-0 transition-all dark:scale-0 dark:-rotate-90" />
|
|
20
|
+
<Moon className="absolute h-[1.2rem] w-[1.2rem] scale-0 rotate-90 transition-all dark:scale-100 dark:rotate-0" />
|
|
21
|
+
<span className="sr-only">Toggle theme</span>
|
|
22
|
+
</Button>
|
|
23
|
+
</DropdownMenuTrigger>
|
|
24
|
+
<DropdownMenuContent align="end">
|
|
25
|
+
<DropdownMenuItem onClick={() => setTheme('light')}>Light</DropdownMenuItem>
|
|
26
|
+
<DropdownMenuItem onClick={() => setTheme('dark')}>Dark</DropdownMenuItem>
|
|
27
|
+
<DropdownMenuItem onClick={() => setTheme('system')}>System</DropdownMenuItem>
|
|
28
|
+
</DropdownMenuContent>
|
|
29
|
+
</DropdownMenu>
|
|
30
|
+
)
|
|
31
|
+
}
|