diff --git a/.github/workflows/smoke-tests-source.yml b/.github/workflows/smoke-tests-source.yml index ef2b82c53..4bdc62493 100644 --- a/.github/workflows/smoke-tests-source.yml +++ b/.github/workflows/smoke-tests-source.yml @@ -76,7 +76,7 @@ jobs: run: cargo build env: TAURI_DIST_DIR: ../../test/fixture/dist - TAURI_DIR: ../test/fixture + TAURI_DIR: ../test/fixture/src-tauri - run: cargo install --path ./cli/tauri-cli --force - name: install cli deps via yarn run: | diff --git a/.github/workflows/test-on-pr.yml b/.github/workflows/test-on-pr.yml index c0fc56376..4abcbf0a4 100644 --- a/.github/workflows/test-on-pr.yml +++ b/.github/workflows/test-on-pr.yml @@ -30,7 +30,7 @@ jobs: cargo build env: TAURI_DIST_DIR: ../../test/fixture/dist - TAURI_DIR: ../test/fixture/ + TAURI_DIR: ../test/fixture/src-tauri build-tauri-bundler: runs-on: ${{ matrix.platform }} diff --git a/cli/tauri.js/.gitignore b/cli/tauri.js/.gitignore index 4a9ebc4dd..9c6a313d8 100644 --- a/cli/tauri.js/.gitignore +++ b/cli/tauri.js/.gitignore @@ -71,7 +71,7 @@ config.json target -# doing this because of how our tests currently (naively) drop the tauri.conf.js in that folder +# doing this because of how our tests currently (naively) drop the tauri.conf.json in that folder # todo: needs a proper fic -tauri.conf.js +tauri.conf.json src-tauri \ No newline at end of file diff --git a/cli/tauri.js/bin/tauri-init.js b/cli/tauri.js/bin/tauri-init.js index f4f84b5f6..f514e5047 100644 --- a/cli/tauri.js/bin/tauri-init.js +++ b/cli/tauri.js/bin/tauri-init.js @@ -25,7 +25,7 @@ const argv = parseArgs(process.argv.slice(2), { if (argv.help) { console.log(` Description - Inits the Tauri template. If Tauri cannot find the tauri.conf.js + Inits the Tauri template. If Tauri cannot find the tauri.conf.json it will create one. Usage $ tauri init diff --git a/cli/tauri.js/src/api/build.ts b/cli/tauri.js/src/api/build.ts index 6a3c9570f..40e8423eb 100644 --- a/cli/tauri.js/src/api/build.ts +++ b/cli/tauri.js/src/api/build.ts @@ -1,9 +1,8 @@ import { TauriConfig } from 'types' import merge from 'webpack-merge' import * as entry from '../entry' -import * as generator from '../generator' import { tauriDir } from '../helpers/app-paths' -import getTauriConfig from '../helpers/tauri-config' +const getTauriConfig = require('../helpers/tauri-config') import Runner from '../runner' module.exports = async (config: TauriConfig): Promise => { @@ -19,7 +18,6 @@ module.exports = async (config: TauriConfig): Promise => { ) as TauriConfig ) - generator.generate(tauriConfig.tauri) entry.generate(tauriDir, tauriConfig) return tauri.build(tauriConfig) diff --git a/cli/tauri.js/src/api/dev.ts b/cli/tauri.js/src/api/dev.ts index 75a85429e..968cdfa7e 100644 --- a/cli/tauri.js/src/api/dev.ts +++ b/cli/tauri.js/src/api/dev.ts @@ -1,9 +1,8 @@ import { TauriConfig } from 'types' import merge from 'webpack-merge' import * as entry from '../entry' -import * as generator from '../generator' import { tauriDir } from '../helpers/app-paths' -import getTauriConfig from '../helpers/tauri-config' +const getTauriConfig = require('../helpers/tauri-config') import Runner from '../runner' module.exports = async (config: TauriConfig): Promise => { @@ -20,7 +19,6 @@ module.exports = async (config: TauriConfig): Promise => { ) as TauriConfig ) - generator.generate(tauriConfig.tauri) entry.generate(tauriDir, tauriConfig) return tauri.run(tauriConfig) diff --git a/cli/tauri.js/src/api/init.ts b/cli/tauri.js/src/api/init.ts index 328b5a1cf..4d7b24272 100644 --- a/cli/tauri.js/src/api/init.ts +++ b/cli/tauri.js/src/api/init.ts @@ -1,14 +1,16 @@ import { inject } from '../template' +import { TauriConfig } from 'types' module.exports = (args: { directory: string force: false | 'conf' | 'template' | 'all' logging: boolean - tauriPath?: string + tauriPath?: string, + customConfig?: Partial }): boolean => { return inject(args.directory, 'all', { force: args.force, logging: args.logging, tauriPath: args.tauriPath - }) + }, args.customConfig) } diff --git a/cli/tauri.js/src/generator.ts b/cli/tauri.js/src/generator.ts deleted file mode 100644 index 5e7d2aec1..000000000 --- a/cli/tauri.js/src/generator.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { writeFileSync } from 'fs-extra' -import path from 'path' -import { tauriDir } from './helpers/app-paths' -import { TauriConfig } from './types/config' - -export const generate = (tauriConfig: TauriConfig['tauri']): void => { - const { bundle, ...cfg } = tauriConfig - const outDir = tauriDir - writeFileSync(path.join(outDir, 'config.json'), JSON.stringify(cfg)) - writeFileSync(path.join(outDir, 'bundle.json'), JSON.stringify(bundle)) -} diff --git a/cli/tauri.js/src/helpers/app-paths.ts b/cli/tauri.js/src/helpers/app-paths.ts index 312e45091..adfc20769 100644 --- a/cli/tauri.js/src/helpers/app-paths.ts +++ b/cli/tauri.js/src/helpers/app-paths.ts @@ -7,7 +7,7 @@ const getAppDir = (): string => { // only go up three folders max while (dir.length > 0 && dir.endsWith(sep) && count <= 2) { - if (existsSync(join(dir, 'tauri.conf.js'))) { + if (existsSync(join(dir, 'tauri.conf.json'))) { return dir } count++ diff --git a/cli/tauri.js/src/helpers/tauri-config.ts b/cli/tauri.js/src/helpers/tauri-config.ts index e9b0b1fd8..5e0521155 100644 --- a/cli/tauri.js/src/helpers/tauri-config.ts +++ b/cli/tauri.js/src/helpers/tauri-config.ts @@ -1,4 +1,5 @@ import { existsSync } from 'fs-extra' +import { resolve } from 'path' import { TauriConfig } from 'types' import merge from 'webpack-merge' import logger from '../helpers/logger' @@ -6,20 +7,20 @@ import * as appPaths from './app-paths' const error = logger('ERROR:', 'red') -export default (cfg: Partial): TauriConfig => { +module.exports = (cfg: Partial): TauriConfig => { const pkgPath = appPaths.resolve.app('package.json') - const tauriConfPath = appPaths.resolve.app('tauri.conf.js') + const tauriConfPath = appPaths.resolve.tauri('tauri.conf.json') if (!existsSync(pkgPath)) { error("Could not find a package.json in your app's directory.") process.exit(1) } if (!existsSync(tauriConfPath)) { error( - "Could not find a tauri config (tauri.conf.js) in your app's directory." + "Could not find a tauri config (tauri.conf.json) in your app's directory." ) process.exit(1) } - const tauriConf = __non_webpack_require__(tauriConfPath)(cfg.ctx) + const tauriConf = __non_webpack_require__(tauriConfPath) const pkg = __non_webpack_require__(pkgPath) const config = merge( @@ -52,6 +53,14 @@ export default (cfg: Partial): TauriConfig => { cfg as any ) as TauriConfig + const runningDevServer = config.build.devPath && config.build.devPath.startsWith('http') + if (!runningDevServer) { + config.build.devPath = resolve(appPaths.tauriDir, config.build.devPath) + } + if (config.build.distDir) { + config.build.distDir = resolve(appPaths.tauriDir, config.build.distDir) + } + process.env.TAURI_DIST_DIR = appPaths.resolve.app(config.build.distDir) process.env.TAURI_DIR = appPaths.tauriDir diff --git a/cli/tauri.js/src/runner.ts b/cli/tauri.js/src/runner.ts index 2f3df7dbd..b11160ba8 100644 --- a/cli/tauri.js/src/runner.ts +++ b/cli/tauri.js/src/runner.ts @@ -1,17 +1,16 @@ import Inliner from '@tauri-apps/tauri-inliner' import toml from '@tauri-apps/toml' import chokidar, { FSWatcher } from 'chokidar' -import { existsSync, readFileSync, writeFileSync } from 'fs-extra' +import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs-extra' import { JSDOM } from 'jsdom' import debounce from 'lodash.debounce' import path from 'path' import * as entry from './entry' -import * as generator from './generator' import { appDir, tauriDir } from './helpers/app-paths' import logger from './helpers/logger' import onShutdown from './helpers/on-shutdown' import { spawn } from './helpers/spawn' -import getTauriConfig from './helpers/tauri-config' +const getTauriConfig = require('./helpers/tauri-config') import { TauriConfig } from './types/config' const log = logger('app:tauri', 'green') @@ -52,14 +51,11 @@ class Runner { let inlinedAssets: string[] = [] if (!runningDevServer) { - inlinedAssets = await this.__parseHtml(cfg, path.resolve(appDir, devPath)) + inlinedAssets = await this.__parseHtml(cfg, devPath) } - generator.generate({ - devPath: runningDevServer ? devPath : path.resolve(appDir, devPath), - inlinedAssets, - ...cfg.tauri - }) + process.env.TAURI_INLINED_ASSSTS = inlinedAssets.join('|') + entry.generate(tauriDir, cfg) this.devPath = devPath @@ -127,10 +123,8 @@ class Runner { const inlinedAssets = await this.__parseHtml(cfg, cfg.build.distDir) - generator.generate({ - inlinedAssets, - ...cfg.tauri - }) + process.env.TAURI_INLINED_ASSSTS = inlinedAssets.join('|') + entry.generate(tauriDir, cfg) const features = [ @@ -163,6 +157,7 @@ class Runner { async __parseHtml(cfg: TauriConfig, indexDir: string): Promise { const inlinedAssets: string[] = [] + const distDir = cfg.build.distDir return new Promise((resolve, reject) => { const distIndexPath = path.join(indexDir, 'index.html') @@ -184,8 +179,6 @@ class Runner { }) const tauriScript = document.createElement('script') - // TODO: should this be read as a buffer or a utf8 string? - // TODO: is text the write attribute to set? // @ts-ignore tauriScript.text = readFileSync(path.join(tauriDir, 'tauri.js')) document.body.insertBefore(tauriScript, document.body.firstChild) @@ -198,8 +191,12 @@ class Runner { document.head.appendChild(cspTag) } + if (!existsSync(distDir)) { + mkdirSync(distDir, { recursive: true }) + } + writeFileSync( - path.join(indexDir, 'index.tauri.html'), + path.join(distDir, 'index.tauri.html'), dom.serialize() ) resolve(inlinedAssets) diff --git a/cli/tauri.js/src/template/defaultConfig.ts b/cli/tauri.js/src/template/defaultConfig.ts new file mode 100644 index 000000000..71e9929ef --- /dev/null +++ b/cli/tauri.js/src/template/defaultConfig.ts @@ -0,0 +1,31 @@ +export default { + build: { + distDir: 'dist', + devPath: 'http://localhost:4000' + }, + ctx: {}, + tauri: { + embeddedServer: { + active: true + }, + bundle: { + active: true + }, + whitelist: { + all: false + }, + window: { + title: 'Tauri App' + }, + security: { + csp: + "default-src data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'" + }, + edge: { + active: true + }, + automaticStart: { + active: true + } + } +} diff --git a/cli/tauri.js/src/template.ts b/cli/tauri.js/src/template/index.ts similarity index 63% rename from cli/tauri.js/src/template.ts rename to cli/tauri.js/src/template/index.ts index 8d6ea2765..1371198fb 100644 --- a/cli/tauri.js/src/template.ts +++ b/cli/tauri.js/src/template/index.ts @@ -1,7 +1,10 @@ -import { copySync, existsSync, removeSync } from 'fs-extra' +import { existsSync, removeSync, writeFileSync } from 'fs-extra' import { join, normalize, resolve } from 'path' -import copyTemplates from './helpers/copy-templates' -import logger from './helpers/logger' +import { TauriConfig } from 'types' +import merge from 'webpack-merge' +import copyTemplates from '../helpers/copy-templates' +import logger from '../helpers/logger' +import defaultConfig from './defaultConfig' const log = logger('app:tauri', 'green') const warn = logger('app:tauri (template)', 'red') @@ -15,22 +18,32 @@ type InjectionType = 'conf' | 'template' | 'all' const injectConfFile = ( injectPath: string, - { force, logging }: InjectOptions + { force, logging }: InjectOptions, + customConfig: Partial = {} ): boolean | undefined => { - const path = join(injectPath, 'tauri.conf.js') + const path = join(injectPath, 'tauri.conf.json') if (existsSync(path) && force !== 'conf' && force !== 'all') { - warn(`tauri.conf.js found in ${path} + warn(`tauri.conf.json found in ${path} Run \`tauri init --force conf\` to overwrite.`) if (!force) return false } else { try { removeSync(path) - copySync(resolve(__dirname, '../templates/tauri.conf.js'), path) + const finalConf = merge(defaultConfig as any, customConfig as any) as { + [index: string]: any + } + Object.keys(finalConf).forEach(key => { + // Options marked `null` should be removed + if (finalConf[key] === null) { + delete finalConf[key] + } + }) + writeFileSync(path, JSON.stringify(finalConf, undefined, 2)) } catch (e) { if (logging) console.log(e) return false } finally { - if (logging) log('Successfully wrote tauri.conf.js') + if (logging) log('Successfully wrote tauri.conf.json') } } } @@ -70,18 +83,19 @@ Run \`tauri init --force template\` to overwrite.`) const inject = ( injectPath: string, type: InjectionType, - { force = false, logging = false, tauriPath }: InjectOptions + { force = false, logging = false, tauriPath }: InjectOptions, + customConfig?: Partial ): boolean => { if (typeof type !== 'string' || typeof injectPath !== 'string') { warn('- internal error. Required params missing.') return false } - if (type === 'conf' || type === 'all') { - injectConfFile(injectPath, { force, logging }) - } if (type === 'template' || type === 'all') { injectTemplate(injectPath, { force, logging, tauriPath }) } + if (type === 'conf' || type === 'all') { + injectConfFile(join(injectPath, 'src-tauri'), { force, logging }, customConfig) + } return true } diff --git a/cli/tauri.js/templates/src-tauri/Cargo.toml b/cli/tauri.js/templates/src-tauri/Cargo.toml index 67f4a2437..4070fb847 100755 --- a/cli/tauri.js/templates/src-tauri/Cargo.toml +++ b/cli/tauri.js/templates/src-tauri/Cargo.toml @@ -15,7 +15,6 @@ build = "src/build.rs" serde_json = "1.0.41" serde = "1.0.104" serde_derive = "1.0.104" -tiny_http = "0.6" tauri = <%= tauriDep || `{ version = "0.2.0" }` %> [target."cfg(windows)".build-dependencies] diff --git a/cli/tauri.js/templates/tauri.conf.js b/cli/tauri.js/templates/tauri.conf.js deleted file mode 100644 index 325711ad7..000000000 --- a/cli/tauri.js/templates/tauri.conf.js +++ /dev/null @@ -1,35 +0,0 @@ -const path = require('path') -const distDir = path.resolve(__dirname, './dist') - -module.exports = function () { - return { - build: { - distDir: distDir, - devPath: 'http://localhost:4000' // devServer URL or html dir - }, - ctx: {}, - tauri: { - embeddedServer: { - active: true - }, - bundle: { - active: true - }, - whitelist: { - all: false - }, - window: { - title: 'Tauri App' - }, - security: { - csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\'' - }, - edge: { - active: true - }, - automaticStart: { - active: true - } - } - } -} diff --git a/cli/tauri.js/templates/tauri.esm.js b/cli/tauri.js/templates/tauri.esm.js index 0bd01cb65..59978818b 100644 --- a/cli/tauri.js/templates/tauri.esm.js +++ b/cli/tauri.js/templates/tauri.esm.js @@ -4,7 +4,7 @@ * * THIS FILE IS GENERATED AUTOMATICALLY. * DO NOT EDIT. * - * Please whitelist these API functions in tauri.conf.js + * Please whitelist these API functions in tauri.conf.json * **/ @@ -14,7 +14,7 @@ * @module tauri * @description This API interface makes powerful interactions available * to be run on client side applications. They are opt-in features, and - * must be enabled in tauri.conf.js + * must be enabled in tauri.conf.json * * Each binding MUST provide these interfaces in order to be compliant, * and also whitelist them based upon the developer's settings. @@ -35,12 +35,12 @@ const uid = function () { /** * @name __whitelistWarning * @description Present a stylish warning to the developer that their API - * call has not been whitelisted in tauri.conf.js + * call has not been whitelisted in tauri.conf.json * @param {String} func - function name to warn * @private */ const __whitelistWarning = function (func) { - console.warn('%c[Tauri] Danger \ntauri.' + func + ' not whitelisted 💣\n%c\nAdd to tauri.conf.js: \n\ntauri: \n whitelist: { \n ' + func + ': true \n\nReference: https://tauri-apps.org/docs/api#' + func , 'background: red; color: white; font-weight: 800; padding: 2px; font-size:1.5em', ' ') + console.warn('%c[Tauri] Danger \ntauri.' + func + ' not whitelisted 💣\n%c\nAdd to tauri.conf.json: \n\ntauri: \n whitelist: { \n ' + func + ': true \n\nReference: https://tauri-apps.org/docs/api#' + func , 'background: red; color: white; font-weight: 800; padding: 2px; font-size:1.5em', ' ') } <% } %> diff --git a/cli/tauri.js/templates/tauri.js b/cli/tauri.js/templates/tauri.js index ce6ec20a4..689d46022 100644 --- a/cli/tauri.js/templates/tauri.js +++ b/cli/tauri.js/templates/tauri.js @@ -4,7 +4,7 @@ * * THIS FILE IS GENERATED AUTOMATICALLY. * DO NOT EDIT. * - * Please whitelist these API functions in tauri.conf.js + * Please whitelist these API functions in tauri.conf.json * **/ @@ -12,7 +12,7 @@ * @module tauri * @description This API interface makes powerful interactions available * to be run on client side applications. They are opt-in features, and - * must be enabled in tauri.conf.js + * must be enabled in tauri.conf.json * * Each binding MUST provide these interfaces in order to be compliant, * and also whitelist them based upon the developer's settings. diff --git a/cli/tauri.js/webpack.config.js b/cli/tauri.js/webpack.config.js index 828c07c86..c648ff56f 100644 --- a/cli/tauri.js/webpack.config.js +++ b/cli/tauri.js/webpack.config.js @@ -6,7 +6,8 @@ module.exports = { build: './src/api/build.ts', dev: './src/api/dev.ts', init: './src/api/init.ts', - tauricon: './src/api/tauricon.ts' + tauricon: './src/api/tauricon.ts', + 'tauri-config': './src/helpers/tauri-config.ts' }, mode: process.env.NODE_ENV || 'development', devtool: 'source-map', diff --git a/examples/react/create-react-app/src-tauri/tauri.conf.json b/examples/react/create-react-app/src-tauri/tauri.conf.json new file mode 100644 index 000000000..aea959329 --- /dev/null +++ b/examples/react/create-react-app/src-tauri/tauri.conf.json @@ -0,0 +1,30 @@ +{ + "build": { + "distDir": "../build", + "devPath": "http://localhost:3000" + }, + "ctx": {}, + "tauri": { + "embeddedServer": { + "active": true + }, + "bundle": { + "active": true + }, + "whitelist": { + "all": false + }, + "window": { + "title": "Tauri App" + }, + "security": { + "csp": "default-src data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'" + }, + "edge": { + "active": true + }, + "automaticStart": { + "active": true + } + } +} diff --git a/examples/react/create-react-app/tauri.conf.js b/examples/react/create-react-app/tauri.conf.js deleted file mode 100644 index c6b04063d..000000000 --- a/examples/react/create-react-app/tauri.conf.js +++ /dev/null @@ -1,35 +0,0 @@ -const path = require('path') -const distDir = path.resolve(__dirname, './build') - -module.exports = function () { - return { - build: { - distDir: distDir, - devPath: 'http://localhost:3000' // devServer URL or html dir - }, - ctx: {}, - tauri: { - embeddedServer: { - active: true - }, - bundle: { - active: true - }, - whitelist: { - all: false - }, - window: { - title: 'Tauri App' - }, - security: { - csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\'' - }, - edge: { - active: true - }, - automaticStart: { - active: true - } - } - } -} diff --git a/examples/react/gatsby-themed-site/src-tauri/tauri.conf.json b/examples/react/gatsby-themed-site/src-tauri/tauri.conf.json new file mode 100644 index 000000000..b2661a228 --- /dev/null +++ b/examples/react/gatsby-themed-site/src-tauri/tauri.conf.json @@ -0,0 +1,27 @@ +{ + "build": { + "distDir": "../public", + "devPath": "http://localhost:8000" + }, + "ctx": {}, + "tauri": { + "embeddedServer": { + "active": true + }, + "bundle": { + "active": true + }, + "whitelist": { + "all": false + }, + "window": { + "title": "Tauri App" + }, + "security": { + "csp": "default-src data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'" + }, + "edge": { + "active": true + } + } +} diff --git a/examples/react/gatsby-themed-site/tauri.conf.js b/examples/react/gatsby-themed-site/tauri.conf.js deleted file mode 100644 index 9c1da01f0..000000000 --- a/examples/react/gatsby-themed-site/tauri.conf.js +++ /dev/null @@ -1,32 +0,0 @@ -const path = require('path') -const distDir = path.resolve(__dirname, './public') - -module.exports = function () { - return { - build: { - distDir: distDir, - devPath: 'http://localhost:8000' // devServer URL or html dir - }, - ctx: {}, - tauri: { - embeddedServer: { - active: true - }, - bundle: { - active: true - }, - whitelist: { - all: false - }, - window: { - title: 'Tauri App' - }, - security: { - csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\'' - }, - edge: { - active: true - } - } - } -} diff --git a/examples/react/next.js/src-tauri/tauri.conf.json b/examples/react/next.js/src-tauri/tauri.conf.json new file mode 100644 index 000000000..08d238af4 --- /dev/null +++ b/examples/react/next.js/src-tauri/tauri.conf.json @@ -0,0 +1,30 @@ +{ + "build": { + "distDir": "../out", + "devPath": "http://localhost:3000" + }, + "ctx": {}, + "tauri": { + "embeddedServer": { + "active": true + }, + "bundle": { + "active": true + }, + "whitelist": { + "all": false + }, + "window": { + "title": "Tauri App" + }, + "security": { + "csp": "default-src data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'" + }, + "edge": { + "active": true + }, + "automaticStart": { + "active": true + } + } +} diff --git a/examples/react/next.js/tauri.conf.js b/examples/react/next.js/tauri.conf.js deleted file mode 100644 index 0e9115a1b..000000000 --- a/examples/react/next.js/tauri.conf.js +++ /dev/null @@ -1,35 +0,0 @@ -const path = require('path') -const distDir = path.resolve(__dirname, './out') - -module.exports = function () { - return { - build: { - distDir: distDir, - devPath: 'http://localhost:3000' // devServer URL or html dir - }, - ctx: {}, - tauri: { - embeddedServer: { - active: true - }, - bundle: { - active: true - }, - whitelist: { - all: false - }, - window: { - title: 'Tauri App' - }, - security: { - csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\'' - }, - edge: { - active: true - }, - automaticStart: { - active: true - } - } - } -} diff --git a/examples/svelte/svelte-app/src-tauri/tauri.conf.json b/examples/svelte/svelte-app/src-tauri/tauri.conf.json new file mode 100644 index 000000000..fc434564f --- /dev/null +++ b/examples/svelte/svelte-app/src-tauri/tauri.conf.json @@ -0,0 +1,30 @@ +{ + "build": { + "distDir": "../public", + "devPath": "http://localhost:5000" + }, + "ctx": {}, + "tauri": { + "embeddedServer": { + "active": true + }, + "bundle": { + "active": true + }, + "whitelist": { + "all": false + }, + "window": { + "title": "Tauri App" + }, + "security": { + "csp": "default-src data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'" + }, + "edge": { + "active": true + }, + "automaticStart": { + "active": true + } + } +} diff --git a/examples/svelte/svelte-app/tauri.conf.js b/examples/svelte/svelte-app/tauri.conf.js deleted file mode 100644 index c9c8dd111..000000000 --- a/examples/svelte/svelte-app/tauri.conf.js +++ /dev/null @@ -1,35 +0,0 @@ -const path = require('path') -const distDir = path.resolve(__dirname, './public') - -module.exports = function () { - return { - build: { - distDir: distDir, - devPath: 'http://localhost:5000' // devServer URL or html dir - }, - ctx: {}, - tauri: { - embeddedServer: { - active: true - }, - bundle: { - active: true - }, - whitelist: { - all: false - }, - window: { - title: 'Tauri App' - }, - security: { - csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\'' - }, - edge: { - active: true - }, - automaticStart: { - active: true - } - } - } -} diff --git a/examples/vanillajs/monolith/src-tauri/tauri.conf.json b/examples/vanillajs/monolith/src-tauri/tauri.conf.json new file mode 100644 index 000000000..1fe49ab1b --- /dev/null +++ b/examples/vanillajs/monolith/src-tauri/tauri.conf.json @@ -0,0 +1,27 @@ +{ + "build": { + "distDir": "../dist", + "devPath": "http://localhost:4000" + }, + "ctx": {}, + "tauri": { + "embeddedServer": { + "active": true + }, + "bundle": { + "active": true + }, + "whitelist": { + "all": true + }, + "window": { + "title": "Tauri App" + }, + "security": { + "csp": "default-src data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'" + }, + "edge": { + "active": true + } + } +} diff --git a/examples/vanillajs/monolith/tauri.conf.js b/examples/vanillajs/monolith/tauri.conf.js deleted file mode 100644 index cbb73b19f..000000000 --- a/examples/vanillajs/monolith/tauri.conf.js +++ /dev/null @@ -1,32 +0,0 @@ -const path = require('path') -const distDir = path.resolve(__dirname, './dist') - -module.exports = function () { - return { - build: { - distDir: distDir, - devPath: 'http://localhost:4000' // devServer URL or html dir - }, - ctx: {}, - tauri: { - embeddedServer: { - active: true - }, - bundle: { - active: true - }, - whitelist: { - all: true - }, - window: { - title: 'Tauri App' - }, - security: { - csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\'' - }, - edge: { - active: true - } - } - } -} diff --git a/examples/vue/quasar-app/src-tauri/Cargo.toml b/examples/vue/quasar-app/src-tauri/Cargo.toml index 7cd58b329..30d43e3e0 100644 --- a/examples/vue/quasar-app/src-tauri/Cargo.toml +++ b/examples/vue/quasar-app/src-tauri/Cargo.toml @@ -24,9 +24,6 @@ icon = [ serde_json = "1.0.44" serde = "1.0" serde_derive = "1.0" -tiny_http = "0.6" -phf = "0.8.0" -includedir = "0.5.0" tauri = { path = "../../../../tauri", features = [ "all-api", "edge" ] } [features] diff --git a/examples/vue/quasar-app/src-tauri/src/main.rs b/examples/vue/quasar-app/src-tauri/src/main.rs index 71c82fb80..89f6b0252 100644 --- a/examples/vue/quasar-app/src-tauri/src/main.rs +++ b/examples/vue/quasar-app/src-tauri/src/main.rs @@ -1,3 +1,8 @@ +#![cfg_attr( + all(not(debug_assertions), target_os = "windows"), + windows_subsystem = "windows" +)] + mod cmd; #[macro_use] diff --git a/examples/vue/quasar-app/src-tauri/tauri.conf.json b/examples/vue/quasar-app/src-tauri/tauri.conf.json new file mode 100644 index 000000000..50bd82270 --- /dev/null +++ b/examples/vue/quasar-app/src-tauri/tauri.conf.json @@ -0,0 +1,27 @@ +{ + "build": { + "distDir": "../dist/spa", + "devPath": "http://localhost:7334" + }, + "ctx": {}, + "tauri": { + "embeddedServer": { + "active": true + }, + "bundle": { + "active": true + }, + "whitelist": { + "all": true + }, + "window": { + "title": "Tauri App" + }, + "security": { + "csp": "default-src data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'" + }, + "edge": { + "active": true + } + } +} diff --git a/examples/vue/quasar-app/tauri.conf.js b/examples/vue/quasar-app/tauri.conf.js deleted file mode 100644 index 9bcd10e77..000000000 --- a/examples/vue/quasar-app/tauri.conf.js +++ /dev/null @@ -1,32 +0,0 @@ -const path = require('path') -const distDir = path.resolve(__dirname, './dist/spa') - -module.exports = function () { - return { - build: { - distDir: distDir, - devPath: 'http://localhost:7334' // devServer URL or html dir - }, - ctx: {}, - tauri: { - embeddedServer: { - active: true - }, - bundle: { - active: true - }, - whitelist: { - all: true - }, - window: { - title: 'Tauri App' - }, - security: { - csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\'' - }, - edge: { - active: true - } - } - } -} diff --git a/tauri/Cargo.toml b/tauri/Cargo.toml index 97bcc0a9d..bb25d014b 100644 --- a/tauri/Cargo.toml +++ b/tauri/Cargo.toml @@ -27,9 +27,6 @@ tauri-api = { version = "0.2", path = "../tauri-api" } [build-dependencies] tauri_includedir_codegen = "0.5.1" -serde_json = "1.0.44" -serde = "1.0" -serde_derive = "1.0" [features] edge = ["web-view/edge"] diff --git a/tauri/build.rs b/tauri/build.rs index 00ab692ec..45abdb611 100644 --- a/tauri/build.rs +++ b/tauri/build.rs @@ -1,26 +1,21 @@ #[cfg(not(feature = "dev-server"))] extern crate tauri_includedir_codegen; -#[cfg(not(feature = "dev-server"))] -#[macro_use] -extern crate serde_derive; -#[cfg(not(feature = "dev-server"))] -extern crate serde_json; - -#[cfg(not(feature = "dev-server"))] -#[path = "src/config.rs"] -mod config; - pub fn main() { #[cfg(not(feature = "dev-server"))] { match std::env::var("TAURI_DIST_DIR") { Ok(dist_path) => { - let config = config::get(); + let inlined_assets = match std::env::var("TAURI_INLINED_ASSETS") { + Ok(assets) => { + assets.split("|").map(|s| s.to_string()).collect() + } + Err(_) => Vec::new() + }; // include assets tauri_includedir_codegen::start("ASSETS") .dir(dist_path, tauri_includedir_codegen::Compression::None) - .build("data.rs", config.inlined_assets) + .build("data.rs", inlined_assets) .expect("failed to build data.rs") } Err(e) => panic!("Build error: Couldn't find ENV: {}", e), diff --git a/tauri/src/app/runner.rs b/tauri/src/app/runner.rs index 74995b37e..3913e0dc6 100644 --- a/tauri/src/app/runner.rs +++ b/tauri/src/app/runner.rs @@ -5,10 +5,10 @@ pub(crate) fn run(application: &mut crate::App) { let content; #[cfg(not(any(feature = "embedded-server", feature = "no-server")))] { - content = if config.dev_path.starts_with("http") { - web_view::Content::Url(config.dev_path) + content = if config.build.dev_path.starts_with("http") { + web_view::Content::Url(config.build.dev_path) } else { - let dev_path = std::path::Path::new(&config.dev_path).join("index.tauri.html"); + let dev_path = std::path::Path::new(env!("TAURI_DIST_DIR")).join("index.tauri.html"); web_view::Content::Html( std::fs::read_to_string(dev_path).expect("failed to build index.tauri.html"), ) @@ -23,7 +23,7 @@ pub(crate) fn run(application: &mut crate::App) { // define URL let port; let port_valid; - if config.embedded_server.port == "random" { + if config.tauri.embedded_server.port == "random" { match crate::tcp::get_available_port() { Some(available_port) => { port = available_port.to_string(); @@ -35,7 +35,7 @@ pub(crate) fn run(application: &mut crate::App) { } } } else { - port = config.embedded_server.port; + port = config.tauri.embedded_server.port; port_valid = crate::tcp::port_is_available( port .parse::() @@ -43,7 +43,7 @@ pub(crate) fn run(application: &mut crate::App) { ); } if port_valid { - let mut url = format!("{}:{}", config.embedded_server.host, port); + let mut url = format!("{}:{}", config.tauri.embedded_server.host, port); if !url.starts_with("http") { url = format!("http://{}", url); } @@ -76,9 +76,9 @@ pub(crate) fn run(application: &mut crate::App) { let mut ran_setup = false; let webview = web_view::builder() - .title(&config.window.title) - .size(config.window.width, config.window.height) - .resizable(config.window.resizable) + .title(&config.tauri.window.title) + .size(config.tauri.window.width, config.tauri.window.height) + .resizable(config.tauri.window.resizable) .debug(debug) .user_data(()) .invoke_handler(|webview, arg| { diff --git a/tauri/src/config.rs b/tauri/src/config.rs index 4fb501ea1..b5098b030 100644 --- a/tauri/src/config.rs +++ b/tauri/src/config.rs @@ -63,27 +63,48 @@ fn default_embedded_server() -> EmbeddedServerConfig { } #[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Config { +#[serde(tag = "tauri", rename_all = "camelCase")] +pub struct TauriConfig { #[serde(default = "default_window")] pub window: WindowConfig, #[serde(default = "default_embedded_server")] - pub embedded_server: EmbeddedServerConfig, - #[serde(default = "default_dev_path")] - pub dev_path: String, - #[serde(default = "default_inlined_assets")] - pub inlined_assets: Vec, + pub embedded_server: EmbeddedServerConfig } -fn default_inlined_assets() -> Vec { - Vec::new() +#[derive(Deserialize)] +#[serde(tag = "build", rename_all = "camelCase")] +pub struct BuildConfig { + #[serde(default = "default_dev_path")] + pub dev_path: String } fn default_dev_path() -> String { "".to_string() } -pub fn get() -> Config { - serde_json::from_str(include_str!(concat!(env!("TAURI_DIR"), "/config.json"))) - .expect("failed to create config.json") +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Config { + #[serde(default = "default_tauri")] + pub tauri: TauriConfig, + #[serde(default = "default_build")] + pub build: BuildConfig +} + +fn default_tauri() -> TauriConfig { + TauriConfig { + window: default_window(), + embedded_server: default_embedded_server() + } +} + +fn default_build() -> BuildConfig { + BuildConfig { + dev_path: default_dev_path() + } +} + +pub fn get() -> Config { + serde_json::from_str(include_str!(concat!(env!("TAURI_DIR"), "/tauri.conf.json"))) + .expect("failed to read tauri.conf.json") } diff --git a/tauri/test/fixture/src-tauri/tauri.conf.json b/tauri/test/fixture/src-tauri/tauri.conf.json new file mode 100644 index 000000000..c60f00918 --- /dev/null +++ b/tauri/test/fixture/src-tauri/tauri.conf.json @@ -0,0 +1,25 @@ +{ + "build": { + "distDir": "../dist", + "devPath": "http://localhost:4000" + }, + "ctx": {}, + "tauri": { + "embeddedServer": { + "active": true + }, + "bundle": { + "active": true + }, + "whitelist": { + "all": true + }, + "window": { + "title": "Tauri App" + }, + "security": { + "csp": "default-src data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'" + } + }, + "edge": true +} diff --git a/tauri/test/fixture/tauri.conf.js b/tauri/test/fixture/tauri.conf.js deleted file mode 100644 index 19ebc419a..000000000 --- a/tauri/test/fixture/tauri.conf.js +++ /dev/null @@ -1,30 +0,0 @@ -const path = require('path') -const distDir = path.resolve(__dirname, './dist') - -module.exports = function () { - return { - build: { - distDir: distDir, - devPath: 'http://localhost:4000' // devServer URL or html dir - }, - ctx: {}, - tauri: { - embeddedServer: { - active: true - }, - bundle: { - active: true - }, - whitelist: { - all: true - }, - window: { - title: 'Tauri App' - }, - security: { - csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\'' - } - }, - edge: true - } -}