Skip to content

Commit

Permalink
feat/web-view (tauri-apps#52)
Browse files Browse the repository at this point in the history
* feat(web-view): revert to now well-maintained upstream web-view [WIP]

* feat(tests): add jest testing, first test

* feat(lint): install, config and fix
  • Loading branch information
nothingismagick authored Nov 16, 2019
1 parent 1ee1933 commit 5ec8e2f
Show file tree
Hide file tree
Showing 37 changed files with 4,897 additions and 177 deletions.
1 change: 1 addition & 0 deletions .env.jest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_ENV=test
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/src-tauri
23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
env: {
node: true,
jest: true
},

extends: ["standard"],

plugins: [],

globals: {
__statics: true,
process: true
},

// add your custom rules here
rules: {
// allow console.log during development only
"no-console": process.env.NODE_ENV === "production" ? "error" : "off",
// allow debugger during development only
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off"
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ typings/
debug.log
package-lock.json
.vscode/settings.json


src-tauri
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ node_modules
.github
.idea
SECURITY.md

src-tauri
35 changes: 35 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
globals: {
__DEV__: true
},
setupFilesAfterEnv: ['<rootDir>/test/jest/jest.setup.js'],
// noStackTrace: true,
// bail: true,
// cache: false,
// verbose: true,
// watch: true,
collectCoverage: true,
coverageDirectory: '<rootDir>/test/jest/coverage',
collectCoverageFrom: [
'<rootDir>/mode/**/*.js',
],
coverageReporters: ['json-summary', 'text', 'lcov'],
coverageThreshold: {
global: {
// branches: 50,
// functions: 50,
// lines: 50,
// statements: 50
}
},
testMatch: [
'<rootDir>/test/jest/__tests__/**/*.spec.js',
'<rootDir>/test/jest/__tests__/**/*.test.js'
],
moduleFileExtensions: ['js', 'json'],
moduleNameMapper: {
'^~/(.*)$': '<rootDir>/$1',
'^mode/(.*)$': '<rootDir>/mode/$1'
},
transform: {}
}
22 changes: 12 additions & 10 deletions lib/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@ license = "MIT"
edition = "2018"

[dependencies]
tauri-ui = { path = "../../bindings/rust" }
serde_json = "1.0.39"
# tauri-ui = { path = "../../bindings/rust" }
web-view = "0.5.3"
serde_json = "1.0.41"
serde = "1.0"
serde_derive = "1.0"
dirs = "1.0"
ignore = "0.4.7"
phf = "0.7.21"
dirs = "2.0.2"
ignore = "0.4.10"
phf = "0.8.0"
threadpool = "1.7"
rand = "0.7"
reqwest = "0.9"
pbr = "1"
zip = "0.5.0"
zip = "0.5.3"
tempdir = "0.3"
semver = "0.9"
tempfile = "3"
either = "1.5.0"
either = "1.5.3"
tar = "0.4"
flate2 = "1"
hyper-old-types = "0.11.0"
sysinfo = "0.9"
webbrowser = "0.5.1"
uuid = { version = "0.7", features = ["v4"] }
lazy_static = "1.3.0"
webbrowser = "0.5.2"
uuid = { version = "0.8.1", features = ["v4"] }
lazy_static = "1.4.0"
includedir = "0.5.0"
tiny_http = "0.6"
clap = {version = "2.33", features = ["yaml"]}
Expand All @@ -37,6 +38,7 @@ clap = {version = "2.33", features = ["yaml"]}
includedir_codegen = "0.5.0"

[features]
# edge = ["webview-sys/edge"]
dev = []
embedded-server = []
all-api = []
Expand Down
14 changes: 7 additions & 7 deletions lib/rust/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod cmd;

use tauri_ui::WebView;
use web_view::WebView;

#[allow(unused_variables)]
pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
Expand All @@ -23,21 +23,21 @@ pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
}}).then(function () {{
const listeners = (window['{listeners}'] && window['{listeners}'][payload.type]) || []
if (!ignoreQueue && listeners.length === 0) {{
window['{queue}'].push({{
if (!ignoreQueue && listeners.length === 0) {{
window['{queue}'].push({{
payload: payload,
salt: salt
}})
}}
for (let i = listeners.length - 1; i >= 0; i--) {{
for (let i = listeners.length - 1; i >= 0; i--) {{
const listener = listeners[i]
if (listener.once)
listeners.splice(i, 1)
listener.handler(payload)
}}
}})
}}",
}}",
fn = crate::event::emit_function_name(),
listeners = crate::event::event_listeners_object_name(),
queue = crate::event::event_queue_object_name()
Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
webview
.eval(&format!(
"
if (window['{listeners}'] === void 0) {{
if (window['{listeners}'] === void 0) {{
window['{listeners}'] = {{}}
}}
if (window['{listeners}']['{evt}'] === void 0) {{
Expand All @@ -136,7 +136,7 @@ pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
once: {once_flag}
}});
for (let i = 0; i < window['{queue}'].length; i++) {{
for (let i = 0; i < window['{queue}'].length; i++) {{
const e = window['{queue}'][i];
window['{emit}'](e.payload, e.salt, true)
}}
Expand Down
2 changes: 1 addition & 1 deletion lib/rust/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod runner;
use tauri_ui::WebView;
use web_view::WebView;

//type FnMut(&mut InvokeHandler<WebView<'_, ()>>, &str) = FnMut(&mut FnMut(&mut InvokeHandler<WebView<'_, ()>>, &str)<WebView<'_, ()>>, &str);

Expand Down
8 changes: 4 additions & 4 deletions lib/rust/src/app/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(crate) fn run(application: &mut crate::App) {
);

let matches = app.get_matches();
content = tauri_ui::Content::Url(matches.value_of("url").unwrap().to_owned());
content = web_view::Content::Url(matches.value_of("url").unwrap().to_owned());
debug = true;
}

Expand All @@ -51,7 +51,7 @@ pub(crate) fn run(application: &mut crate::App) {
#[cfg(not(feature = "embedded-server"))]
{
content =
tauri_ui::Content::Html(include_str!(concat!(env!("TAURI_DIST_DIR"), "/index.html")));
web_view::Content::Html(include_str!(concat!(env!("TAURI_DIST_DIR"), "/index.html")));
}
#[cfg(feature = "embedded-server")]
{
Expand Down Expand Up @@ -81,14 +81,14 @@ pub(crate) fn run(application: &mut crate::App) {
if !server_url.starts_with("http") {
server_url = format!("http://{}", server_url);
}
content = tauri_ui::Content::Url(server_url.clone());
content = web_view::Content::Url(server_url.clone());
} else {
panic!(format!("Port {} is not valid or not open", port));
}
}
}

let webview = tauri_ui::builder()
let webview = web_view::builder()
.title(&config.window.title)
.size(config.window.width, config.window.height)
.resizable(config.window.resizable)
Expand Down
2 changes: 1 addition & 1 deletion lib/rust/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use tauri_ui::WebView;
use web_view::WebView;

use std::process::{Child, Command, Stdio};

Expand Down
2 changes: 1 addition & 1 deletion lib/rust/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::boxed::Box;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use tauri_ui::Handle;
use web_view::Handle;

struct EventHandler {
on_event: Box<dyn FnOnce(String)>,
Expand Down
2 changes: 1 addition & 1 deletion lib/rust/src/file_system.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use tauri_ui::WebView;
use web_view::WebView;

use crate::dir;
use crate::execute_promise;
Expand Down
4 changes: 3 additions & 1 deletion lib/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ mod macros;
#[macro_use]
extern crate lazy_static;

extern crate web_view;

pub mod api;
mod app;
pub mod command;
Expand All @@ -27,7 +29,7 @@ pub mod updater;
pub mod version;
pub use app::*;

use tauri_ui::WebView;
use web_view::*;

use threadpool::ThreadPool;

Expand Down
2 changes: 1 addition & 1 deletion lib/rust/src/salt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::sync::Mutex;
use tauri_ui::WebView;
use web_view::WebView;
use uuid::Uuid;

struct Salt {
Expand Down
2 changes: 1 addition & 1 deletion lib/tauri.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class Tauri {
* @param {Boolean} once
*/
<% } %>
static addEventListener(evt, handler, once = false) {
static addEventListener (evt, handler, once = false) {
this.invoke({
cmd: 'addEventListener',
evt,
Expand Down
16 changes: 8 additions & 8 deletions mode/bin/tauri-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ if (argv.help) {
process.exit(0)
}

const { tauriDir } = require('../helpers/app-paths'),
Runner = require('../runner'),
tauri = new Runner({modeDir: tauriDir}),
tauriConfig = require('../helpers/tauri-config')({
ctx: {
debug: argv.debug
}
})
const { tauriDir } = require('../helpers/app-paths')
const Runner = require('../runner')
const tauri = new Runner({ modeDir: tauriDir })
const tauriConfig = require('../helpers/tauri-config')({
ctx: {
debug: argv.debug
}
})

require('../generator').generate(tauriConfig.tauri)
require('../entry').generate(tauriDir, tauriConfig)
Expand Down
16 changes: 8 additions & 8 deletions mode/bin/tauri-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ if (argv.help) {
process.exit(0)
}

const { tauriDir } = require('../helpers/app-paths'),
Runner = require('../runner'),
tauri = new Runner(),
tauriConfig = require('../helpers/tauri-config')({
ctx: {
debug: true
}
})
const { tauriDir } = require('../helpers/app-paths')
const Runner = require('../runner')
const tauri = new Runner()
const tauriConfig = require('../helpers/tauri-config')({
ctx: {
debug: true
}
})

require('../generator').generate(tauriConfig.tauri)
require('../entry').generate(tauriDir, tauriConfig)
Expand Down
Empty file added mode/bin/tauri-help.js
Empty file.
38 changes: 20 additions & 18 deletions mode/bin/tauri-init.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const
parseArgs = require('minimist'),
appPaths = require('../helpers/app-paths'),
logger = require('../helpers/logger'),
log = logger('app:tauri'),
warn = logger('app:tauri (init)', 'red')
parseArgs = require('minimist')
const appPaths = require('../helpers/app-paths')
const logger = require('../helpers/logger')
const log = logger('app:tauri')
const warn = logger('app:tauri (init)', 'red')

/**
* @type {object}
Expand All @@ -15,34 +15,36 @@ const
* @property {boolean} log
*/
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
f: 'force',
l: 'log'
},
boolean: ['h', 'l']
alias: {
h: 'help',
f: 'force',
l: 'log',
d: 'directory'
},
boolean: ['h', 'l']
})

if (argv.help) {
console.log(`
console.log(`
Description
Inits the Tauri template. If Tauri cannot find the tauri.conf.js
it will create one.
Usage
$ tauri init
Options
--help, -h Displays this message
--force, -f Force init to overwrite [conf|template|all]
--log, l Logging [boolean]
`)
process.exit(0)
--help, -h Displays this message
--force, -f Force init to overwrite [conf|template|all]
--log, l Logging [boolean]
--directory, d Set target directory for init
`)
process.exit(0)
}

const { inject } = require('../template')

const target = appPaths.tauriDir

if (inject(target, 'all', argv.f, argv.l)) {
if (inject(target, 'all', argv.f, argv.l, argv.d)) {
log('tauri init successful')
} else {
warn('tauri init unsuccessful')
Expand Down
Loading

0 comments on commit 5ec8e2f

Please sign in to comment.