Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Clean all data on desktop start for the new version

Hakan Shehu35e77ea906f2
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 76bf1dc3..d2af72aa 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -32,6 +32,7 @@
"@types/mime-types": "^2.1.4",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
+ "@types/semver": "^7.5.8",
"@types/unzipper": "^0.10.10",
"autoprefixer": "^10.4.20",
"electron": "^34.0.1",
@@ -104,6 +105,7 @@
"react-hook-form": "^7.53.2",
"react-intersection-observer": "^9.15.1",
"react-router-dom": "^7.1.3",
+ "semver": "^7.7.1",
"tailwind-merge": "^2.5.5",
"tailwindcss-animate": "^1.0.7",
"tiptap-extension-auto-joiner": "^0.1.3",
diff --git a/apps/desktop/src/main/lib/utils.ts b/apps/desktop/src/main/lib/utils.ts
index fc6ad228..2303ff17 100644
--- a/apps/desktop/src/main/lib/utils.ts
+++ b/apps/desktop/src/main/lib/utils.ts
@@ -22,8 +22,10 @@ export const appPath = app.getPath('userData');
export const appDatabasePath = path.join(appPath, 'app.db');
+export const accountsDirectoryPath = path.join(appPath, 'accounts');
+
export const getAccountDirectoryPath = (accountId: string): string => {
- return path.join(appPath, 'accounts', accountId);
+ return path.join(accountsDirectoryPath, accountId);
};
export const getWorkspaceDirectoryPath = (
diff --git a/apps/desktop/src/main/services/app-service.ts b/apps/desktop/src/main/services/app-service.ts
index fc1e3378..c2bd5302 100644
--- a/apps/desktop/src/main/services/app-service.ts
+++ b/apps/desktop/src/main/services/app-service.ts
@@ -3,11 +3,13 @@ import SQLite from 'better-sqlite3';
import { ApiErrorCode, createDebugger } from '@colanode/core';
import ms from 'ms';
import axios from 'axios';
+import semver from 'semver';
+import fs from 'fs';
import { app } from 'electron';
import { AppDatabaseSchema, appDatabaseMigrations } from '@/main/databases/app';
-import { appDatabasePath } from '@/main/lib/utils';
+import { accountsDirectoryPath, appDatabasePath } from '@/main/lib/utils';
import { mapServer, mapAccount } from '@/main/lib/mappers';
import { MetadataService } from '@/main/services/metadata-service';
import { AccountService } from '@/main/services/accounts/account-service';
@@ -76,6 +78,11 @@ export class AppService {
await migrator.migrateToLatest();
+ const version = await this.metadata.get('version');
+ if (version && semver.lt(version.value, '0.1.0')) {
+ await this.deleteAllData();
+ }
+
await this.metadata.set('version', this.version);
await this.metadata.set('platform', process.platform as AppPlatform);
}
@@ -265,6 +272,21 @@ export class AppService {
}
}
}
+
+ private async deleteAllData(): Promise<void> {
+ await this.database.deleteFrom('accounts').execute();
+ await this.database.deleteFrom('metadata').execute();
+ await this.database.deleteFrom('deleted_tokens').execute();
+
+ if (fs.existsSync(accountsDirectoryPath)) {
+ fs.rmSync(accountsDirectoryPath, {
+ recursive: true,
+ force: true,
+ maxRetries: 3,
+ retryDelay: 1000,
+ });
+ }
+ }
}
export const appService = new AppService();
diff --git a/package-lock.json b/package-lock.json
index 632c7698..05c06d8b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -102,6 +102,7 @@
"react-hook-form": "^7.53.2",
"react-intersection-observer": "^9.15.1",
"react-router-dom": "^7.1.3",
+ "semver": "^7.7.1",
"tailwind-merge": "^2.5.5",
"tailwindcss-animate": "^1.0.7",
"tiptap-extension-auto-joiner": "^0.1.3",
@@ -128,6 +129,7 @@
"@types/mime-types": "^2.1.4",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
+ "@types/semver": "^7.5.8",
"@types/unzipper": "^0.10.10",
"autoprefixer": "^10.4.20",
"electron": "^34.0.1",
@@ -7205,6 +7207,13 @@
"integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==",
"license": "MIT"
},
+ "node_modules/@types/semver": {
+ "version": "7.5.8",
+ "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz",
+ "integrity": "sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/@types/send": {
"version": "0.17.4",
"resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.4.tgz",
@@ -17641,9 +17650,9 @@
}
},
"node_modules/semver": {
- "version": "7.6.3",
- "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz",
- "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==",
+ "version": "7.7.1",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz",
+ "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==",
"license": "ISC",
"bin": {
"semver": "bin/semver.js"