feat: update to tauri v1.0.0-rc

This commit is contained in:
Lucas Nogueira
2022-02-13 17:19:12 -03:00
parent 9e970d3d74
commit ea880bb8a6
10 changed files with 1098 additions and 3316 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ serde = "1.0"
serde_json = "1.0"
thiserror = "1.0"
rand = "0.8"
tauri = "1.0.0-beta.8"
tauri = "1.0.0-rc.1"
futures-util = "0.3"
tokio = { version = "1.16", features = ["net", "sync"] }
tokio-tungstenite = { version = "0.16", features = ["native-tls"] }
+1 -1
View File
@@ -12,7 +12,7 @@
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.0",
"@rollup/plugin-typescript": "^8.2.0",
"@tauri-apps/cli": "^1.0.0-beta.8",
"@tauri-apps/cli": "^1.0.0-rc.2",
"@tsconfig/svelte": "^1.0.0",
"rollup": "^2.45",
"rollup-plugin-css-only": "^3.1.0",
+987 -397
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -9,14 +9,14 @@ edition = "2018"
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = [ "derive" ] }
tauri = { version = "1.0.0-beta.5", features = ["api-all"] }
tauri = { version = "1.0.0-rc.1", features = ["api-all"] }
tokio = { version = "1.11", features = ["net"] }
futures-util = "0.3"
tauri-plugin-websocket = { path = "../../../" }
tokio-tungstenite = "0.15"
[build-dependencies]
tauri-build = "1.0.0-beta.3"
tauri-build = "1.0.0-rc.0"
[features]
default = [ "custom-protocol" ]
+3 -4
View File
@@ -25,10 +25,9 @@ async fn accept_connection(stream: TcpStream) {
.expect("Error during the websocket handshake occurred");
let (write, read) = ws_stream.split();
read
.forward(write)
.await
.expect("Failed to forward message")
if let Err(e) = read.forward(write).await {
eprintln!("Error: {}", e);
}
}
fn main() {
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -26,7 +26,7 @@
"typescript": "4.5.5"
},
"dependencies": {
"@tauri-apps/api": "1.0.0-beta.8",
"@tauri-apps/api": "1.0.0-rc.0",
"tslib": "2.3.1"
}
}
+7 -4
View File
@@ -1,7 +1,11 @@
use futures_util::{stream::SplitSink, SinkExt, StreamExt};
use serde::{ser::Serializer, Deserialize, Serialize};
use serde_json::Value as JsonValue;
use tauri::{plugin::Plugin, AppHandle, Invoke, Manager, Runtime, State, Window};
use tauri::{
api::ipc::{format_callback, CallbackFn},
plugin::Plugin,
AppHandle, Invoke, Manager, Runtime, State, Window,
};
use tokio::{net::TcpStream, sync::Mutex};
use tokio_tungstenite::{
connect_async_with_config,
@@ -79,7 +83,7 @@ enum WebSocketMessage {
fn connect<R: Runtime>(
window: Window<R>,
url: String,
callback_function: String,
callback_function: CallbackFn,
config: Option<ConnectionConfig>,
) -> Result<Id> {
let id = rand::random();
@@ -92,7 +96,6 @@ fn connect<R: Runtime>(
manager.0.lock().await.insert(id, write);
read.for_each(move |message| {
let window_ = window.clone();
let callback_function_ = callback_function.clone();
async move {
if let Ok(Message::Close(_)) = message {
let manager = window_.state::<ConnectionManager>();
@@ -121,7 +124,7 @@ fn connect<R: Runtime>(
}
Err(e) => serde_json::to_value(Error::from(e)).unwrap(),
};
let js = tauri::api::rpc::format_callback(callback_function_, &response)
let js = format_callback(callback_function, &response)
.expect("unable to serialize websocket message");
let _ = window_.eval(js.as_str());
}
+1 -1
View File
@@ -12,4 +12,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var e=function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function t(e,t){void 0===t&&(t=!1);var n=function(){var e=new Int8Array(1);window.crypto.getRandomValues(e);var t=new Uint8Array(Math.max(16,Math.abs(e[0])));return window.crypto.getRandomValues(t),t.join("")}();return Object.defineProperty(window,n,{value:function(r){return t&&Reflect.deleteProperty(window,n),null==e?void 0:e(r)},writable:!1,configurable:!0}),n}function n(n,r){return void 0===r&&(r={}),function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function c(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}l((r=r.apply(e,t||[])).next())}))}(this,void 0,void 0,(function(){return function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,(function(o){return[2,new Promise((function(o,i){var a=t((function(e){o(e),Reflect.deleteProperty(window,c)}),!0),c=t((function(e){i(e),Reflect.deleteProperty(window,a)}),!0);window.rpc.notify(n,e({__invokeKey:__TAURI_INVOKE_KEY__,callback:a,error:c},r))}))]}))}))}Object.freeze({__proto__:null,transformCallback:t,invoke:n,convertFileSrc:function(e){return navigator.userAgent.includes("Windows")?"https://asset.localhost/"+e:"asset://"+e}});class r{constructor(e,t){this.id=e,this.listeners=t}static async connect(e,o){const i=[];return n("plugin:websocket|connect",{url:e,callbackFunction:t((e=>{i.forEach((t=>t(e)))})),options:o}).then((e=>new r(e,i)))}addListener(e){this.listeners.push(e)}send(e){let t;if("string"==typeof e)t={type:"Text",data:e};else if("object"==typeof e&&"type"in e)t=e;else{if(!Array.isArray(e))throw new Error("invalid `message` type, expected a `{ type: string, data: any }` object, a string or a numeric array");t={type:"Binary",data:e}}return n("plugin:websocket|send",{id:this.id,message:t})}disconnect(){return this.send({type:"Close",data:{code:1e3,reason:"Disconnected by client"}})}}export{r as default};
var e=function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function t(e,t){void 0===t&&(t=!1);var n=window.crypto.getRandomValues(new Uint32Array(1))[0],r="_".concat(n);return Object.defineProperty(window,r,{value:function(n){return t&&Reflect.deleteProperty(window,r),null==e?void 0:e(n)},writable:!1,configurable:!0}),n}function n(n,r){return void 0===r&&(r={}),function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function c(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}l((r=r.apply(e,t||[])).next())}))}(this,void 0,void 0,(function(){return function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,(function(o){return[2,new Promise((function(o,i){var a=t((function(e){o(e),Reflect.deleteProperty(window,c)}),!0),c=t((function(e){i(e),Reflect.deleteProperty(window,a)}),!0);window.__TAURI_IPC__(e({cmd:n,callback:a,error:c},r))}))]}))}))}Object.freeze({__proto__:null,transformCallback:t,invoke:n,convertFileSrc:function(e){return navigator.userAgent.includes("Windows")?"https://asset.localhost/".concat(e):"asset://".concat(e)}});class r{constructor(e,t){this.id=e,this.listeners=t}static async connect(e,o){const i=[];return n("plugin:websocket|connect",{url:e,callbackFunction:t((e=>{i.forEach((t=>t(e)))})),options:o}).then((e=>new r(e,i)))}addListener(e){this.listeners.push(e)}send(e){let t;if("string"==typeof e)t={type:"Text",data:e};else if("object"==typeof e&&"type"in e)t=e;else{if(!Array.isArray(e))throw new Error("invalid `message` type, expected a `{ type: string, data: any }` object, a string or a numeric array");t={type:"Binary",data:e}}return n("plugin:websocket|send",{id:this.id,message:t})}disconnect(){return this.send({type:"Close",data:{code:1e3,reason:"Disconnected by client"}})}}export{r as default};
+11 -4
View File
@@ -52,10 +52,12 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"
"@tauri-apps/api@1.0.0-beta.8":
version "1.0.0-beta.8"
resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-1.0.0-beta.8.tgz#a43dc4a4515148f29bfb616db85445b771e84f78"
integrity sha512-a56lXB7XvQ4+fKtT0pxpkjTSKhyrQ1Vmjyvt2ox3mT9xw3l7s8IOKHJ1WuqW6TA6xdoy3Cyja3Z3prw8hflS7g==
"@tauri-apps/api@1.0.0-rc.0":
version "1.0.0-rc.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-1.0.0-rc.0.tgz#f9fa469923591a6e8294ffe906bf886ace2cb4d0"
integrity sha512-BOREst3Nq931RQTqNT5gbBw8E7wpjEr4PhSviAJwIWtKi3KGRxY5TmWyMO4j3kKmsZQQVoZ4dPwI2pQfNJYtKw==
dependencies:
type-fest "2.11.2"
"@types/estree@0.0.39":
version "0.0.39"
@@ -290,6 +292,11 @@ tslib@2.3.1:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==
type-fest@2.11.2:
version "2.11.2"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.11.2.tgz#5534a919858bc517492cd3a53a673835a76d2e71"
integrity sha512-reW2Y2Mpn0QNA/5fvtm5doROLwDPu2zOm5RtY7xQQS05Q7xgC8MOZ3yPNaP9m/s/sNjjFQtHo7VCNqYW2iI+Ig==
typescript@4.5.5:
version "4.5.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3"