Save username/password, clean up proxy startup
This commit is contained in:
parent
b1042f55ea
commit
74d9837402
@ -11,6 +11,6 @@ To build install Tauri `cargo install create-tauri-app`, then run `cargo tauri b
|
|||||||
If you want to download binaries head over to [Releases](https://github.com/conversejs/converse-tauri/releases).
|
If you want to download binaries head over to [Releases](https://github.com/conversejs/converse-tauri/releases).
|
||||||
|
|
||||||
#### License
|
#### License
|
||||||
MPLv2 - Converse.js files under dist/ excluding 3rdparty/
|
MPLv2 - Converse.js files under dist/ excluding 3rdparty/
|
||||||
GNU/GPLv3 - dist/3rdparty/libsignal-protocol.min.js
|
GNU/GPLv3 - dist/3rdparty/libsignal-protocol.min.js
|
||||||
GNU/AGPLv3 - Rust files under src-tauri/ - Check LICENSE.md for details
|
GNU/AGPLv3 - Rust files under src-tauri/ - Check LICENSE.md for details
|
||||||
|
85
dist/index.html
vendored
85
dist/index.html
vendored
@ -23,21 +23,80 @@
|
|||||||
// access the pre-bundled global API functions
|
// access the pre-bundled global API functions
|
||||||
const { invoke } = window.__TAURI__.tauri;
|
const { invoke } = window.__TAURI__.tauri;
|
||||||
|
|
||||||
invoke('start_proxy').then((port) => {
|
function addCredentials (login, password) {
|
||||||
console.log('start_proxy Completed!, port: ' + port);
|
localStorage.setItem('login', login);
|
||||||
|
localStorage.setItem('password', password);
|
||||||
|
}
|
||||||
|
|
||||||
converse.initialize({
|
function getCredentials () {
|
||||||
authentication: 'login',
|
const credentials = {}
|
||||||
auto_away: 300,
|
credentials.login = localStorage.getItem('login') || '';
|
||||||
auto_reconnect: true,
|
if (credentials.login) {
|
||||||
//websocket_url: 'wss://burtrum.org/xmpp-websocket/',
|
credentials.password = localStorage.getItem('password');
|
||||||
websocket_url: 'ws://127.0.0.1:' + port + '/xmpp-websocket/',
|
}
|
||||||
assets_path: './dist/',
|
|
||||||
discover_connection_methods: false,
|
return credentials;
|
||||||
message_archiving: 'always',
|
}
|
||||||
play_sounds: false,
|
|
||||||
view_mode: 'fullscreen'
|
function removeCredentials () {
|
||||||
|
localStorage.removeItem('login');
|
||||||
|
localStorage.removeItem('password');
|
||||||
|
}
|
||||||
|
|
||||||
|
converse.plugins.add('converse-desktop-credentials', {
|
||||||
|
initialize () {
|
||||||
|
console.log("converse-desktop-credentials - initialize");
|
||||||
|
|
||||||
|
const { _converse } = this;
|
||||||
|
const { api } = _converse;
|
||||||
|
|
||||||
|
api.listen.on('afterResourceBinding', () => {
|
||||||
|
console.log("converse-desktop-credentials - afterResourceBinding");
|
||||||
|
if (_converse.connection.pass) {
|
||||||
|
addCredentials(
|
||||||
|
_converse.bare_jid,
|
||||||
|
_converse.connection.pass
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
api.listen.on('logout', () => {
|
||||||
|
console.log("converse-desktop-credentials - logout");
|
||||||
|
removeCredentials();
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { login, password } = getCredentials();
|
||||||
|
console.log('login: ' + login);
|
||||||
|
|
||||||
|
invoke('proxy_port').then((port) => {
|
||||||
|
console.log('proxy_port: ' + port);
|
||||||
|
|
||||||
|
converse.initialize({
|
||||||
|
auto_login: login && password,
|
||||||
|
jid: login,
|
||||||
|
password: password,
|
||||||
|
authentication: 'login',
|
||||||
|
auto_away: 300,
|
||||||
|
auto_reconnect: true,
|
||||||
|
websocket_url: 'ws://127.0.0.1:' + port + '/xmpp-websocket/',
|
||||||
|
assets_path: './dist/',
|
||||||
|
discover_connection_methods: false,
|
||||||
|
message_archiving: 'always',
|
||||||
|
play_sounds: false,
|
||||||
|
view_mode: 'fullscreen',
|
||||||
|
loglevel: 'debug',
|
||||||
|
muc_respect_autojoin: true,
|
||||||
|
muc_show_logs_before_join: true,
|
||||||
|
whitelisted_plugins: ['converse-desktop-credentials']
|
||||||
|
}).catch((reason) => {
|
||||||
|
document.body.innerText = "error starting converse: " + reason;
|
||||||
|
console.log(document.body.innerText);
|
||||||
|
});
|
||||||
|
}).catch((reason) => {
|
||||||
|
document.body.innerText = "error starting proxy: " + reason;
|
||||||
|
console.log(document.body.innerText);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
1
src-tauri/Cargo.lock
generated
1
src-tauri/Cargo.lock
generated
@ -336,6 +336,7 @@ dependencies = [
|
|||||||
name = "converse-tauri"
|
name = "converse-tauri"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tauri",
|
"tauri",
|
||||||
|
@ -19,6 +19,7 @@ serde_json = "1.0"
|
|||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tauri = { version = "1.1.1", features = ["api-all", "devtools", "system-tray"] }
|
tauri = { version = "1.1.1", features = ["api-all", "devtools", "system-tray"] }
|
||||||
|
|
||||||
|
once_cell = "1"
|
||||||
tokio = { version = "1.9", features = ["net"] }
|
tokio = { version = "1.9", features = ["net"] }
|
||||||
xmpp-proxy = { git = "https://github.com/moparisthebest/xmpp-proxy", default-features = false, features = ["c2s-outgoing", "tls", "quic", "websocket", "tls-ca-roots-bundled"] }
|
xmpp-proxy = { git = "https://github.com/moparisthebest/xmpp-proxy", default-features = false, features = ["c2s-outgoing", "tls", "quic", "websocket", "tls-ca-roots-bundled"] }
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
windows_subsystem = "windows"
|
windows_subsystem = "windows"
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tauri::{
|
use tauri::{
|
||||||
CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem,
|
CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem,
|
||||||
@ -13,9 +14,15 @@ use xmpp_proxy::{
|
|||||||
outgoing::spawn_outgoing_listener,
|
outgoing::spawn_outgoing_listener,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static PROXY_PORT: OnceCell<Result<u16, &'static str>> = OnceCell::new();
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn start_proxy() -> u16 {
|
fn proxy_port() -> Result<u16, &'static str> {
|
||||||
println!("starting proxy");
|
println!("returning proxy_port");
|
||||||
|
*PROXY_PORT.wait()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn start_proxy() -> Result<u16, std::io::Error> {
|
||||||
let outgoing_cfg = OutgoingConfig {
|
let outgoing_cfg = OutgoingConfig {
|
||||||
// limit incoming stanzas to this many bytes, default to ejabberd's default
|
// limit incoming stanzas to this many bytes, default to ejabberd's default
|
||||||
// https://github.com/processone/ejabberd/blob/master/ejabberd.yml.example#L32
|
// https://github.com/processone/ejabberd/blob/master/ejabberd.yml.example#L32
|
||||||
@ -23,14 +30,27 @@ async fn start_proxy() -> u16 {
|
|||||||
max_stanza_size_bytes: 262_144,
|
max_stanza_size_bytes: 262_144,
|
||||||
certs_key: Arc::new(CertsKey {}),
|
certs_key: Arc::new(CertsKey {}),
|
||||||
};
|
};
|
||||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
// try to listen to a specific port (10032), but otherwise listen on any available
|
||||||
let port = listener.local_addr().unwrap().port();
|
let listener = match TcpListener::bind("127.0.0.1:10032").await {
|
||||||
|
Ok(listener) => listener,
|
||||||
|
Err(_) => TcpListener::bind("127.0.0.1:0").await?,
|
||||||
|
};
|
||||||
|
let port = listener.local_addr()?.port();
|
||||||
spawn_outgoing_listener(listener, outgoing_cfg);
|
spawn_outgoing_listener(listener, outgoing_cfg);
|
||||||
println!("started proxy at port: {port}");
|
println!("started proxy at port: {port}");
|
||||||
port
|
Ok(port)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
tauri::async_runtime::spawn(async {
|
||||||
|
PROXY_PORT
|
||||||
|
.set(
|
||||||
|
start_proxy()
|
||||||
|
.await
|
||||||
|
.map_err(|e| Box::leak(Box::new(format!("{:?}", e))).as_str()),
|
||||||
|
)
|
||||||
|
.expect("this is the only place that calls set");
|
||||||
|
});
|
||||||
let tray_menu = SystemTrayMenu::new()
|
let tray_menu = SystemTrayMenu::new()
|
||||||
.add_item(CustomMenuItem::new("show".to_string(), "Show"))
|
.add_item(CustomMenuItem::new("show".to_string(), "Show"))
|
||||||
.add_native_item(SystemTrayMenuItem::Separator)
|
.add_native_item(SystemTrayMenuItem::Separator)
|
||||||
@ -39,6 +59,15 @@ fn main() {
|
|||||||
.add_item(CustomMenuItem::new("quit".to_string(), "Quit"));
|
.add_item(CustomMenuItem::new("quit".to_string(), "Quit"));
|
||||||
let system_tray = SystemTray::new().with_menu(tray_menu);
|
let system_tray = SystemTray::new().with_menu(tray_menu);
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
|
.setup(|app| {
|
||||||
|
#[cfg(debug_assertions)] // only include this code on debug builds
|
||||||
|
{
|
||||||
|
let window = app.get_window("main").unwrap();
|
||||||
|
window.open_devtools();
|
||||||
|
window.close_devtools();
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
.system_tray(system_tray)
|
.system_tray(system_tray)
|
||||||
.on_system_tray_event(|app, event| match event {
|
.on_system_tray_event(|app, event| match event {
|
||||||
SystemTrayEvent::LeftClick {
|
SystemTrayEvent::LeftClick {
|
||||||
@ -81,7 +110,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
})
|
})
|
||||||
.invoke_handler(tauri::generate_handler![start_proxy])
|
.invoke_handler(tauri::generate_handler![proxy_port])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user