[
  {
    "path": ".gitignore",
    "content": "node_modules\n.svelte-kit\n\ndist\nbuild\npackage\n\n.env\n.env.*\n*.local\n!.env.example\n\nyarn-error.log\npnpm-lock.yaml\n\n.DS_Store\n"
  },
  {
    "path": ".npmrc",
    "content": "engine-strict = true\n"
  },
  {
    "path": ".prettierrc",
    "content": "{\n\t\"svelteSortOrder\": \"scripts-markup-styles\",\n\t\"htmlWhitespaceSensitivity\": \"ignore\",\n\t\"trailingComma\": \"all\",\n\t\"requirePragma\": false,\n\t\"bracketSpacing\": true,\n\t\"singleQuote\": true,\n\t\"printWidth\": 100,\n\t\"useTabs\": true,\n\t\"tabWidth\": 4,\n\t\"semi\": true\n}\n"
  },
  {
    "path": ".vscode/extensions.json",
    "content": "{\n  \"recommendations\": [\"svelte.svelte-vscode\"]\n}\n"
  },
  {
    "path": ".vscode/settings.json",
    "content": "{\n  \"[svelte]\": {\n    \"editor.formatOnSave\": true,\n    \"editor.defaultFormatter\": \"svelte.svelte-vscode\"\n  }\n}\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2022 Braden Wiggins and contributors: https://github.com/fractalhq/sveltekit-electron/graphs/contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "<p align=\"center\">\n  <img src=\"static/sveltekit-electron.svg\" />\n</p>\n\n# Sveltekit + Electron\n\nMinimal [Sveltekit](https://github.com/sveltejs/kit#readme) + [Electron](https://www.electronjs.org/) starter template.\n\n<br />\n\n## Getting Started\n\nUnfortunately you must use `npm` as there are issues that arise when using `pnpm` or `yarn`\n\n|         |                                             |\n| ------- | ------------------------------------------- |\n| Clone   | · `npx degit fractalhq/sveltekit-electron ` |\n| Install | · `npm install`                             |\n| Develop | · `npm run dev`                             |\n| Build   | · `npm run build`                           |\n\nIn order to eliminate vulnerabilities caused by electron itself, please run `npm update` and `npm audit fix`. This will apply overrides.\n\n<br />\n\n<p align=\"center\">\n  <img src=\"screenshot.png\" />\n</p>\n\n## Recommended IDE Setup\n\n[VSCode](https://code.visualstudio.com/) + [Svelte for VSCode](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode)\n\n## Change Build Targets\n\nIn the scripts section of package.json you can update the `build:electron` command and change the flags to set the targets, by default it uses `-mwl` which is Mac, Windows, and Linux\n"
  },
  {
    "path": "build.config.json",
    "content": "{\n\t\"appId\": \"com.example.app\",\n\t\"productName\": \"Sveltekit Electron\",\n\t\"directories\": {\n\t\t\"output\": \"dist\"\n\t},\n\t\"files\": [\n\t\t\"src/electron.cjs\",\n\t\t\"src/preload.cjs\",\n\t\t{\n\t\t\t\"from\": \"build\",\n\t\t\t\"to\": \"\"\n\t\t}\n\t]\n}\n"
  },
  {
    "path": "globals.d.ts",
    "content": "/// <reference types=\"svelte\" />\n/// <reference types=\"vite/client\" />\n"
  },
  {
    "path": "jsconfig.json",
    "content": "{\n\t\"compilerOptions\": {\n\t\t\"baseUrl\": \".\",\n\t\t\"paths\": {\n\t\t\t\"$lib\": [\"src/lib\"],\n\t\t\t\"$lib/*\": [\"src/lib/*\"],\n\t\t\t\"/~/*\": [\"src/*\"]\n\t\t}\n\t},\n\t\"exclude\": [\"node_modules\", \"build\", \"dist\"]\n}\n"
  },
  {
    "path": "package.json",
    "content": "{\n\t\"name\": \"sveltekit-electron\",\n\t\"version\": \"0.0.1\",\n\t\"private\": true,\n\t\"description\": \"Minimal Sveltekit + Electron starter template.\",\n\t\"main\": \"src/electron.cjs\",\n\t\"type\": \"module\",\n\t\"author\": \"Braden Wiggins\",\n\t\"scripts\": {\n\t\t\"dev\": \"cross-env NODE_ENV=dev npm run dev:all\",\n\t\t\"dev:all\": \"concurrently -n=svelte,electron -c='#ff3e00',blue \\\"npm run dev:svelte\\\" \\\"npm run dev:electron\\\"\",\n\t\t\"dev:svelte\": \"vite dev\",\n\t\t\"dev:electron\": \"electron src/electron.cjs\",\n\t\t\"build\": \"cross-env NODE_ENV=production npm run build:svelte && npm run build:electron\",\n\t\t\"build:svelte\": \"vite build\",\n\t\t\"build:electron\": \"electron-builder -mwl --config build.config.json\"\n\t},\n\t\"engines\": {\n\t\t\"npm\": \">=7\",\n\t\t\"yarn\": \"use npm - https://github.com/FractalHQ/sveltekit-electron/issues/12#issuecomment-1068399385\"\n\t},\n\t\"browserslist\": [\n\t\t\"Chrome 89\"\n\t],\n\t\"dependencies\": {\n\t\t\"electron-context-menu\": \"^3.6.1\",\n\t\t\"electron-reloader\": \"^1.2.3\",\n\t\t\"electron-serve\": \"^1.1.0\",\n\t\t\"electron-window-state\": \"^5.0.3\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@sveltejs/adapter-static\": \"2.0.1\",\n\t\t\"@sveltejs/kit\": \"1.14.0\",\n\t\t\"@typescript-eslint/eslint-plugin\": \"^5.56.0\",\n\t\t\"@typescript-eslint/parser\": \"^5.56.0\",\n\t\t\"concurrently\": \"^7.6.0\",\n\t\t\"cross-env\": \"^7.0.3\",\n\t\t\"dotenv\": \"^16.0.3\",\n\t\t\"electron\": \"^23.2.0\",\n\t\t\"electron-builder\": \"^23.6.0\",\n\t\t\"electron-connect\": \"^0.6.3\",\n\t\t\"electron-packager\": \"^17.1.1\",\n\t\t\"electron-updater\": \"^5.3.0\",\n\t\t\"eslint\": \"^8.36.0\",\n\t\t\"eslint-config-prettier\": \"^8.8.0\",\n\t\t\"eslint-plugin-svelte3\": \"^4.0.0\",\n\t\t\"npm-run-all\": \"^4.1.5\",\n\t\t\"prettier\": \"^2.8.7\",\n\t\t\"prettier-plugin-svelte\": \"^2.10.0\",\n\t\t\"sass\": \"^1.60.0\",\n\t\t\"svelte\": \"^3.57.0\",\n\t\t\"svelte-check\": \"^3.1.4\",\n\t\t\"svelte-preprocess\": \"^5.0.3\",\n\t\t\"tslib\": \"^2.5.0\",\n\t\t\"typescript\": \"^4.9.4\",\n\t\t\"vite\": \"^4.0.4\"\n\t},\n\t\"overrides\": {\n\t\t\"electron\": {\n\t\t\t\"got\": \"^12.5.1\"\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/app.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n\t<head>\n\t\t<meta charset=\"utf-8\" />\n\t\t<link rel=\"icon\" href=\"/favicon.ico\" />\n\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n\t\t<title>Sveltekit + Electron</title>\n\t\t%sveltekit.head%\n\t</head>\n\t<body>\n\t\t<div id=\"svelte\">%sveltekit.body%</div>\n\t</body>\n</html>\n"
  },
  {
    "path": "src/electron.cjs",
    "content": "const windowStateManager = require('electron-window-state');\nconst { app, BrowserWindow, ipcMain } = require('electron');\nconst contextMenu = require('electron-context-menu');\nconst serve = require('electron-serve');\nconst path = require('path');\n\ntry {\n\trequire('electron-reloader')(module);\n} catch (e) {\n\tconsole.error(e);\n}\n\nconst serveURL = serve({ directory: '.' });\nconst port = process.env.PORT || 5173;\nconst dev = !app.isPackaged;\nlet mainWindow;\n\nfunction createWindow() {\n\tlet windowState = windowStateManager({\n\t\tdefaultWidth: 800,\n\t\tdefaultHeight: 600,\n\t});\n\n\tconst mainWindow = new BrowserWindow({\n\t\tbackgroundColor: 'whitesmoke',\n\t\ttitleBarStyle: 'hidden',\n\t\tautoHideMenuBar: true,\n\t\ttrafficLightPosition: {\n\t\t\tx: 17,\n\t\t\ty: 32,\n\t\t},\n\t\tminHeight: 450,\n\t\tminWidth: 500,\n\t\twebPreferences: {\n\t\t\tenableRemoteModule: true,\n\t\t\tcontextIsolation: true,\n\t\t\tnodeIntegration: true,\n\t\t\tspellcheck: false,\n\t\t\tdevTools: dev,\n\t\t\tpreload: path.join(__dirname, 'preload.cjs'),\n\t\t},\n\t\tx: windowState.x,\n\t\ty: windowState.y,\n\t\twidth: windowState.width,\n\t\theight: windowState.height,\n\t});\n\n\twindowState.manage(mainWindow);\n\n\tmainWindow.once('ready-to-show', () => {\n\t\tmainWindow.show();\n\t\tmainWindow.focus();\n\t});\n\n\tmainWindow.on('close', () => {\n\t\twindowState.saveState(mainWindow);\n\t});\n\n\treturn mainWindow;\n}\n\ncontextMenu({\n\tshowLookUpSelection: false,\n\tshowSearchWithGoogle: false,\n\tshowCopyImage: false,\n\tprepend: (defaultActions, params, browserWindow) => [\n\t\t{\n\t\t\tlabel: 'Make App 💻',\n\t\t},\n\t],\n});\n\nfunction loadVite(port) {\n\tmainWindow.loadURL(`http://localhost:${port}`).catch((e) => {\n\t\tconsole.log('Error loading URL, retrying', e);\n\t\tsetTimeout(() => {\n\t\t\tloadVite(port);\n\t\t}, 200);\n\t});\n}\n\nfunction createMainWindow() {\n\tmainWindow = createWindow();\n\tmainWindow.once('close', () => {\n\t\tmainWindow = null;\n\t});\n\n\tif (dev) loadVite(port);\n\telse serveURL(mainWindow);\n}\n\napp.once('ready', createMainWindow);\napp.on('activate', () => {\n\tif (!mainWindow) {\n\t\tcreateMainWindow();\n\t}\n});\napp.on('window-all-closed', () => {\n\tif (process.platform !== 'darwin') app.quit();\n});\n\nipcMain.on('to-main', (event, count) => {\n\treturn mainWindow.webContents.send('from-main', `next count is ${count + 1}`);\n});\n"
  },
  {
    "path": "src/global.d.ts",
    "content": "/// <reference types=\"@sveltejs/kit\" />\n/// <reference types=\"svelte\" />\n/// <reference types=\"vite/client\" />\ndeclare interface Window {\n\telectron: any;\n}\n"
  },
  {
    "path": "src/lib/Counter.svelte",
    "content": "<script lang=\"ts\">\n\timport { getStore } from '$lib/utils/hmr-stores';\n\n\texport let id: string;\n\texport let agent: string;\n\n\tconst count = getStore(id, 0);\n\n\tconst handleClick = () => {\n\t\t$count += 1;\n\t};\n\n\t$: if (window.electron) {\n\t\twindow.electron.send('to-main', $count);\n\t}\n</script>\n\n<button {id} on:click={handleClick}>\n\tSend Clicks to {agent}: {$count}\n</button>\n\n<style>\n\tbutton {\n\t\tfont-family: inherit;\n\t\tfont-size: inherit;\n\t\tpadding: 1em 2em;\n\t\tcolor: #ff3e00;\n\t\tbackground-color: rgba(255, 62, 0, 0.1);\n\t\tborder-radius: 2em;\n\t\tborder: 2px solid rgba(255, 62, 0, 0);\n\t\toutline: none;\n\t\twidth: 200px;\n\t\tfont-variant-numeric: tabular-nums;\n\t}\n\tbutton:focus {\n\t\tborder: 2px solid #ff3e00;\n\t}\n\tbutton:active {\n\t\tbackground-color: rgba(255, 62, 0, 0.2);\n\t}\n</style>\n"
  },
  {
    "path": "src/lib/Logo.svelte",
    "content": "<script>\n\timport { fly } from 'svelte/transition';\n\timport { onMount } from 'svelte';\n\tlet visible = false;\n\tonMount(() => (visible = true));\n</script>\n\n{#if visible}\n\t<img\n\t\tsrc=\"/sveltekit-electron.svg\"\n\t\talt=\"Svelte Logo\"\n\t\tdraggable=\"false\"\n\t\tin:fly={{ y: 100, duration: 1500 }}\n\t/>\n{:else}\n\t<div style=\"height: 16rem\" />\n{/if}\n\n<style>\n\timg {\n\t\theight: 16rem;\n\t\twidth: 16rem;\n\t\tuser-select: none;\n\t}\n</style>\n"
  },
  {
    "path": "src/lib/utils/hmr-stores.js",
    "content": "// Customized HMR-safe stores\n// Based off https://github.com/svitejs/svite/blob/ddec6b9/packages/playground/hmr/src/stores/hmr-stores.js\nimport { writable } from 'svelte/store';\n\n/**\n * @type { Record<string, import('svelte/store').Writable<any>> }\n */\nlet stores = {};\n\n/**\n * @template T\n * @param { string } id\n * @param { T } initialValue\n * @returns { import('svelte/store').Writable<T> }\n */\nexport function getStore(id, initialValue) {\n\treturn stores[id] || (stores[id] = writable(initialValue));\n}\n\n// preserve the store across HMR updates\nif (import.meta.hot) {\n\tif (import.meta.hot.data.stores) {\n\t\tstores = import.meta.hot.data.stores;\n\t}\n\timport.meta.hot.accept();\n\timport.meta.hot.dispose(() => {\n\t\timport.meta.hot.data.stores = stores;\n\t});\n}\n"
  },
  {
    "path": "src/preload.cjs",
    "content": "const { contextBridge, ipcRenderer } = require('electron');\n\ncontextBridge.exposeInMainWorld('electron', {\n\tsend: (channel, data) => {\n\t\tipcRenderer.send(channel, data);\n\t},\n\tsendSync: (channel, data) => {\n\t\tipcRenderer.sendSync(channel, data);\n\t},\n\treceive: (channel, func) => {\n\t\tipcRenderer.on(channel, (event, ...args) => func(...args));\n\t},\n});\n"
  },
  {
    "path": "src/routes/+layout.js",
    "content": "export const ssr = false;\n"
  },
  {
    "path": "src/routes/+layout.svelte",
    "content": "<script lang=\"ts\">\n\timport { onMount } from 'svelte';\n\n\tlet ready: boolean = false;\n\tonMount(() => (ready = true));\n</script>\n\n<div class=\"dragbar\" />\n\n{#if ready}\n\t<slot />\n{/if}\n\n<style>\n\t.dragbar {\n\t\t-webkit-app-region: drag;\n\t\tposition: absolute;\n\t\tz-index: 100;\n\t\theight: 40px;\n\t\twidth: 100%;\n\t}\n</style>\n"
  },
  {
    "path": "src/routes/+page.svelte",
    "content": "<script lang=\"ts\">\n\timport Counter from '$lib/Counter.svelte';\n\timport Logo from '$lib/Logo.svelte';\n\timport { browser } from '$app/environment';\n\n\tlet desktop: string;\n\n\tif (window.electron && browser) {\n\t\twindow.electron.receive('from-main', (data: any) => {\n\t\t\tdesktop = `Received Message \"${data}\" from Electron`;\n\t\t\tconsole.log(desktop);\n\t\t});\n\t}\n\n\tconst agent = window.electron ? 'Electron' : 'Browser';\n</script>\n\n<main>\n\t<Logo />\n\n\t<h1>Hello {agent}!</h1>\n\n\t<Counter id=\"0\" {agent} />\n\n\t{#if desktop}\n\t\t<br />\n\t\t<br />\n\t\t{desktop}\n\t{/if}\n</main>\n\n<style>\n\t:root {\n\t\tfont-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,\n\t\t\tCantarell, 'Open Sans', 'Helvetica Neue', sans-serif;\n\t}\n\n\t:global(body) {\n\t\tmargin: 0;\n\t\tpadding: 0;\n\t}\n\n\tmain {\n\t\tpadding: 2em 1em 1em 1em;\n\t\ttext-align: center;\n\t\tanimation: fade 1s;\n\t\tmargin: 0 auto;\n\t}\n\n\t@keyframes fade {\n\t\tfrom {\n\t\t\topacity: 0;\n\t\t}\n\t\tto {\n\t\t\topacity: 1;\n\t\t}\n\t}\n</style>\n"
  },
  {
    "path": "svelte.config.js",
    "content": "import adapter from '@sveltejs/adapter-static';\nimport preprocess from 'svelte-preprocess';\n\n/** @type {import('@sveltejs/kit').Config} */\nconst config = {\n\t// Consult https://github.com/sveltejs/svelte-preprocess\n\t// for more information about preprocessors\n\tpreprocess: preprocess(),\n\n\tkit: {\n\t\tadapter: adapter({\n\t\t\tfallback: 'index.html',\n\t\t}),\n\t\tprerender: { entries: [] },\n\t},\n};\n\nexport default config;\n"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n\t\"extends\": \"./.svelte-kit/tsconfig.json\",\n\t\"compilerOptions\": {\n\t\t\"module\": \"esnext\",\n\t\t\"target\": \"es2020\",\n\t\t\"moduleResolution\": \"node\",\n\t\t\"strict\": true,\n\t\t\"types\": [\"vite/client\", \"node\"],\n\t\t\"typeRoots\": [\"node_modules/@types\"],\n\t\t\"lib\": [\"ESNext\"],\n\t\t/**\n\t\t\tsvelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript\n\t\t\tto enforce using \\`import type\\` instead of \\`import\\` for Types.\n\t\t*/\n\t\t\"importsNotUsedAsValues\": \"error\",\n\t\t\"isolatedModules\": true,\n\t\t/**\n\t\t\tTo have warnings/errors of the Svelte compiler at the correct position,\n\t\t\tenable source maps by default.\n\t\t*/\n\t\t\"sourceMap\": true,\n\t\t\"esModuleInterop\": true,\n\t\t\"skipLibCheck\": true,\n\t\t\"forceConsistentCasingInFileNames\": true,\n\t\t\"baseUrl\": \".\",\n\t\t\"allowJs\": true,\n\t\t\"checkJs\": false,\n\t\t\"paths\": {\n\t\t\t\"$lib\": [\"src/lib\"],\n\t\t\t\"$lib/*\": [\"src/lib/*\"],\n\t\t\t\"$app/*\": [\".svelte/dev/runtime/app/*\", \".svelte/build/runtime/app/*\"]\n\t\t}\n\t},\n\t\"include\": [\"src/**/*.d.ts\", \"src/**/*.ts\", \"src/**/*.svelte\", \"src/electron.js\"]\n}\n"
  },
  {
    "path": "vite.config.js",
    "content": "import { sveltekit } from '@sveltejs/kit/vite';\n\nconst config = {\n\tplugins: [sveltekit()],\n};\n\nexport default config;\n"
  }
]