initial working version

This commit is contained in:
riqo 2021-06-16 08:42:47 -05:00
commit d963f7d8a8
23 changed files with 89 additions and 100 deletions

View file

@ -1,7 +1,7 @@
import { postAuth, postLogin, postLogout } from "@/api/account";
import { endSession, launchSession } from "@/session";
import { getToken, clearToken, setToken } from "@/composables/store";
import { getToken, clearToken, setToken } from "./store";
import { parseAuthRes } from "./auth";
export const accountAuth = async (): Promise<Error | AuthState> => {
@ -57,29 +57,6 @@ export const accountLogin: IpcHandlerCallback<AccountCredentials, Profile> = asy
}
}
// export const accountLogin = async (account: Account): Promise<Error | Profile> => {
//
// try {
//
// // attempt login with email password
// const res = await postLogin(account.email, account.password);
// const parsed = parseAuthRes(res);
//
// // save jwt token and profile
// setToken(parsed.token)
//
// // launch session
// launchSession(parsed.token)
//
// // return profile to renderer
// return parsed.profile;
//
// } catch(e) {
// console.log('[ACCOUNT]', e);
// throw (new Error('Failed to authenticate'));
// }
//
// }
export const accountLogout = async (): Promise<Error | void> => {

View file

@ -1,5 +1,5 @@
import { useHttp } from "@/composables/http";
import useHttp from "@/composables/useHttp";
import axios from "axios";
import {config} from "@/config";

View file

@ -1,15 +1,16 @@
/* eslint-disable */
// Backend emitter
//
const EventEmitter = require('events');
class BackgroundMitt extends EventEmitter { }
export const backgroundMitt = new BackgroundMitt();
export default function ipcEmit (channel: string, payload: any) {
export const ipcEmit = (channel: string, payload: any) => {
backgroundMitt.emit('ipc-renderer', {
endpoint: channel,
message: payload
});
}
};

View file

@ -22,7 +22,7 @@ const makeQuery = (reqQuery: Record<string, any>) => {
};
export const useHttp = () => {
export default function useHttp() {
const api = axios.create({
baseURL,

View file

@ -8,6 +8,7 @@
import { app, protocol } from "electron";
import createWindow from "./window";
import main from "./main";
import { backgroundMitt } from '@/composables/useEmitter';
console.log('Starting Crimata electron app.');
@ -18,6 +19,13 @@ protocol.registerSchemesAsPrivileged([
const isDev = require('electron-is-dev');
let win: boolean;
// Listen for window creation.
backgroundMitt.on('window-active', (state: boolean) => {
win = state;
});
/* Start main process on ready */
app.on("ready", async () => {
await main();

View file

@ -2,7 +2,7 @@
"use strict";
import { accountLogin, accountLogout } from "@/account";
import {IpcHandler} from "@/composables/ipcHandler";
import {IpcHandler} from "@/composables/useIpcMain";
const LOGIN_CHANNEL = "account-login";
const LOGOUT_CHANNEL = "account-logout";

View file

@ -12,7 +12,7 @@
import useIpc from "@/ipc/index";
import { accountAuth } from "./account";
import { launchSession } from "./session";
import ipcEmit from "./composables/emitter";
import { ipcEmit } from "./composables/useEmitter";
import createWindow from "./window";
let authState: AuthState | null;
@ -31,8 +31,12 @@ export default async function main() {
console.log('AUTH:', e);
authState = null;
} finally {
if (authState) launchSession(authState.token as string);
ipcEmit("set-profile", authState?.profile);
let profile = null;
if (authState) {
launchSession(authState.token as string);
profile = authState.profile;
}
ipcEmit("set-profile", profile);
}
}

View file

@ -21,8 +21,8 @@
<script lang="ts">
import { defineComponent, onMounted, onUnmounted, Ref } from "vue";
import { invokeProfile } from "@/ipc/account";
import { defineComponent, onMounted, onUnmounted, Ref, ref } from "vue";
import { invokeProfile } from "@/render/ipc";
import Splash from "@/render/components/splash.vue";
import Messenger from "@/render/components/messenger.vue";
@ -47,7 +47,7 @@ export default defineComponent({
/* listen for auth related messages */
window.addEventListener("update-auth", (event: any) => {
state.value = event.data;
// state.value = event.data;
});
});

View file

@ -92,7 +92,7 @@ export function newMessage ({
audio=false,
context=false,
uid=uuidv4()
}): Message {
}) {
return {
text: text,
audio: audio,

View file

@ -1,9 +1,7 @@
import anime from "animejs";
import { useIpc } from '@/modules/ipc';
import { onMounted, onUnmounted, ref, Ref } from "vue";
import { postMessage } from "@/ipc/session";
import { postMessage } from "@/render/ipc";
import { newMessage, animateAudioInput } from "./helpers";
import { invokeStopRecord, postAudioChunk } from "@/ipc/audio";
import { invokeReturnAudio, postAudioChunk } from "@/render/ipc";
export default function useAudioInputController (typing: Ref) {
@ -28,7 +26,7 @@ export default function useAudioInputController (typing: Ref) {
// get audio and post new message to backend
mediaRecorder.addEventListener('stop', (_e: Event) => {
invokeStopRecord().then((audio: ArrayBuffer[] | Error) => {
invokeReturnAudio().then((audio: ArrayBuffer[] | Error) => {
console.log(audio);
// postMessage(newMessage({audio: audio}));
});

View file

@ -1,10 +1,10 @@
import { Ref, ref, watch, onMounted, onUnmounted } from "vue";
import { postMessage } from "@/ipc/session";
import { postMessage } from "@/render/ipc";
import { newMessage, animateTextInput } from "./helpers";
export default function useTextInputController(elementX: Ref) {
let textInput: HTMLInputElement | null;
const { side, show, hide, switchSide } = animateTextInput();
@ -37,10 +37,10 @@ export default function useTextInputController(elementX: Ref) {
// Send it to the backend for processing.
const message = newMessage({
text: textInput.value
text: false
});
postMessage(message);
// postMessage(message);
clearInput()
}

View file

@ -1,5 +1,5 @@
import { ref } from 'vue';
import useScroll from "@/render/composables/scroll";
import useScroll from "@/render/composables/useScroll";
const messagesRef = ref();

View file

@ -14,14 +14,22 @@
<script lang="ts">
import { postNavBarExit, postNavBarMin } from "@/render/ipc";
setup() {
// import { postNavBarExit, postNavBarMin } from "@/render/ipc";
import { defineComponent } from "vue";
export default defineComponent({
name: "Header",
setup() {
const postNavBarExit = () => {};
const postNavBarMin = () => {};
return {
postNavBarExit,
postNavBarMin
}
}
}
});
</script>
@ -78,4 +86,4 @@
.minimizeButton:active {
background-color: #c08e38;
}
</style>
</style>

View file

@ -6,16 +6,16 @@
:style="{ top: `${elementY}px`, left: `${elementX}px` }"
>
<div>{{ initials }}</div>
<!-- Recording animation on space bar -->
<span v-if="recording" class="play"></span>
<span v-if="recording" class="pause"></span>
<!-- Show text input on key-down -->
<input
id="textInput"
type="text"
<input
id="textInput"
type="text"
/>
<!-- Show suggestions menu on click -->
@ -27,24 +27,19 @@
<script lang="ts">
import { defineComponent } from "vue";
import draggify from "@/modules/draggify";
import draggify from "@/render/composables/useDraggify";
import TextInput from "@/components/textInput.vue";
import useTextInputController from
"@/components/controllers/inputItem.control.audio";
import useAudioInputController from
"@/components/controllers/inputItem.control.text";
import useTextInputController from
"@/render/components/controllers/inputItem.control.text";
import useAudioInputController from
"@/render/components/controllers/inputItem.control.audio";
export default defineComponent({
name: "InputItem",
props: ["initials"],
components: {
TextInput
},
setup() {
// Default values for position.

View file

@ -35,11 +35,8 @@
<script lang="ts">
import { defineComponent, ref } from "vue";
import { useIpc } from "@/modules/ipc";
import { authRequest } from '@/modules/message';
import { useProfile } from '@/modules/auth';
import { invokeLogin } from "@/ipcRend/account";
import { postInitSession } from "@/ipcRend/session";
import { useProfile } from '@/render/composables/useProfile';
import { invokeLogin } from "@/render/ipc";
export default defineComponent({
name: "Login",
@ -49,6 +46,8 @@ export default defineComponent({
const usr = ref("");
const pwd = ref("");
const { setProfile } = useProfile();
// Submit login credentials to the backend.
const submitForm = async () => {
@ -57,12 +56,14 @@ export default defineComponent({
const profile = await invokeLogin({
email: usr.value,
password: pwd.value
});
}) as Profile;
/* emit event to app.vue */
window.postMessage(profile);
setProfile(profile)
} catch (e) console.log(e);
} catch(e) {
console.log(e);
};
}

View file

@ -20,7 +20,6 @@
<script lang="ts">
import { defineComponent, onMounted, onUnmounted } from "vue";
import Message from "@/render/components/message.vue";
import InputItem from "@/render/components/inputItem.vue";
import Settings from "@/render/components/settings.vue";
import useMessages from "./controllers/messenger.control";
@ -31,7 +30,6 @@ export default defineComponent({
props: ["profile", "messages"],
components: {
Message,
InputItem,
Settings
},
@ -39,7 +37,7 @@ export default defineComponent({
setup(props) {
// Handle messages in view.
const { messagesRef, updateMessageView } = useMessages();
const { messagesRef } = useMessages();
onMounted(() => {

View file

@ -28,9 +28,7 @@
<script lang="ts">
import { defineComponent, ref } from "vue";
import { useIpc } from "@/modules/ipc";
import { logoutRequest } from '@/modules/message';
import { useProfile } from "@/modules/auth"
import { useProfile } from "@/render/composables/useProfile"
import { invokeLogout } from "@/render/ipc";
export default defineComponent({
@ -39,8 +37,6 @@
setup() {
const toggleSettings = ref(false);
const { post, invoke } = useIpc();
const { clearProfile } = useProfile();
// Listen for escape key to close settings.
@ -63,8 +59,8 @@
console.log("Submitting logout request.");
try {
clearProfile();
await invokeLogout();
clearProfile();
} catch(e) {
console.log('error')
}

View file

@ -6,6 +6,8 @@ export const useProfile = () => {
const setProfile = (payload: Profile) => {
profile.value = payload;
/* emit event to app.vue */
window.postMessage(profile, 'profile');
}
const clearProfile = () => {

View file

@ -1,13 +1,13 @@
import useIpc from "@/render/composables/ipc";
import useIpc from "@/render/composables/useIpcRend";
const { post, invoke } = useIpc();
/**
*
*
* Account and auth related endpoints
*
*/
*
*/
export const invokeProfile = async (): Promise<Profile | Error> => (
await invoke('user-profile', null)
@ -24,9 +24,9 @@ export const invokeLogout = async (): Promise<void> => (
);
/**
*
*
* Audio endpoints
*
*
*/
export const postAudioChunk = (chunk: ArrayBuffer): void => (
@ -38,9 +38,9 @@ export const invokeReturnAudio = async (): Promise<ArrayBuffer[] | Error> => (
);
/**
*
*
* Crimata Platform (session) endpoints
*
*
*/
export const invokeSession = async (cid: string): Promise<Profile | Error> => (
@ -49,4 +49,4 @@ export const invokeSession = async (cid: string): Promise<Profile | Error> => (
export const postMessage = (payload: Message): void => (
post('client-message', payload)
);
);

View file

@ -3,8 +3,8 @@
// import useAudio from "@/audio";
import ipcEmit from "@/composables/emitter";
import useWebsockets from "./composables/websockets";
import ipcEmit from "@/composables/useEmitter";
import useWebsockets from "./composables/useWebsockets";
import {config} from "@/config";
/* data structure of messages that's tied to the UI */

View file

@ -4,7 +4,6 @@ interface Message {
context: boolean | string;
audio: boolean | string;
type: 1 | 2 | 3;
time: number;
uid: string;
}

View file

@ -2,8 +2,8 @@
import { BrowserWindow, ipcMain, app } from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import { backgroundMitt } from './composables/emitter';
import { saveToJson } from "./composables/json";
import { backgroundMitt } from './composables/useEmitter';
import { saveToJson } from "./composables/useSaveToJSON";
import * as path from "path";
import fs from 'fs';
import { config } from "@/config";