chore: adjust prettier config, .gitignore and use taplo to format toml files (#1728)

* chore: adjust prettier config, .gitignore and use taplo to format toml files

This brings the plugins-workspace repository to the same code style of the main tauri repo

* format toml

* ignore examples gen dir

* add .vscode/extensions.json

* remove packageManager field

* fmt

* fix audit

* taplo ignore permissions autogenerated files

* remove create dummy dist

* fix prettier workflow

* install fmt in prettier workflow

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
Amr Bashir
2024-09-04 14:54:23 +03:00
committed by GitHub
parent 72c2ce82c1
commit cf4d7d4e6c
227 changed files with 2534 additions and 2505 deletions
-2
View File
@@ -1,2 +0,0 @@
node_modules
gen/schemas
+3 -3
View File
@@ -11,11 +11,11 @@ links = "tauri-plugin-websocket"
exclude = ["/examples"]
[package.metadata.docs.rs]
rustc-args = [ "--cfg", "docsrs" ]
rustdoc-args = [ "--cfg", "docsrs" ]
rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs"]
[build-dependencies]
tauri-plugin = { workspace = true, features = [ "build" ] }
tauri-plugin = { workspace = true, features = ["build"] }
[dependencies]
serde = { workspace = true }
+4 -4
View File
@@ -60,13 +60,13 @@ fn main() {
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
```javascript
import WebSocket from "@tauri-apps/plugin-websocket";
import WebSocket from '@tauri-apps/plugin-websocket'
const ws = await WebSocket.connect("wss://example.com");
const ws = await WebSocket.connect('wss://example.com')
await ws.send("Hello World");
await ws.send('Hello World')
await ws.disconnect();
await ws.disconnect()
```
## Contributing
+1 -1
View File
@@ -20,4 +20,4 @@ We prefer to receive reports in English.
Please disclose a vulnerability or security relevant issue here: [https://github.com/tauri-apps/plugins-workspace/security/advisories/new](https://github.com/tauri-apps/plugins-workspace/security/advisories/new).
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
@@ -2,57 +2,57 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import WebSocket from "tauri-plugin-websocket-api";
import "./style.css";
import WebSocket from 'tauri-plugin-websocket-api'
import './style.css'
let ws: WebSocket;
let ws: WebSocket
document.addEventListener("DOMContentLoaded", async () => {
document.querySelector("#send")?.addEventListener("click", send);
document.querySelector("#disconnect")?.addEventListener("click", disconnect);
await connect();
});
document.addEventListener('DOMContentLoaded', async () => {
document.querySelector('#send')?.addEventListener('click', send)
document.querySelector('#disconnect')?.addEventListener('click', disconnect)
await connect()
})
function _updateResponse(returnValue: unknown) {
const msg = document.createElement("p");
const msg = document.createElement('p')
msg.textContent =
typeof returnValue === "string" ? returnValue : JSON.stringify(returnValue);
document.querySelector("#response-container")?.appendChild(msg);
typeof returnValue === 'string' ? returnValue : JSON.stringify(returnValue)
document.querySelector('#response-container')?.appendChild(msg)
}
async function connect() {
try {
ws = await WebSocket.connect("ws://127.0.0.1:8080").then((r) => {
_updateResponse("Connected");
return r;
});
ws = await WebSocket.connect('ws://127.0.0.1:8080').then((r) => {
_updateResponse('Connected')
return r
})
} catch (e) {
_updateResponse(e);
_updateResponse(e)
}
ws.addListener(_updateResponse);
ws.addListener(_updateResponse)
}
function send() {
ws.send(document.querySelector("#msg-input")?.textContent || "")
ws.send(document.querySelector('#msg-input')?.textContent || '')
.then(() => {
_updateResponse("Message sent");
_updateResponse('Message sent')
})
.catch(_updateResponse);
.catch(_updateResponse)
}
function disconnect() {
ws.disconnect()
.then(() => {
_updateResponse("Disconnected");
_updateResponse('Disconnected')
})
.catch(_updateResponse);
.catch(_updateResponse)
}
document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
<div>
<input type="text" />
<button id="send">send</button>
<button id="disconnect">disconnect</button>
<div id="response-container"></div>
</div>
`;
`
@@ -10,8 +10,8 @@ body {
margin: 0;
padding: 8px;
box-sizing: border-box;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
}
a {
+48 -48
View File
@@ -2,97 +2,97 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { invoke, Channel } from "@tauri-apps/api/core";
import { invoke, Channel } from '@tauri-apps/api/core'
export interface ConnectionConfig {
writeBufferSize?: number;
maxWriteBufferSize?: number;
maxMessageSize?: number;
maxFrameSize?: number;
acceptUnmaskedFrames?: boolean;
headers?: HeadersInit;
writeBufferSize?: number
maxWriteBufferSize?: number
maxMessageSize?: number
maxFrameSize?: number
acceptUnmaskedFrames?: boolean
headers?: HeadersInit
}
export interface MessageKind<T, D> {
type: T;
data: D;
type: T
data: D
}
export interface CloseFrame {
code: number;
reason: string;
code: number
reason: string
}
export type Message =
| MessageKind<"Text", string>
| MessageKind<"Binary", number[]>
| MessageKind<"Ping", number[]>
| MessageKind<"Pong", number[]>
| MessageKind<"Close", CloseFrame | null>;
| MessageKind<'Text', string>
| MessageKind<'Binary', number[]>
| MessageKind<'Ping', number[]>
| MessageKind<'Pong', number[]>
| MessageKind<'Close', CloseFrame | null>
export default class WebSocket {
id: number;
private readonly listeners: Array<(arg: Message) => void>;
id: number
private readonly listeners: Array<(arg: Message) => void>
constructor(id: number, listeners: Array<(arg: Message) => void>) {
this.id = id;
this.listeners = listeners;
this.id = id
this.listeners = listeners
}
static async connect(
url: string,
config?: ConnectionConfig,
config?: ConnectionConfig
): Promise<WebSocket> {
const listeners: Array<(arg: Message) => void> = [];
const listeners: Array<(arg: Message) => void> = []
const onMessage = new Channel<Message>();
const onMessage = new Channel<Message>()
onMessage.onmessage = (message: Message): void => {
listeners.forEach((l) => {
l(message);
});
};
if (config?.headers) {
config.headers = Array.from(new Headers(config.headers).entries());
l(message)
})
}
return await invoke<number>("plugin:websocket|connect", {
if (config?.headers) {
config.headers = Array.from(new Headers(config.headers).entries())
}
return await invoke<number>('plugin:websocket|connect', {
url,
onMessage,
config,
}).then((id) => new WebSocket(id, listeners));
config
}).then((id) => new WebSocket(id, listeners))
}
addListener(cb: (arg: Message) => void): void {
this.listeners.push(cb);
this.listeners.push(cb)
}
async send(message: Message | string | number[]): Promise<void> {
let m: Message;
if (typeof message === "string") {
m = { type: "Text", data: message };
} else if (typeof message === "object" && "type" in message) {
m = message;
let m: Message
if (typeof message === 'string') {
m = { type: 'Text', data: message }
} else if (typeof message === 'object' && 'type' in message) {
m = message
} else if (Array.isArray(message)) {
m = { type: "Binary", data: message };
m = { type: 'Binary', data: message }
} else {
throw new Error(
"invalid `message` type, expected a `{ type: string, data: any }` object, a string or a numeric array",
);
'invalid `message` type, expected a `{ type: string, data: any }` object, a string or a numeric array'
)
}
await invoke("plugin:websocket|send", {
await invoke('plugin:websocket|send', {
id: this.id,
message: m,
});
message: m
})
}
async disconnect(): Promise<void> {
await this.send({
type: "Close",
type: 'Close',
data: {
code: 1000,
reason: "Disconnected by client",
},
});
reason: 'Disconnected by client'
}
})
}
}
+2 -2
View File
@@ -2,6 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { createConfig } from "../../shared/rollup.config.js";
import { createConfig } from '../../shared/rollup.config.js'
export default createConfig();
export default createConfig()