feat: add brew app connection
- initialize tcp communication with brew app - WIP value editor sync Signed-off-by: pakintada@gmail.com <Pakin>
This commit is contained in:
parent
08f7626dcb
commit
274025ed33
14 changed files with 431 additions and 69 deletions
28
src/lib/core/stores/adbWriter.ts
Normal file
28
src/lib/core/stores/adbWriter.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { get, writable } from 'svelte/store';
|
||||
import { addNotification } from './noti';
|
||||
|
||||
const adbWriter: any = writable(null);
|
||||
|
||||
async function sendToAndroid(message: any) {
|
||||
let writer: any = get(adbWriter);
|
||||
console.log('writer', writer);
|
||||
if (!writer) {
|
||||
addNotification('ERR:No active connection');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const encoder = new TextEncoder();
|
||||
console.log(writer);
|
||||
await writer.write(encoder.encode(JSON.stringify(message) + '\n'));
|
||||
console.log('sent!');
|
||||
} catch (error) {
|
||||
console.error('write failed', error);
|
||||
}
|
||||
}
|
||||
|
||||
// helper function for checking if connection is ok
|
||||
function isAdbWriterAvailable() {
|
||||
return get(adbWriter) != null;
|
||||
}
|
||||
|
||||
export { sendToAndroid, adbWriter, isAdbWriterAvailable };
|
||||
Loading…
Add table
Add a link
Reference in a new issue