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

@ -73,7 +73,9 @@
"lintOnSave": false, "lintOnSave": false,
"pluginOptions": { "pluginOptions": {
"electronBuilder": { "electronBuilder": {
"preload": "src/renderer/preload.ts", "mainProcessFile": "./src/init.ts",
"rendererProcessFile": "./src/render/main.ts",
"preload": "./src/render/preload.ts",
"builderOptions": { "builderOptions": {
"appId": "com.crimata.ElectronUpdaterApp", "appId": "com.crimata.ElectronUpdaterApp",
"artifactName": "${productName}-${version}.${ext}", "artifactName": "${productName}-${version}.${ext}",

View file

@ -1,7 +1,7 @@
import { postAuth, postLogin, postLogout } from "@/api/account"; import { postAuth, postLogin, postLogout } from "@/api/account";
import { endSession, launchSession } from "@/session"; import { endSession, launchSession } from "@/session";
import { getToken, clearToken, setToken } from "@/composables/store"; import { getToken, clearToken, setToken } from "./store";
import { parseAuthRes } from "./auth"; import { parseAuthRes } from "./auth";
export const accountAuth = async (): Promise<Error | AuthState> => { 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> => { 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 axios from "axios";
import {config} from "@/config"; import {config} from "@/config";

View file

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

View file

@ -8,6 +8,7 @@
import { app, protocol } from "electron"; import { app, protocol } from "electron";
import createWindow from "./window"; import createWindow from "./window";
import main from "./main"; import main from "./main";
import { backgroundMitt } from '@/composables/useEmitter';
console.log('Starting Crimata electron app.'); console.log('Starting Crimata electron app.');
@ -18,6 +19,13 @@ protocol.registerSchemesAsPrivileged([
const isDev = require('electron-is-dev'); 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 */ /* Start main process on ready */
app.on("ready", async () => { app.on("ready", async () => {
await main(); await main();

View file

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

View file

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

View file

@ -21,8 +21,8 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, onMounted, onUnmounted, Ref } from "vue"; import { defineComponent, onMounted, onUnmounted, Ref, ref } from "vue";
import { invokeProfile } from "@/ipc/account"; import { invokeProfile } from "@/render/ipc";
import Splash from "@/render/components/splash.vue"; import Splash from "@/render/components/splash.vue";
import Messenger from "@/render/components/messenger.vue"; import Messenger from "@/render/components/messenger.vue";
@ -47,7 +47,7 @@ export default defineComponent({
/* listen for auth related messages */ /* listen for auth related messages */
window.addEventListener("update-auth", (event: any) => { 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, audio=false,
context=false, context=false,
uid=uuidv4() uid=uuidv4()
}): Message { }) {
return { return {
text: text, text: text,
audio: audio, 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 { onMounted, onUnmounted, ref, Ref } from "vue";
import { postMessage } from "@/ipc/session"; import { postMessage } from "@/render/ipc";
import { newMessage, animateAudioInput } from "./helpers"; import { newMessage, animateAudioInput } from "./helpers";
import { invokeStopRecord, postAudioChunk } from "@/ipc/audio"; import { invokeReturnAudio, postAudioChunk } from "@/render/ipc";
export default function useAudioInputController (typing: Ref) { export default function useAudioInputController (typing: Ref) {
@ -28,7 +26,7 @@ export default function useAudioInputController (typing: Ref) {
// get audio and post new message to backend // get audio and post new message to backend
mediaRecorder.addEventListener('stop', (_e: Event) => { mediaRecorder.addEventListener('stop', (_e: Event) => {
invokeStopRecord().then((audio: ArrayBuffer[] | Error) => { invokeReturnAudio().then((audio: ArrayBuffer[] | Error) => {
console.log(audio); console.log(audio);
// postMessage(newMessage({audio: audio})); // postMessage(newMessage({audio: audio}));
}); });

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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