Skip to content

Commit

Permalink
bookmarks fixed + imessage datastructure + improving scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil-lalani committed Nov 14, 2024
1 parent 6d996bb commit d4893c8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
16 changes: 12 additions & 4 deletions assets/imessage_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

folder_path = sys.argv[1]
company = sys.argv[2]
name = sys.argv[3]
platform_name = sys.argv[3]
password = sys.argv[4]
app_data_path = sys.argv[5] # New argument for the app's data path
id = sys.argv[6]
Expand All @@ -37,7 +37,7 @@ def apple_time_to_iso(apple_timestamp):
backup = EncryptedBackup(backup_directory=folder_path, passphrase=password)
print('Backup decrypted successfully')
# Define the output directory using the provided app data path
output_dir = os.path.join(app_data_path, 'surfer_data', company, name, id)
output_dir = os.path.join(app_data_path, 'surfer_data', company, platform_name, id)

# Ensure the directory exists
os.makedirs(output_dir, exist_ok=True)
Expand Down Expand Up @@ -142,16 +142,24 @@ def apple_time_to_iso(apple_timestamp):
imessage_conn.close()
contacts_conn.close()

imessages = {
"company": company,
"name": platform_name,
"runID": id,
"timestamp": int(id.split('-')[-1]),
"content": message_list
}

# Save to JSON file
imessage_json_path = os.path.join(output_dir, 'imessages.json')
with open(imessage_json_path, 'w') as f:
json.dump(message_list, f, indent=2)
json.dump(imessages, f, indent=2)

print(output_dir)

sys.exit(0)
except Exception as e:
if "Invalid password" in str(e):
if "incorrect passphrase" in str(e):
print('INVALID_PASSWORD')
else:
print(f"ERROR: {str(e)}")
Expand Down
14 changes: 14 additions & 0 deletions src/main/helpers/platforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ import fs from 'fs';
import path from 'path';
import { mboxParser } from 'mbox-parser';
import yauzl from 'yauzl';
import { app } from 'electron'

export function checkConnectedPlatforms(platforms: any[]) {
const userDataPath = app.getPath('userData');
const connectedPlatforms : any = {};

for (const platform of platforms) {
const { company, name } = platform;
const platformPath = path.join(userDataPath, 'surfer_data', company, name);
connectedPlatforms[platform.id] = fs.existsSync(platformPath);
}

return connectedPlatforms;
}

export async function convertMboxToJson(
mboxFilePath: string,
Expand Down
37 changes: 18 additions & 19 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { autoUpdater } from 'electron-updater';
import log from 'electron-log';
import { resolveHtmlPath } from './utils/util';
import fs from 'fs';
import { convertMboxToJson, findMboxFile, extractZip, getTotalFolderSize } from './helpers/platforms';
import { convertMboxToJson, findMboxFile, extractZip, getTotalFolderSize, checkConnectedPlatforms } from './helpers/platforms';
import { getImessageData } from './utils/imessage';
const { download } = require('electron-dl');
import express from 'express';
Expand Down Expand Up @@ -297,16 +297,7 @@ ipcMain.on('get-linkedin-credentials', async (event, company, name) => {
});

ipcMain.handle('check-connected-platforms', async (event, platforms) => {
const userDataPath = app.getPath('userData');
const connectedPlatforms = {};

for (const platform of platforms) {
const { company, name } = platform;
const platformPath = path.join(userDataPath, 'surfer_data', company, name);
connectedPlatforms[platform.id] = fs.existsSync(platformPath);
}

return connectedPlatforms;
return checkConnectedPlatforms(platforms);
});

const getPlatforms = async () => {
Expand Down Expand Up @@ -438,7 +429,7 @@ class AppUpdater {
}
}

let mainWindow: BrowserWindow | null = null;
export let mainWindow: BrowserWindow | null = null;

const isDebug =
process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true';
Expand Down Expand Up @@ -767,20 +758,28 @@ const initializeExports = async () => {

try {
const platforms = await getPlatforms();

const connectedPlatformsMap = await checkConnectedPlatforms(platforms);

// Get current runs
mainWindow.webContents.send('get-runs');
const runsResponse: any = await new Promise((resolve) => {
ipcMain.once('get-runs-response', (event, runs) => resolve(runs));
});

for (const platform of platforms) {
if (platform.exportFrequency) {
console.log(`Checking exports for ${platform.name}`);
await runInitialExports(platform, runsResponse);
scheduleNextExport(platform, runsResponse);
// Filter platforms that are both connected and have exportFrequency set
const platformsToSchedule = platforms.filter(platform =>
connectedPlatformsMap[platform.id] === true &&
platform.exportFrequency
);

}
console.log('Scheduling exports for connected platforms:',
platformsToSchedule.map(p => `${p.name} (${p.id})`)
);

for (const platform of platformsToSchedule) {
console.log(`Initializing exports for ${platform.name} (${platform.id})`);
await runInitialExports(platform, runsResponse);
scheduleNextExport(platform, runsResponse);
}
} catch (error) {
console.error('Failed to initialize export scheduling:', error);
Expand Down
1 change: 1 addition & 0 deletions src/main/preloadFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const features = {
longform_notetweets_rich_text_read_enabled: true,
longform_notetweets_inline_media_enabled: true,
responsive_web_enhance_cards_enabled: false,
responsive_web_live_screen_enabled: false,
};


Expand Down

0 comments on commit d4893c8

Please sign in to comment.