feat(example) add API showcase to communication example (#511)

This commit is contained in:
Lucas Fernandes Nogueira
2020-03-14 11:08:13 -03:00
committed by GitHub
parent b7dfb001a1
commit b4a08e88fd
7 changed files with 265 additions and 136 deletions

View File

@@ -11,8 +11,7 @@ import logger from './helpers/logger'
import onShutdown from './helpers/on-shutdown'
import { spawn, spawnSync } from './helpers/spawn'
import { TauriConfig } from './types/config'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const getTauriConfig = require('./helpers/tauri-config')
import getTauriConfig from './helpers/tauri-config'
const log = logger('app:tauri', 'green')
const warn = logger('app:tauri (runner)', 'red')
@@ -105,17 +104,20 @@ class Runner {
path.join(tauriDir, 'build.rs'),
path.join(tauriDir, 'tauri.conf.json'),
...tauriPaths
],
].concat(runningDevServer ? [] : [devPath]),
{
ignoreInitial: true
ignoreInitial: true,
ignored: runningDevServer ? null : path.join(devPath, 'index.tauri.html')
}
)
.on(
'change',
debounce((path: string) => {
debounce((changedPath: string) => {
(this.pid ? this.__stopCargo() : Promise.resolve())
.then(() => {
if (path.includes('tauri.conf.json')) {
const shouldTriggerRun = changedPath.includes('tauri.conf.json') ||
changedPath.startsWith(devPath)
if (shouldTriggerRun) {
this.run(getTauriConfig({ ctx: cfg.ctx })).catch(e => {
throw e
})
@@ -243,7 +245,7 @@ class Runner {
})
}
if (cfg.tauri.embeddedServer.active || !cfg.tauri.inliner.active) {
if ((!cfg.ctx.dev && cfg.tauri.embeddedServer.active) || !cfg.tauri.inliner.active) {
rewriteHtml(readFileSync(indexPath).toString(), domInterceptor)
resolve(inlinedAssets)
} else {

View File

@@ -267,7 +267,7 @@ window.tauri = {
if (_typeof(cfg) === 'object') {
Object.freeze(cfg);
}
this.invoke({
return this.promisified({
cmd: 'writeFile',
file: cfg.file,
contents: cfg.contents
@@ -282,45 +282,25 @@ window.tauri = {
<% if (ctx.dev) { %>
/**
* @name listFiles
* @description Get the files in a path.
* @name readDir
* @description Reads a directory
* Permissions based on the app's PID owner
* @param {String} path
* @param {Object} [options]
* @param {Boolean} [options.recursive]
* @returns {*|Promise<any>|Promise}
*/
<% } %>
listFiles: function listFiles(path) {
<% if (tauri.whitelist.listFiles === true || tauri.whitelist.all === true) { %>
readDir: function readDir(path, options) {
<% if (tauri.whitelist.readDir === true || tauri.whitelist.all === true) { %>
return this.promisified({
cmd: 'listFiles',
path: path
cmd: 'readDir',
path: path,
options: options
});
<% } else { %>
<% if (ctx.dev) { %>
return __whitelistWarning('listDirs')
<% } %>
return __reject()
<% } %>
},
<% if (ctx.dev) { %>
/**
* @name listDirs
* @description Get the directories in a path.
* Permissions based on the app's PID owner
* @param {String} path
* @returns {*|Promise<any>|Promise}
*/
<% } %>
listDirs: function listDirs(path) {
<% if (tauri.whitelist.listDirs === true || tauri.whitelist.all === true) { %>
return this.promisified({
cmd: 'listDirs',
path: path
});
<% } else { %>
<% if (ctx.dev) { %>
return __whitelistWarning('listDirs')
return __whitelistWarning('readDir')
<% } %>
return __reject()
<% } %>