mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-04 00:56:45 +03:00
feat(tauri) use config as JSON (#214)
* feat(tauri.js): move to typescript * fix(tauri.js): properly export api as commonjs * feat(tauri.js): convert tauricon to typescript * fix(tauri.js/tauricon): type error * chore(tauri.js/package): update yarn.lock * chore(tauri.js/package): add build/pretest scripts * refactor(tauri.js/template): remove duplicate types * feat(tauri.js): use tauri.conf.json instead of .js * feat(tauri) read config using tauri.conf.json * fix(tauri) read devPath index.html from distDir * chore(examples) move to conf.json * chore(tauri.js) remove todo * fix(ci) TAURI_DIR env variable * fix(examples) move svelte-app config to tauri.conf.json * fix(examples): line endings tauri.conf.json * addition to previous commit * fix(test): EOF in tauri.conf.json Co-authored-by: Noah Klayman <noahklayman@gmail.com> Co-authored-by: nothingismagick <drthompsonsmagickindustries@gmail.com>
This commit is contained in:
parent
8489a9a520
commit
a4e229ca10
2
.github/workflows/smoke-tests-source.yml
vendored
2
.github/workflows/smoke-tests-source.yml
vendored
@ -76,7 +76,7 @@ jobs:
|
|||||||
run: cargo build
|
run: cargo build
|
||||||
env:
|
env:
|
||||||
TAURI_DIST_DIR: ../../test/fixture/dist
|
TAURI_DIST_DIR: ../../test/fixture/dist
|
||||||
TAURI_DIR: ../test/fixture
|
TAURI_DIR: ../test/fixture/src-tauri
|
||||||
- run: cargo install --path ./cli/tauri-cli --force
|
- run: cargo install --path ./cli/tauri-cli --force
|
||||||
- name: install cli deps via yarn
|
- name: install cli deps via yarn
|
||||||
run: |
|
run: |
|
||||||
|
2
.github/workflows/test-on-pr.yml
vendored
2
.github/workflows/test-on-pr.yml
vendored
@ -30,7 +30,7 @@ jobs:
|
|||||||
cargo build
|
cargo build
|
||||||
env:
|
env:
|
||||||
TAURI_DIST_DIR: ../../test/fixture/dist
|
TAURI_DIST_DIR: ../../test/fixture/dist
|
||||||
TAURI_DIR: ../test/fixture/
|
TAURI_DIR: ../test/fixture/src-tauri
|
||||||
|
|
||||||
build-tauri-bundler:
|
build-tauri-bundler:
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
|
4
cli/tauri.js/.gitignore
vendored
4
cli/tauri.js/.gitignore
vendored
@ -71,7 +71,7 @@ config.json
|
|||||||
target
|
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
|
# todo: needs a proper fic
|
||||||
tauri.conf.js
|
tauri.conf.json
|
||||||
src-tauri
|
src-tauri
|
@ -25,7 +25,7 @@ const argv = parseArgs(process.argv.slice(2), {
|
|||||||
if (argv.help) {
|
if (argv.help) {
|
||||||
console.log(`
|
console.log(`
|
||||||
Description
|
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.
|
it will create one.
|
||||||
Usage
|
Usage
|
||||||
$ tauri init
|
$ tauri init
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { TauriConfig } from 'types'
|
import { TauriConfig } from 'types'
|
||||||
import merge from 'webpack-merge'
|
import merge from 'webpack-merge'
|
||||||
import * as entry from '../entry'
|
import * as entry from '../entry'
|
||||||
import * as generator from '../generator'
|
|
||||||
import { tauriDir } from '../helpers/app-paths'
|
import { tauriDir } from '../helpers/app-paths'
|
||||||
import getTauriConfig from '../helpers/tauri-config'
|
const getTauriConfig = require('../helpers/tauri-config')
|
||||||
import Runner from '../runner'
|
import Runner from '../runner'
|
||||||
|
|
||||||
module.exports = async (config: TauriConfig): Promise<void> => {
|
module.exports = async (config: TauriConfig): Promise<void> => {
|
||||||
@ -19,7 +18,6 @@ module.exports = async (config: TauriConfig): Promise<void> => {
|
|||||||
) as TauriConfig
|
) as TauriConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
generator.generate(tauriConfig.tauri)
|
|
||||||
entry.generate(tauriDir, tauriConfig)
|
entry.generate(tauriDir, tauriConfig)
|
||||||
|
|
||||||
return tauri.build(tauriConfig)
|
return tauri.build(tauriConfig)
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { TauriConfig } from 'types'
|
import { TauriConfig } from 'types'
|
||||||
import merge from 'webpack-merge'
|
import merge from 'webpack-merge'
|
||||||
import * as entry from '../entry'
|
import * as entry from '../entry'
|
||||||
import * as generator from '../generator'
|
|
||||||
import { tauriDir } from '../helpers/app-paths'
|
import { tauriDir } from '../helpers/app-paths'
|
||||||
import getTauriConfig from '../helpers/tauri-config'
|
const getTauriConfig = require('../helpers/tauri-config')
|
||||||
import Runner from '../runner'
|
import Runner from '../runner'
|
||||||
|
|
||||||
module.exports = async (config: TauriConfig): Promise<void> => {
|
module.exports = async (config: TauriConfig): Promise<void> => {
|
||||||
@ -20,7 +19,6 @@ module.exports = async (config: TauriConfig): Promise<void> => {
|
|||||||
) as TauriConfig
|
) as TauriConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
generator.generate(tauriConfig.tauri)
|
|
||||||
entry.generate(tauriDir, tauriConfig)
|
entry.generate(tauriDir, tauriConfig)
|
||||||
|
|
||||||
return tauri.run(tauriConfig)
|
return tauri.run(tauriConfig)
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
import { inject } from '../template'
|
import { inject } from '../template'
|
||||||
|
import { TauriConfig } from 'types'
|
||||||
|
|
||||||
module.exports = (args: {
|
module.exports = (args: {
|
||||||
directory: string
|
directory: string
|
||||||
force: false | 'conf' | 'template' | 'all'
|
force: false | 'conf' | 'template' | 'all'
|
||||||
logging: boolean
|
logging: boolean
|
||||||
tauriPath?: string
|
tauriPath?: string,
|
||||||
|
customConfig?: Partial<TauriConfig>
|
||||||
}): boolean => {
|
}): boolean => {
|
||||||
return inject(args.directory, 'all', {
|
return inject(args.directory, 'all', {
|
||||||
force: args.force,
|
force: args.force,
|
||||||
logging: args.logging,
|
logging: args.logging,
|
||||||
tauriPath: args.tauriPath
|
tauriPath: args.tauriPath
|
||||||
})
|
}, args.customConfig)
|
||||||
}
|
}
|
||||||
|
@ -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))
|
|
||||||
}
|
|
@ -7,7 +7,7 @@ const getAppDir = (): string => {
|
|||||||
|
|
||||||
// only go up three folders max
|
// only go up three folders max
|
||||||
while (dir.length > 0 && dir.endsWith(sep) && count <= 2) {
|
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
|
return dir
|
||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { existsSync } from 'fs-extra'
|
import { existsSync } from 'fs-extra'
|
||||||
|
import { resolve } from 'path'
|
||||||
import { TauriConfig } from 'types'
|
import { TauriConfig } from 'types'
|
||||||
import merge from 'webpack-merge'
|
import merge from 'webpack-merge'
|
||||||
import logger from '../helpers/logger'
|
import logger from '../helpers/logger'
|
||||||
@ -6,20 +7,20 @@ import * as appPaths from './app-paths'
|
|||||||
|
|
||||||
const error = logger('ERROR:', 'red')
|
const error = logger('ERROR:', 'red')
|
||||||
|
|
||||||
export default (cfg: Partial<TauriConfig>): TauriConfig => {
|
module.exports = (cfg: Partial<TauriConfig>): TauriConfig => {
|
||||||
const pkgPath = appPaths.resolve.app('package.json')
|
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)) {
|
if (!existsSync(pkgPath)) {
|
||||||
error("Could not find a package.json in your app's directory.")
|
error("Could not find a package.json in your app's directory.")
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
if (!existsSync(tauriConfPath)) {
|
if (!existsSync(tauriConfPath)) {
|
||||||
error(
|
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)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
const tauriConf = __non_webpack_require__(tauriConfPath)(cfg.ctx)
|
const tauriConf = __non_webpack_require__(tauriConfPath)
|
||||||
const pkg = __non_webpack_require__(pkgPath)
|
const pkg = __non_webpack_require__(pkgPath)
|
||||||
|
|
||||||
const config = merge(
|
const config = merge(
|
||||||
@ -52,6 +53,14 @@ export default (cfg: Partial<TauriConfig>): TauriConfig => {
|
|||||||
cfg as any
|
cfg as any
|
||||||
) as TauriConfig
|
) 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_DIST_DIR = appPaths.resolve.app(config.build.distDir)
|
||||||
process.env.TAURI_DIR = appPaths.tauriDir
|
process.env.TAURI_DIR = appPaths.tauriDir
|
||||||
|
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
import Inliner from '@tauri-apps/tauri-inliner'
|
import Inliner from '@tauri-apps/tauri-inliner'
|
||||||
import toml from '@tauri-apps/toml'
|
import toml from '@tauri-apps/toml'
|
||||||
import chokidar, { FSWatcher } from 'chokidar'
|
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 { JSDOM } from 'jsdom'
|
||||||
import debounce from 'lodash.debounce'
|
import debounce from 'lodash.debounce'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import * as entry from './entry'
|
import * as entry from './entry'
|
||||||
import * as generator from './generator'
|
|
||||||
import { appDir, tauriDir } from './helpers/app-paths'
|
import { appDir, tauriDir } from './helpers/app-paths'
|
||||||
import logger from './helpers/logger'
|
import logger from './helpers/logger'
|
||||||
import onShutdown from './helpers/on-shutdown'
|
import onShutdown from './helpers/on-shutdown'
|
||||||
import { spawn } from './helpers/spawn'
|
import { spawn } from './helpers/spawn'
|
||||||
import getTauriConfig from './helpers/tauri-config'
|
const getTauriConfig = require('./helpers/tauri-config')
|
||||||
import { TauriConfig } from './types/config'
|
import { TauriConfig } from './types/config'
|
||||||
|
|
||||||
const log = logger('app:tauri', 'green')
|
const log = logger('app:tauri', 'green')
|
||||||
@ -52,14 +51,11 @@ class Runner {
|
|||||||
let inlinedAssets: string[] = []
|
let inlinedAssets: string[] = []
|
||||||
|
|
||||||
if (!runningDevServer) {
|
if (!runningDevServer) {
|
||||||
inlinedAssets = await this.__parseHtml(cfg, path.resolve(appDir, devPath))
|
inlinedAssets = await this.__parseHtml(cfg, devPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.generate({
|
process.env.TAURI_INLINED_ASSSTS = inlinedAssets.join('|')
|
||||||
devPath: runningDevServer ? devPath : path.resolve(appDir, devPath),
|
|
||||||
inlinedAssets,
|
|
||||||
...cfg.tauri
|
|
||||||
})
|
|
||||||
entry.generate(tauriDir, cfg)
|
entry.generate(tauriDir, cfg)
|
||||||
|
|
||||||
this.devPath = devPath
|
this.devPath = devPath
|
||||||
@ -127,10 +123,8 @@ class Runner {
|
|||||||
|
|
||||||
const inlinedAssets = await this.__parseHtml(cfg, cfg.build.distDir)
|
const inlinedAssets = await this.__parseHtml(cfg, cfg.build.distDir)
|
||||||
|
|
||||||
generator.generate({
|
process.env.TAURI_INLINED_ASSSTS = inlinedAssets.join('|')
|
||||||
inlinedAssets,
|
|
||||||
...cfg.tauri
|
|
||||||
})
|
|
||||||
entry.generate(tauriDir, cfg)
|
entry.generate(tauriDir, cfg)
|
||||||
|
|
||||||
const features = [
|
const features = [
|
||||||
@ -163,6 +157,7 @@ class Runner {
|
|||||||
|
|
||||||
async __parseHtml(cfg: TauriConfig, indexDir: string): Promise<string[]> {
|
async __parseHtml(cfg: TauriConfig, indexDir: string): Promise<string[]> {
|
||||||
const inlinedAssets: string[] = []
|
const inlinedAssets: string[] = []
|
||||||
|
const distDir = cfg.build.distDir
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const distIndexPath = path.join(indexDir, 'index.html')
|
const distIndexPath = path.join(indexDir, 'index.html')
|
||||||
@ -184,8 +179,6 @@ class Runner {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const tauriScript = document.createElement('script')
|
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
|
// @ts-ignore
|
||||||
tauriScript.text = readFileSync(path.join(tauriDir, 'tauri.js'))
|
tauriScript.text = readFileSync(path.join(tauriDir, 'tauri.js'))
|
||||||
document.body.insertBefore(tauriScript, document.body.firstChild)
|
document.body.insertBefore(tauriScript, document.body.firstChild)
|
||||||
@ -198,8 +191,12 @@ class Runner {
|
|||||||
document.head.appendChild(cspTag)
|
document.head.appendChild(cspTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!existsSync(distDir)) {
|
||||||
|
mkdirSync(distDir, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
path.join(indexDir, 'index.tauri.html'),
|
path.join(distDir, 'index.tauri.html'),
|
||||||
dom.serialize()
|
dom.serialize()
|
||||||
)
|
)
|
||||||
resolve(inlinedAssets)
|
resolve(inlinedAssets)
|
||||||
|
31
cli/tauri.js/src/template/defaultConfig.ts
Normal file
31
cli/tauri.js/src/template/defaultConfig.ts
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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 { join, normalize, resolve } from 'path'
|
||||||
import copyTemplates from './helpers/copy-templates'
|
import { TauriConfig } from 'types'
|
||||||
import logger from './helpers/logger'
|
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 log = logger('app:tauri', 'green')
|
||||||
const warn = logger('app:tauri (template)', 'red')
|
const warn = logger('app:tauri (template)', 'red')
|
||||||
@ -15,22 +18,32 @@ type InjectionType = 'conf' | 'template' | 'all'
|
|||||||
|
|
||||||
const injectConfFile = (
|
const injectConfFile = (
|
||||||
injectPath: string,
|
injectPath: string,
|
||||||
{ force, logging }: InjectOptions
|
{ force, logging }: InjectOptions,
|
||||||
|
customConfig: Partial<TauriConfig> = {}
|
||||||
): boolean | undefined => {
|
): boolean | undefined => {
|
||||||
const path = join(injectPath, 'tauri.conf.js')
|
const path = join(injectPath, 'tauri.conf.json')
|
||||||
if (existsSync(path) && force !== 'conf' && force !== 'all') {
|
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.`)
|
Run \`tauri init --force conf\` to overwrite.`)
|
||||||
if (!force) return false
|
if (!force) return false
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
removeSync(path)
|
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) {
|
} catch (e) {
|
||||||
if (logging) console.log(e)
|
if (logging) console.log(e)
|
||||||
return false
|
return false
|
||||||
} finally {
|
} 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 = (
|
const inject = (
|
||||||
injectPath: string,
|
injectPath: string,
|
||||||
type: InjectionType,
|
type: InjectionType,
|
||||||
{ force = false, logging = false, tauriPath }: InjectOptions
|
{ force = false, logging = false, tauriPath }: InjectOptions,
|
||||||
|
customConfig?: Partial<TauriConfig>
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if (typeof type !== 'string' || typeof injectPath !== 'string') {
|
if (typeof type !== 'string' || typeof injectPath !== 'string') {
|
||||||
warn('- internal error. Required params missing.')
|
warn('- internal error. Required params missing.')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (type === 'conf' || type === 'all') {
|
|
||||||
injectConfFile(injectPath, { force, logging })
|
|
||||||
}
|
|
||||||
if (type === 'template' || type === 'all') {
|
if (type === 'template' || type === 'all') {
|
||||||
injectTemplate(injectPath, { force, logging, tauriPath })
|
injectTemplate(injectPath, { force, logging, tauriPath })
|
||||||
}
|
}
|
||||||
|
if (type === 'conf' || type === 'all') {
|
||||||
|
injectConfFile(join(injectPath, 'src-tauri'), { force, logging }, customConfig)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -15,7 +15,6 @@ build = "src/build.rs"
|
|||||||
serde_json = "1.0.41"
|
serde_json = "1.0.41"
|
||||||
serde = "1.0.104"
|
serde = "1.0.104"
|
||||||
serde_derive = "1.0.104"
|
serde_derive = "1.0.104"
|
||||||
tiny_http = "0.6"
|
|
||||||
tauri = <%= tauriDep || `{ version = "0.2.0" }` %>
|
tauri = <%= tauriDep || `{ version = "0.2.0" }` %>
|
||||||
|
|
||||||
[target."cfg(windows)".build-dependencies]
|
[target."cfg(windows)".build-dependencies]
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,7 @@
|
|||||||
* * THIS FILE IS GENERATED AUTOMATICALLY.
|
* * THIS FILE IS GENERATED AUTOMATICALLY.
|
||||||
* DO NOT EDIT.
|
* 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
|
* @module tauri
|
||||||
* @description This API interface makes powerful interactions available
|
* @description This API interface makes powerful interactions available
|
||||||
* to be run on client side applications. They are opt-in features, and
|
* 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,
|
* Each binding MUST provide these interfaces in order to be compliant,
|
||||||
* and also whitelist them based upon the developer's settings.
|
* and also whitelist them based upon the developer's settings.
|
||||||
@ -35,12 +35,12 @@ const uid = function () {
|
|||||||
/**
|
/**
|
||||||
* @name __whitelistWarning
|
* @name __whitelistWarning
|
||||||
* @description Present a stylish warning to the developer that their API
|
* @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
|
* @param {String} func - function name to warn
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
const __whitelistWarning = function (func) {
|
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', ' ')
|
||||||
}
|
}
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* * THIS FILE IS GENERATED AUTOMATICALLY.
|
* * THIS FILE IS GENERATED AUTOMATICALLY.
|
||||||
* DO NOT EDIT.
|
* 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
|
* @module tauri
|
||||||
* @description This API interface makes powerful interactions available
|
* @description This API interface makes powerful interactions available
|
||||||
* to be run on client side applications. They are opt-in features, and
|
* 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,
|
* Each binding MUST provide these interfaces in order to be compliant,
|
||||||
* and also whitelist them based upon the developer's settings.
|
* and also whitelist them based upon the developer's settings.
|
||||||
|
@ -6,7 +6,8 @@ module.exports = {
|
|||||||
build: './src/api/build.ts',
|
build: './src/api/build.ts',
|
||||||
dev: './src/api/dev.ts',
|
dev: './src/api/dev.ts',
|
||||||
init: './src/api/init.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',
|
mode: process.env.NODE_ENV || 'development',
|
||||||
devtool: 'source-map',
|
devtool: 'source-map',
|
||||||
|
30
examples/react/create-react-app/src-tauri/tauri.conf.json
Normal file
30
examples/react/create-react-app/src-tauri/tauri.conf.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
27
examples/react/gatsby-themed-site/src-tauri/tauri.conf.json
Normal file
27
examples/react/gatsby-themed-site/src-tauri/tauri.conf.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
30
examples/react/next.js/src-tauri/tauri.conf.json
Normal file
30
examples/react/next.js/src-tauri/tauri.conf.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
30
examples/svelte/svelte-app/src-tauri/tauri.conf.json
Normal file
30
examples/svelte/svelte-app/src-tauri/tauri.conf.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
27
examples/vanillajs/monolith/src-tauri/tauri.conf.json
Normal file
27
examples/vanillajs/monolith/src-tauri/tauri.conf.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,9 +24,6 @@ icon = [
|
|||||||
serde_json = "1.0.44"
|
serde_json = "1.0.44"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "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" ] }
|
tauri = { path = "../../../../tauri", features = [ "all-api", "edge" ] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
#![cfg_attr(
|
||||||
|
all(not(debug_assertions), target_os = "windows"),
|
||||||
|
windows_subsystem = "windows"
|
||||||
|
)]
|
||||||
|
|
||||||
mod cmd;
|
mod cmd;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
27
examples/vue/quasar-app/src-tauri/tauri.conf.json
Normal file
27
examples/vue/quasar-app/src-tauri/tauri.conf.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,9 +27,6 @@ tauri-api = { version = "0.2", path = "../tauri-api" }
|
|||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tauri_includedir_codegen = "0.5.1"
|
tauri_includedir_codegen = "0.5.1"
|
||||||
serde_json = "1.0.44"
|
|
||||||
serde = "1.0"
|
|
||||||
serde_derive = "1.0"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
edge = ["web-view/edge"]
|
edge = ["web-view/edge"]
|
||||||
|
@ -1,26 +1,21 @@
|
|||||||
#[cfg(not(feature = "dev-server"))]
|
#[cfg(not(feature = "dev-server"))]
|
||||||
extern crate tauri_includedir_codegen;
|
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() {
|
pub fn main() {
|
||||||
#[cfg(not(feature = "dev-server"))]
|
#[cfg(not(feature = "dev-server"))]
|
||||||
{
|
{
|
||||||
match std::env::var("TAURI_DIST_DIR") {
|
match std::env::var("TAURI_DIST_DIR") {
|
||||||
Ok(dist_path) => {
|
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
|
// include assets
|
||||||
tauri_includedir_codegen::start("ASSETS")
|
tauri_includedir_codegen::start("ASSETS")
|
||||||
.dir(dist_path, tauri_includedir_codegen::Compression::None)
|
.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")
|
.expect("failed to build data.rs")
|
||||||
}
|
}
|
||||||
Err(e) => panic!("Build error: Couldn't find ENV: {}", e),
|
Err(e) => panic!("Build error: Couldn't find ENV: {}", e),
|
||||||
|
@ -5,10 +5,10 @@ pub(crate) fn run(application: &mut crate::App) {
|
|||||||
let content;
|
let content;
|
||||||
#[cfg(not(any(feature = "embedded-server", feature = "no-server")))]
|
#[cfg(not(any(feature = "embedded-server", feature = "no-server")))]
|
||||||
{
|
{
|
||||||
content = if config.dev_path.starts_with("http") {
|
content = if config.build.dev_path.starts_with("http") {
|
||||||
web_view::Content::Url(config.dev_path)
|
web_view::Content::Url(config.build.dev_path)
|
||||||
} else {
|
} 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(
|
web_view::Content::Html(
|
||||||
std::fs::read_to_string(dev_path).expect("failed to build index.tauri.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
|
// define URL
|
||||||
let port;
|
let port;
|
||||||
let port_valid;
|
let port_valid;
|
||||||
if config.embedded_server.port == "random" {
|
if config.tauri.embedded_server.port == "random" {
|
||||||
match crate::tcp::get_available_port() {
|
match crate::tcp::get_available_port() {
|
||||||
Some(available_port) => {
|
Some(available_port) => {
|
||||||
port = available_port.to_string();
|
port = available_port.to_string();
|
||||||
@ -35,7 +35,7 @@ pub(crate) fn run(application: &mut crate::App) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
port = config.embedded_server.port;
|
port = config.tauri.embedded_server.port;
|
||||||
port_valid = crate::tcp::port_is_available(
|
port_valid = crate::tcp::port_is_available(
|
||||||
port
|
port
|
||||||
.parse::<u16>()
|
.parse::<u16>()
|
||||||
@ -43,7 +43,7 @@ pub(crate) fn run(application: &mut crate::App) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if port_valid {
|
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") {
|
if !url.starts_with("http") {
|
||||||
url = format!("http://{}", url);
|
url = format!("http://{}", url);
|
||||||
}
|
}
|
||||||
@ -76,9 +76,9 @@ pub(crate) fn run(application: &mut crate::App) {
|
|||||||
let mut ran_setup = false;
|
let mut ran_setup = false;
|
||||||
|
|
||||||
let webview = web_view::builder()
|
let webview = web_view::builder()
|
||||||
.title(&config.window.title)
|
.title(&config.tauri.window.title)
|
||||||
.size(config.window.width, config.window.height)
|
.size(config.tauri.window.width, config.tauri.window.height)
|
||||||
.resizable(config.window.resizable)
|
.resizable(config.tauri.window.resizable)
|
||||||
.debug(debug)
|
.debug(debug)
|
||||||
.user_data(())
|
.user_data(())
|
||||||
.invoke_handler(|webview, arg| {
|
.invoke_handler(|webview, arg| {
|
||||||
|
@ -63,27 +63,48 @@ fn default_embedded_server() -> EmbeddedServerConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(tag = "tauri", rename_all = "camelCase")]
|
||||||
pub struct Config {
|
pub struct TauriConfig {
|
||||||
#[serde(default = "default_window")]
|
#[serde(default = "default_window")]
|
||||||
pub window: WindowConfig,
|
pub window: WindowConfig,
|
||||||
#[serde(default = "default_embedded_server")]
|
#[serde(default = "default_embedded_server")]
|
||||||
pub embedded_server: EmbeddedServerConfig,
|
pub embedded_server: EmbeddedServerConfig
|
||||||
#[serde(default = "default_dev_path")]
|
|
||||||
pub dev_path: String,
|
|
||||||
#[serde(default = "default_inlined_assets")]
|
|
||||||
pub inlined_assets: Vec<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_inlined_assets() -> Vec<String> {
|
#[derive(Deserialize)]
|
||||||
Vec::new()
|
#[serde(tag = "build", rename_all = "camelCase")]
|
||||||
|
pub struct BuildConfig {
|
||||||
|
#[serde(default = "default_dev_path")]
|
||||||
|
pub dev_path: String
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_dev_path() -> String {
|
fn default_dev_path() -> String {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get() -> Config {
|
#[derive(Deserialize)]
|
||||||
serde_json::from_str(include_str!(concat!(env!("TAURI_DIR"), "/config.json")))
|
#[serde(rename_all = "camelCase")]
|
||||||
.expect("failed to create config.json")
|
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")
|
||||||
}
|
}
|
||||||
|
25
tauri/test/fixture/src-tauri/tauri.conf.json
Normal file
25
tauri/test/fixture/src-tauri/tauri.conf.json
Normal file
@ -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
|
||||||
|
}
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user