Skip to content

Commit 24aec44

Browse files
author
Tim Sinaeve
committed
feat(sync): integrate computer name in default cloud database filename and add global sync error toast alerts
1 parent 79cead6 commit 24aec44

9 files changed

Lines changed: 146 additions & 20 deletions

File tree

‎App.tsx‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ export const MainApp: React.FC = () => {
233233
});
234234
const [confirmAction, setConfirmAction] = useState<{ title: string; message: React.ReactNode; onConfirm: () => void; } | null>(null);
235235
const [clipboardNotice, setClipboardNotice] = useState<{ title: string; message: React.ReactNode; helpUrl?: string } | null>(null);
236+
const [syncToast, setSyncToast] = useState<{ visible: boolean; message: string; }>({ visible: false, message: '' });
236237
const [searchTerm, setSearchTerm] = useState('');
237238
const previousSearchTermRef = useRef('');
238239
const [contextMenu, setContextMenu] = useState<{ isOpen: boolean; position: { x: number, y: number }, items: MenuItem[] }>({ isOpen: false, position: { x: 0, y: 0 }, items: [] });
@@ -1425,8 +1426,28 @@ export const MainApp: React.FC = () => {
14251426
onUpdateDownloadProgress,
14261427
onUpdateDownloaded,
14271428
onUpdateError,
1429+
onSyncStatus,
14281430
} = window.electronAPI;
14291431

1432+
if (onSyncStatus) {
1433+
cleanups.push(onSyncStatus((payload) => {
1434+
if (payload.status === 'syncing') {
1435+
setDatabaseStatus({ message: payload.message || 'Syncing database...', tone: 'info' });
1436+
} else if (payload.status === 'conflict') {
1437+
setDatabaseStatus({ message: 'Sync conflict detected.', tone: 'error' });
1438+
} else if (payload.status === 'error') {
1439+
setDatabaseStatus({ message: payload.message || 'Sync failed.', tone: 'error' });
1440+
setSyncToast({
1441+
visible: true,
1442+
message: payload.message || 'An error occurred during database synchronization.'
1443+
});
1444+
} else {
1445+
setDatabaseStatus({ message: payload.message || 'Database ready', tone: 'info' });
1446+
setSyncToast(prev => prev.visible ? { ...prev, visible: false } : prev);
1447+
}
1448+
}));
1449+
}
1450+
14301451
if (onUpdateAvailable) {
14311452
cleanups.push(onUpdateAvailable((info) => {
14321453
const versionLabel = info.version ?? info.releaseName ?? 'latest';
@@ -3601,6 +3622,58 @@ export const MainApp: React.FC = () => {
36013622
/>
36023623
)}
36033624

3625+
{syncToast.visible && (
3626+
<div className="fixed bottom-6 right-6 z-50 w-full max-w-sm animate-slide-in-up">
3627+
<div className="bg-secondary/95 backdrop-blur-xl rounded-xl shadow-2xl border border-destructive/30 p-5">
3628+
<div className="flex items-start gap-4">
3629+
<div className="flex-shrink-0 w-10 h-10 rounded-full bg-destructive/15 flex items-center justify-center border border-destructive/35">
3630+
<span className="text-lg">⚠️</span>
3631+
</div>
3632+
<div className="flex-1 space-y-1">
3633+
<h4 className="text-sm font-semibold text-text-main">Cloud Sync Error</h4>
3634+
<p className="text-xs text-text-secondary leading-normal break-words">
3635+
{syncToast.message || 'An error occurred during database synchronization.'}
3636+
</p>
3637+
<div className="flex items-center gap-2 mt-3 pt-2 border-t border-border-color/30">
3638+
<button
3639+
type="button"
3640+
onClick={() => {
3641+
setView('settings');
3642+
setSyncToast(prev => ({ ...prev, visible: false }));
3643+
}}
3644+
className="px-3 py-1.5 text-xs font-semibold text-accent-text bg-primary rounded-md hover:bg-primary/95 focus:outline-none transition-colors"
3645+
>
3646+
Open Settings
3647+
</button>
3648+
<button
3649+
type="button"
3650+
onClick={() => setSyncToast(prev => ({ ...prev, visible: false }))}
3651+
className="px-3 py-1.5 text-xs rounded-md border border-border-color bg-background hover:bg-secondary text-text-main focus:outline-none transition-colors"
3652+
>
3653+
Dismiss
3654+
</button>
3655+
</div>
3656+
</div>
3657+
</div>
3658+
</div>
3659+
<style>{`
3660+
@keyframes slide-in-up {
3661+
from {
3662+
transform: translateY(1rem);
3663+
opacity: 0;
3664+
}
3665+
to {
3666+
transform: translateY(0);
3667+
opacity: 1;
3668+
}
3669+
}
3670+
.animate-slide-in-up {
3671+
animation: slide-in-up 0.28s ease-out forwards;
3672+
}
3673+
`}</style>
3674+
</div>
3675+
)}
3676+
36043677
{clipboardNotice && (
36053678
<InfoModal
36063679
title={clipboardNotice.title}

‎FUNCTIONAL_MANUAL.md‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,26 +260,33 @@ DocForge allows you to maintain a complete history of your document's content.
260260

261261
### Google Drive Cloud Database Sync
262262

263-
Google Drive Cloud Sync lets you back up and synchronize your SQLite database (`docforge.db`) between different machines securely using your own Google account credentials.
263+
Google Drive Cloud Sync lets you back up and synchronize your SQLite database between different machines securely using your own Google account credentials.
264264

265-
#### 1. OAuth Setup & Prerequisites
265+
#### 1. Hostname-Based Database Separation
266+
By default, DocForge constructs a target backup filename incorporating your sanitized local computer name (e.g. `docforge-[computer-name].db`). This prevents different machines from accidentally overwriting each other's databases on first connection, allowing home and work databases to exist side-by-side in your private Google Drive space.
267+
268+
#### 2. Switching Database Files
269+
You can select a different synchronization target file at any time by clicking the database dropdown list in **Settings** -> **Cloud Sync**. This automatically resets internal tracking hashes and swaps the active database safely.
270+
271+
#### 3. OAuth Setup & Prerequisites
266272
To connect Google Drive Sync, you must supply your own Google Cloud Console credentials. This ensures your data remains completely private and under your control.
267273
1. **Google Cloud Project:** Create a project in the Google Cloud Console.
268274
2. **Enable Google Drive API:** Search for the **Google Drive API** in your project's API Library and enable it. *Note: If this API is not enabled, synchronization will fail with a `Drive search failed: Forbidden` error.*
269275
3. **OAuth Consent Screen:** Configure the consent screen and add the `https://www.googleapis.com/auth/drive.appdata` scope. Since the application will be in testing mode, make sure to add your Gmail address as a **Test User**.
270276
4. **OAuth Client ID:** Create credentials of type **OAuth Client ID** and select **Desktop Application**. Copy the generated Client ID and Client Secret.
271277

272-
#### 2. Linking Your Account
278+
#### 4. Linking Your Account
273279
In DocForge's **Cloud Sync** settings section, paste your Client ID and Client Secret, then click **Connect Account**. A temporary server will bind to `http://127.0.0.1:52080` to listen for the OAuth response. Complete the consent flow in your default browser, after which DocForge will show your connected Google email.
274280

275-
#### 3. Sandbox Privacy
281+
#### 5. Sandbox Privacy
276282
DocForge utilizes Google Drive's isolated **Application Data folder** (`appDataFolder`). This is a hidden sandbox space that other applications cannot read or access, and DocForge itself cannot access any other files, folders, or documents in your main Google Drive.
277283

278-
#### 4. Automatic vs. Manual Synchronization
284+
#### 6. Automatic vs. Manual Synchronization
279285
- **Sync on Startup & Shutdown:** Automatically checks for database changes, pushing or pulling the SQLite database as soon as you launch or close the app.
280286
- **Manual Sync ("Sync Now"):** Manually run a sync check at any point from the settings screen.
281287
- **Conflict Resolution:** If local and cloud databases have modified concurrently since the last sync, the synchronization pauses and triggers a **Conflict Resolution Modal**. This dialog displays a side-by-side comparison of local and remote database file sizes, modified dates, document counts, and template counts so you can safely choose which database version to keep ("Keep Local" or "Keep Cloud").
282288

289+
283290
---
284291

285292
## 3. Views and Panels

‎VERSION_LOG.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
## Unreleased
22

3-
- _No entries yet._
3+
### ✨ Features
4+
5+
- **Computer-Name Suffix for Cloud Sync Databases**:
6+
- Automatically appends the sanitized local computer hostname to the default Google Drive sync database filename (e.g. `docforge-[computer-name].db`).
7+
- Supports listing and switching target synchronization databases from other machines via the Database settings dropdown.
8+
- **Global Sync Status & Error Alerts**:
9+
- Integrated real-time sync status updates (`syncing`, `conflict`, `error`) into the bottom status bar.
10+
- Added a global, glassmorphic sync error toast notification that appears on any synchronization failure, displaying clear error diagnostics and a one-click button to jump to **Settings**.
11+
412

513
## v0.9.1 - The Google Drive Multi-Database Sync Update
614

‎components/settings/CloudSyncSettingsSection.tsx‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export const CloudSyncSettingsSection: React.FC<Pick<SectionProps, 'settings' |
3131

3232
const [remoteDbs, setRemoteDbs] = useState<{ name: string; id: string; modifiedTime: string }[]>([]);
3333
const [isLoadingDbs, setIsLoadingDbs] = useState(false);
34-
const [selectedDbName, setSelectedDbName] = useState(settings.syncDatabaseName || 'docforge.db');
34+
const defaultDbName = settings.defaultSyncDatabaseName || 'docforge.db';
35+
const [selectedDbName, setSelectedDbName] = useState(settings.syncDatabaseName || defaultDbName);
3536
const [customDbNameInput, setCustomDbNameInput] = useState('');
3637
const [isCustomNaming, setIsCustomNaming] = useState(false);
3738
const [dbNameError, setDbNameError] = useState<string | null>(null);
@@ -64,8 +65,10 @@ export const CloudSyncSettingsSection: React.FC<Pick<SectionProps, 'settings' |
6465
useEffect(() => {
6566
if (settings.syncDatabaseName) {
6667
setSelectedDbName(settings.syncDatabaseName);
68+
} else {
69+
setSelectedDbName(defaultDbName);
6770
}
68-
}, [settings.syncDatabaseName]);
71+
}, [settings.syncDatabaseName, defaultDbName]);
6972

7073
// Sync state changes from main process
7174
useEffect(() => {
@@ -466,14 +469,17 @@ export const CloudSyncSettingsSection: React.FC<Pick<SectionProps, 'settings' |
466469
}}
467470
className="flex-1 px-3 py-1.5 text-xs rounded-md border border-border-color bg-background text-text-main focus:outline-none focus:ring-1 focus:ring-primary/50"
468471
>
469-
<option value="docforge.db">docforge.db (Default)</option>
470-
{selectedDbName !== 'docforge.db' && !remoteDbs.some(d => d.name === selectedDbName) && (
472+
<option value={defaultDbName}>{defaultDbName} (Default for this PC)</option>
473+
{defaultDbName !== 'docforge.db' && (
474+
<option value="docforge.db">docforge.db (Standard)</option>
475+
)}
476+
{selectedDbName !== defaultDbName && selectedDbName !== 'docforge.db' && !remoteDbs.some(d => d.name === selectedDbName) && (
471477
<option value={selectedDbName}>
472478
{selectedDbName} (configured)
473479
</option>
474480
)}
475481
{remoteDbs.map((dbFile) => {
476-
if (dbFile.name === 'docforge.db') return null;
482+
if (dbFile.name === defaultDbName || dbFile.name === 'docforge.db') return null;
477483
return (
478484
<option key={dbFile.id} value={dbFile.name}>
479485
{dbFile.name} (cloud)

‎docs/FUNCTIONAL_MANUAL.md‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,26 +260,33 @@ DocForge allows you to maintain a complete history of your document's content.
260260

261261
### Google Drive Cloud Database Sync
262262

263-
Google Drive Cloud Sync lets you back up and synchronize your SQLite database (`docforge.db`) between different machines securely using your own Google account credentials.
263+
Google Drive Cloud Sync lets you back up and synchronize your SQLite database between different machines securely using your own Google account credentials.
264264

265-
#### 1. OAuth Setup & Prerequisites
265+
#### 1. Hostname-Based Database Separation
266+
By default, DocForge constructs a target backup filename incorporating your sanitized local computer name (e.g. `docforge-[computer-name].db`). This prevents different machines from accidentally overwriting each other's databases on first connection, allowing home and work databases to exist side-by-side in your private Google Drive space.
267+
268+
#### 2. Switching Database Files
269+
You can select a different synchronization target file at any time by clicking the database dropdown list in **Settings** -> **Cloud Sync**. This automatically resets internal tracking hashes and swaps the active database safely.
270+
271+
#### 3. OAuth Setup & Prerequisites
266272
To connect Google Drive Sync, you must supply your own Google Cloud Console credentials. This ensures your data remains completely private and under your control.
267273
1. **Google Cloud Project:** Create a project in the Google Cloud Console.
268274
2. **Enable Google Drive API:** Search for the **Google Drive API** in your project's API Library and enable it. *Note: If this API is not enabled, synchronization will fail with a `Drive search failed: Forbidden` error.*
269275
3. **OAuth Consent Screen:** Configure the consent screen and add the `https://www.googleapis.com/auth/drive.appdata` scope. Since the application will be in testing mode, make sure to add your Gmail address as a **Test User**.
270276
4. **OAuth Client ID:** Create credentials of type **OAuth Client ID** and select **Desktop Application**. Copy the generated Client ID and Client Secret.
271277

272-
#### 2. Linking Your Account
278+
#### 4. Linking Your Account
273279
In DocForge's **Cloud Sync** settings section, paste your Client ID and Client Secret, then click **Connect Account**. A temporary server will bind to `http://127.0.0.1:52080` to listen for the OAuth response. Complete the consent flow in your default browser, after which DocForge will show your connected Google email.
274280

275-
#### 3. Sandbox Privacy
281+
#### 5. Sandbox Privacy
276282
DocForge utilizes Google Drive's isolated **Application Data folder** (`appDataFolder`). This is a hidden sandbox space that other applications cannot read or access, and DocForge itself cannot access any other files, folders, or documents in your main Google Drive.
277283

278-
#### 4. Automatic vs. Manual Synchronization
284+
#### 6. Automatic vs. Manual Synchronization
279285
- **Sync on Startup & Shutdown:** Automatically checks for database changes, pushing or pulling the SQLite database as soon as you launch or close the app.
280286
- **Manual Sync ("Sync Now"):** Manually run a sync check at any point from the settings screen.
281287
- **Conflict Resolution:** If local and cloud databases have modified concurrently since the last sync, the synchronization pauses and triggers a **Conflict Resolution Modal**. This dialog displays a side-by-side comparison of local and remote database file sizes, modified dates, document counts, and template counts so you can safely choose which database version to keep ("Keep Local" or "Keep Cloud").
282288

289+
283290
---
284291

285292
## 3. Views and Panels

‎docs/VERSION_LOG.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
## Unreleased
22

3-
- _No entries yet._
3+
### ✨ Features
4+
5+
- **Computer-Name Suffix for Cloud Sync Databases**:
6+
- Automatically appends the sanitized local computer hostname to the default Google Drive sync database filename (e.g. `docforge-[computer-name].db`).
7+
- Supports listing and switching target synchronization databases from other machines via the Database settings dropdown.
8+
- **Global Sync Status & Error Alerts**:
9+
- Integrated real-time sync status updates (`syncing`, `conflict`, `error`) into the bottom status bar.
10+
- Added a global, glassmorphic sync error toast notification that appears on any synchronization failure, displaying clear error diagnostics and a one-click button to jump to **Settings**.
11+
412

513
## v0.9.1 - The Google Drive Multi-Database Sync Update
614

‎electron/main.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,24 @@ let syncConfig: SyncConfig = {};
359359
const SYNC_CONFIG_FILE = 'sync-config.json';
360360
const getSyncConfigFilePath = () => path.join(app.getPath('userData'), SYNC_CONFIG_FILE);
361361

362+
function getSanitizedComputerName(): string {
363+
const hostname = os.hostname();
364+
const sanitized = hostname.toLowerCase().replace(/[^a-z0-9_-]/g, '');
365+
return sanitized || 'device';
366+
}
367+
368+
function getDefaultDatabaseName(): string {
369+
const computerName = getSanitizedComputerName();
370+
return `docforge-${computerName}.db`;
371+
}
372+
362373
const loadSyncConfig = async () => {
363374
try {
364375
const raw = await fs.readFile(getSyncConfigFilePath(), 'utf-8');
365376
syncConfig = JSON.parse(raw) as SyncConfig;
377+
if (!syncConfig.syncDatabaseName) {
378+
syncConfig.syncDatabaseName = getDefaultDatabaseName();
379+
}
366380
console.log('[Sync] Local sync-config.json loaded.');
367381
} catch (error) {
368382
syncConfig = {
@@ -371,7 +385,7 @@ const loadSyncConfig = async () => {
371385
clientSecret: '',
372386
syncAutoOnOpenClose: false,
373387
conflictResolution: 'ask',
374-
syncDatabaseName: 'docforge.db',
388+
syncDatabaseName: getDefaultDatabaseName(),
375389
};
376390
console.log('[Sync] Initialized default sync configuration.');
377391
}
@@ -1136,7 +1150,8 @@ ipcMain.handle('sync:get-config', () => {
11361150
lastLocalChecksum: syncConfig.lastLocalChecksum ?? null,
11371151
lastRemoteChecksum: syncConfig.lastRemoteChecksum ?? null,
11381152
lastCompletedAt: syncConfig.lastCompletedAt ?? null,
1139-
syncDatabaseName: syncConfig.syncDatabaseName ?? 'docforge.db',
1153+
syncDatabaseName: syncConfig.syncDatabaseName ?? getDefaultDatabaseName(),
1154+
defaultSyncDatabaseName: getDefaultDatabaseName(),
11401155
};
11411156
});
11421157

‎services/repository.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,8 @@ export const repository = {
16141614
syncLastLocalChecksum: syncConfig.lastLocalChecksum ?? null,
16151615
syncLastRemoteChecksum: syncConfig.lastRemoteChecksum ?? null,
16161616
syncLastCompletedAt: syncConfig.lastCompletedAt ?? null,
1617-
syncDatabaseName: syncConfig.syncDatabaseName ?? 'docforge.db',
1617+
syncDatabaseName: syncConfig.syncDatabaseName ?? syncConfig.defaultSyncDatabaseName,
1618+
defaultSyncDatabaseName: syncConfig.defaultSyncDatabaseName,
16181619
});
16191620
} catch (e) {
16201621
console.error('Failed to load sync settings from main process:', e);

‎types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ export interface Settings {
556556
syncLastRemoteChecksum: string | null;
557557
syncLastCompletedAt: string | null;
558558
syncDatabaseName?: string;
559+
defaultSyncDatabaseName?: string;
559560
}
560561

561562
export type LogLevel = 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';

0 commit comments

Comments
 (0)