]> Repos - mime-chat/commitdiff
updating
authorAndrew Gundersen <gundersena@xavier.edu>
Sat, 20 Mar 2021 14:50:53 +0000 (09:50 -0500)
committerAndrew Gundersen <gundersena@xavier.edu>
Sat, 20 Mar 2021 14:50:53 +0000 (09:50 -0500)
src/App.vue
src/background/init.ts
src/background/session.ts
src/background/window.ts
src/components/inputItem/inputItem.vue
src/views/messenger.vue
windowState.json

index 192910854f2dc072e468f13413dbef19b28e50e9..308977c0f8d06cd91ec084d8dbf7819fa86aeb37 100644 (file)
@@ -20,6 +20,7 @@
 
   </div>
 
+  <!-- Show spash screen if not ready -->
   <Splash v-else />
   
 </template>
@@ -34,34 +35,29 @@ export default defineComponent({
   components: { Splash },
 
   setup() {
-    const { invoke } = useIpc();
-    const ready = ref(false);
-    const { saveMessages } = useMessages();
 
-    onMounted(() => {
-        window.ipcRenderer.on('window-ready', (_event, payload: {message: boolean}) => {
-            ready.value = payload.message;
-        })
-    });
+    // Show spash screen til true.
+    const ready = ref(false);
 
-    onUnmounted(() => {
-        window.ipcRenderer.removeAllListeners('window-ready')
-    })
+    const { invoke } = useIpc();
 
-    const saveWindowState = async () => {
-      await invoke('window-save', "");
+    // Post navbar action to backend.
+    const callNavbar = (action: string) => {
+      console.log("Calling navbar")
+      invoke('nav-bar', action);
     }
 
-    const callNavbar = async (action: string) => {
+    const onWindowReady = (_event: any, payload: any) => {
+      ready.value = true;
+    }
 
-      // save messages before closing.
-      if (action === 'close') {
-        saveMessages();
-        await saveWindowState();
-      }
+    onMounted(() => {
+        window.ipcRenderer.on("window-ready", onWindowReady);
+    });
 
-      invoke('nav-bar', action);
-    }
+    onUnmounted(() => {
+        window.ipcRenderer.removeAllListeners("window-ready")
+    })
 
     return {
         callNavbar,
@@ -77,7 +73,7 @@ export default defineComponent({
 html, body {
   margin: 0;
   padding: 0;
-  background-color: #EBEBEB;
+  // Background color set in window.ts
 }
 
 #app {
index 0f60068dea08420b7e1e87f30ef6e5fbcb808d3b..cb900506ece9c426e7c0c9556497ac31f053a65b 100644 (file)
@@ -9,7 +9,7 @@ import { stopStream } from './audio';
 let winActive: boolean;
 
 backgroundMitt.on('window-active', (state: boolean) => {
-    winActive =  state;
+    winActive = state;
 });
 
 export function initApp(dev: boolean): void {
index 27a55469cf32c83eadc896048a3e68de8ac523d2..766df034aa6654a20d54188078b09f40a2e5c6ec 100644 (file)
@@ -59,7 +59,6 @@ const handleAuthMessage = (message: string) => {
 }
 
 const handleProfileMessage = (message: Profile) => {
-    console.log("Updating profile...")
     backgroundMitt.emit('ipc-renderer', {
         endpoint: 'update-profile',
         message: message
@@ -86,7 +85,6 @@ const handleStandardMessage = (m: StandardMessage) => {
 }
 
 const handleAnnotationMessage = (message: Annotation) => {
-    console.log("Annotation message")
     backgroundMitt.emit('ipc-renderer', {
         endpoint: 'annotate-message',
         message: message 
index d46da182ab0cd8caafd8f4b564ed298d084dc24b..a34427ba609b687b28b44e18d0c049ff776a34b7 100644 (file)
@@ -14,16 +14,17 @@ interface IpcRendererPayload {
 
 let win: BrowserWindow | null;
 
-// Util function to handle window close & minimize.
-const navBarHandler = (_event, action: string): void => {
-    switch(action) {
-        case 'close':
-            if (win) win.close();
-        break;
-        case 'min':
-            if (win) win.minimize();
-        break;
+// Called when a NavBar button is pressed.
+const onNavBar = (_event: any, action: string): void => {
+  console.log("onNavBar")
+  if (win) {
+    if (action === "close") {
+      saveWindowState()
+      win.close()
+    } else {
+      win.minimize()
     }
+  }
 }
 
 // Util function to render message on ipc-renderer event.
@@ -35,34 +36,42 @@ const renderMessage = (payload: IpcRendererPayload): void => {
     }
 }
 
-const onWindowSave = (_event, _s: string) => {
+// Write a json with position and size of window.
+const saveWindowState = () => {
     if (win) {
        const bounds = win.getBounds();
-       const state = JSON.stringify({w: bounds.width, h: bounds.height});
-
-       fs.writeFile('windowstate.json', state, (err: Error) => {
+       const position = win.getPosition();
+
+       const state = JSON.stringify(
+         {
+           w: bounds.width, 
+           h: bounds.height,
+           x: position[0],
+           y: position[1]
+         }
+       );
+
+       fs.writeFile('windowState.json', state, (err) => {
           if (err) throw err;      
           return;
        }); 
     }    
-
 }
 
 // Do this on window mount.
-const windowMount = (): void => {
+const onWindowMount = (): void => {
     backgroundMitt.emit('window-active', true);
+
     // handle win nav-bar event.
     ipcMain.removeHandler('nav-bar'); // avoid setting duplicate handlers
-    ipcMain.handle('nav-bar', navBarHandler);
-
-    ipcMain.removeHandler('window-save'); // avoid setting duplicate handlers
-    ipcMain.handle('window-save', onWindowSave);
-    // render messages through ipc-renderer.
+    ipcMain.handle('nav-bar', onNavBar);
+    
+    // Gateway for messages to the frontend.
     backgroundMitt.on('ipc-renderer', renderMessage);
 }
 
-// do this on window dismount.
-const windowDismount = (): void => {
+// Do this on window dismount (close).
+const onWindowDismount = (): void => {
     win = null;
     backgroundMitt.emit('window-active', false);
 }
@@ -74,49 +83,48 @@ export async function createWindow(): Promise<void> {
     // avoid creating duplicate windows.
     if (win) resolve();
 
-    // read windowState from json.
-    const rawData = fs.readFileSync('windowState.json');
-    const windowState = JSON.parse(rawData);
+    // Load the saved window state.
+    const state = JSON.parse(fs.readFileSync('windowState.json').toString());
 
+    // Define the browser window.
     win = new BrowserWindow({
-      width: windowState.w,
-      height: windowState.h,
+      width: state.w,
+      height: state.h,
+      x: state.x,
+      y: state.y,
       resizable: true,
       backgroundColor: '#EBEBEB',
       frame: false,
       minWidth: 350,
       minHeight: 500,
       webPreferences: {
-        // Use pluginOptions.nodeIntegration, leave this alone
-        // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
-        nodeIntegration: (process.env
-          .ELECTRON_NODE_INTEGRATION as unknown) as boolean,
-        preload: path.join(__dirname, "preload.js")
+        nodeIntegration: (process.env.ELECTRON_NODE_INTEGRATION as unknown) as boolean, preload: path.join(__dirname, "preload.js")
       }
     });
 
-
+    // Load the URL.
     if (process.env.WEBPACK_DEV_SERVER_URL) {
-      // Load the url of the dev server if in development mode
-      win.loadURL(process.env.WEBPACK_DEV_SERVER_URL as string);
-    } else {
+      win.loadURL(process.env.WEBPACK_DEV_SERVER_URL as string); // dev
+    } 
+
+    else {
       createProtocol("app");
-      // Load the index.html when not in development
-      win.loadURL("app://./index.html");
+      win.loadURL("app://./index.html"); // prod
     }
 
     // Handle window close.
-    win.on("closed", windowDismount);
+    win.on("closed", onWindowDismount);
 
     win.once('ready-to-show', () => {
       if (win) win.show()
     })
 
     win.webContents.on('did-finish-load', () => {
-        if (win) win.webContents.send('window-ready', {
-            message: true
-        });
-      windowMount();
+      if (win) win.webContents.send('window-ready', {
+          message: true
+      });
+
+      onWindowMount();
       resolve();
     });
 
index 8ea6a5d0136de610a6f7386504f171e395baf73a..91ef8631d23c70a346d94dcef40a098f0ee27712 100644 (file)
@@ -41,11 +41,23 @@ export default defineComponent({
 
     // Mark input item with user's initials.
     const initials = ref("")
-    initials.value = "IN";
 
-    // Initial position.
-    const xStart = 15;
-    const yStart = window.innerHeight - 200;
+    // ---Set xStart and yStart------------------------------------
+    const cordsStr = window.localStorage.getItem("input_cords")
+
+    let cords = {x: 15, y: window.innerHeight - 200} // default values
+
+    if (cordsStr) {
+      console.log("found archived cords!")
+      cords = JSON.parse(cordsStr)
+    }
+
+    const xStart = cords.x;
+    const yStart = cords.y;
+
+    console.log(`xStart: ${xStart}`)
+    console.log(`yStart: ${yStart}`)
+    // ------------------------------------------------------------
 
     // Calculate position of inputItem on drag.
     const { elementX, elementY } = draggify("inputItem", xStart, yStart, 15);
@@ -63,6 +75,17 @@ export default defineComponent({
       window.ipcRenderer.on("update-profile", onUpdateProfile);
     }) 
 
+    const savePosition = () => {
+      const cords = JSON.stringify(
+        {
+          x: elementX.value, 
+          y: elementY.value
+        }
+      )
+      window.localStorage.setItem("input_cords", cords)
+      console.log(`Start saved: ${cords}`)
+    }
+
     onUnmounted(() => {
       window.ipcRenderer.removeAllListeners("update-profile");
     })
index 9be42efc9518ea25f48a33ed30d1e348b7934451..5c28758d55c3072f325a16d23a23cb5c3c23b117 100644 (file)
@@ -32,7 +32,12 @@ export default defineComponent({
     const { emitter } = useMitt();
 
     // Handle messages in view.
-    const { messages, addMessage, updateMessage } = useMessages();
+    const { 
+      messages, 
+      addMessage, 
+      updateMessage,
+      saveMessages
+    } = useMessages();
 
     // Alter existing message.
     const onAnnotateMessage = (_event: any, payload: any) => {
index d637d9e85b5429a6a431205e3f8fd452644b84eb..99576889072f57cf4728d334be291d7788b897ef 100644 (file)
@@ -1 +1 @@
-{"w":352,"h":500}
\ No newline at end of file
+{"w":688,"h":536,"x":1478,"y":513}
\ No newline at end of file