initial working version
This commit is contained in:
parent
0a3c9f71d8
commit
d963f7d8a8
23 changed files with 89 additions and 100 deletions
|
|
@ -73,7 +73,9 @@
|
|||
"lintOnSave": false,
|
||||
"pluginOptions": {
|
||||
"electronBuilder": {
|
||||
"preload": "src/renderer/preload.ts",
|
||||
"mainProcessFile": "./src/init.ts",
|
||||
"rendererProcessFile": "./src/render/main.ts",
|
||||
"preload": "./src/render/preload.ts",
|
||||
"builderOptions": {
|
||||
"appId": "com.crimata.ElectronUpdaterApp",
|
||||
"artifactName": "${productName}-${version}.${ext}",
|
||||
|
|
|
|||
|
|
@ -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> => {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
import { useHttp } from "@/composables/http";
|
||||
import useHttp from "@/composables/useHttp";
|
||||
import axios from "axios";
|
||||
import {config} from "@/config";
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const makeQuery = (reqQuery: Record<string, any>) => {
|
|||
};
|
||||
|
||||
|
||||
export const useHttp = () => {
|
||||
export default function useHttp() {
|
||||
|
||||
const api = axios.create({
|
||||
baseURL,
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
10
src/main.ts
10
src/main.ts
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ export function newMessage ({
|
|||
audio=false,
|
||||
context=false,
|
||||
uid=uuidv4()
|
||||
}): Message {
|
||||
}) {
|
||||
return {
|
||||
text: text,
|
||||
audio: audio,
|
||||
|
|
|
|||
|
|
@ -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}));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Ref, ref, watch, onMounted, onUnmounted } from "vue";
|
||||
import { postMessage } from "@/ipc/session";
|
||||
import { postMessage } from "@/render/ipc";
|
||||
import { newMessage, animateTextInput } from "./helpers";
|
||||
|
||||
|
||||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { ref } from 'vue';
|
||||
import useScroll from "@/render/composables/scroll";
|
||||
import useScroll from "@/render/composables/useScroll";
|
||||
|
||||
const messagesRef = ref();
|
||||
|
||||
|
|
|
|||
|
|
@ -14,15 +14,23 @@
|
|||
|
||||
<script lang="ts">
|
||||
|
||||
import { postNavBarExit, postNavBarMin } from "@/render/ipc";
|
||||
// import { postNavBarExit, postNavBarMin } from "@/render/ipc";
|
||||
import { defineComponent } from "vue";
|
||||
|
||||
export default defineComponent({
|
||||
name: "Header",
|
||||
setup() {
|
||||
const postNavBarExit = () => {};
|
||||
const postNavBarMin = () => {};
|
||||
return {
|
||||
postNavBarExit,
|
||||
postNavBarMin
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
"@/render/components/controllers/inputItem.control.text";
|
||||
import useAudioInputController from
|
||||
"@/components/controllers/inputItem.control.text";
|
||||
"@/render/components/controllers/inputItem.control.audio";
|
||||
|
||||
export default defineComponent({
|
||||
name: "InputItem",
|
||||
|
||||
props: ["initials"],
|
||||
|
||||
components: {
|
||||
TextInput
|
||||
},
|
||||
|
||||
setup() {
|
||||
|
||||
// Default values for position.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(() => {
|
||||
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = () => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
import useIpc from "@/render/composables/ipc";
|
||||
import useIpc from "@/render/composables/useIpcRend";
|
||||
|
||||
const { post, invoke } = useIpc();
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ interface Message {
|
|||
context: boolean | string;
|
||||
audio: boolean | string;
|
||||
type: 1 | 2 | 3;
|
||||
time: number;
|
||||
uid: string;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
Loading…
Reference in a new issue