Project: A Desktop Document Manager

Combine file import, IPC, status feedback, and PDF saving to build a simple desktop document manager.

🎯 Project goal

Build a small document manager: users select text files, the page shows a file list and read status, and the current documents can be exported as a PDF. This example establishes a complete desktop workflow without a complex backend.


🧱 Divide the responsibilities

FeatureResponsible layer
Page buttons, lists, and statusVue renderer process
Exposing openFile and exportReportPreload script
Opening files, reading contents, and saving PDFsMain process
Application windows, error handling, and lifecycleElectron main process

The page only needs to know whether a request succeeded. It does not access file paths or system modules directly.


🛠 Design a minimal API

electron/preload.js
const { contextBridge, ipcRenderer } = require('electron/renderer');

contextBridge.exposeInMainWorld('electronAPI', {
    openTextFile: () => ipcRenderer.invoke('file:open-text'),
    exportReport: data => ipcRenderer.invoke('report:export', data),
});

Each method corresponds to one specific action. The main process must still validate the type and length of data; requests from your own page must not bypass validation.


🖥 Vue page state

src/App.vue
<script setup>
import { ref } from 'vue';

const files = ref([]);
const status = ref('Ready to import');

async function openFile() {
    status.value = 'Reading';

    try {
        const file = await window.electronAPI.openTextFile();

        if (!file) {
            status.value = 'Canceled';
            return;
        }

        files.value.push(file);
        status.value = 'Read complete';
    } catch {
        status.value = 'Read failed';
    }
}
</script>

<template>
    <main>
        <button type="button" @click="openFile">Import text</button>
        <p>Status: {{ status }}</p>
        <ul>
            <li v-for="file in files" :key="file.name">
                {{ file.name }}
            </li>
        </ul>
    </main>
</template>

Focus on state changes for now, without adding complex list editing, databases, or permission models. As your project needs these features, introduce them as separate modules.


📄 Report saving and delivery checks

When exporting a report, the main process generates the PDF while the page displays the exporting, success, or failure state. Then check the following in order:

  1. Canceling selection does not leave unnecessary error messages on the page.
  2. After a file read fails, the page can still import other files.
  3. Report contents come from the current documents rather than hard-coded sample data.
  4. The export window closes after both success and failure.
  5. The packaged app can still locate the Vue page and report resources.

🧾 Project summary

  • Vue manages the page and its state; Electron provides desktop capabilities.
  • The preload script exposes system capabilities through small APIs.
  • The main process validates arguments and handles files and PDFs.
  • The page must display waiting, canceled, success, and failure states.
  • Before release, recheck resources and file workflows in the packaged app.

❓ Questions and answers

Q1: Why not let Vue read files directly?

That would undermine process boundaries and security settings. Exposing an API through a preload script makes permissions easier to control.

Q2: Why not connect a database at the start of the project?

This course first practices Electron's core end-to-end workflow. A database introduces extra concepts; beginners should first understand file import and status feedback.

🧪 Practice

Add an “Export” button to each list item and call the reserved exportReport API:

<button type="button">
    <!-- Write your code here -->
</button>

🎉 You have completed a basic desktop workflow from file import to report saving!