ci: deleting comments

This commit is contained in:
Moyasee
2025-10-21 21:08:01 +03:00
parent 9b693f2297
commit 72e6f1e328
7 changed files with 11 additions and 62 deletions

View File

@@ -5,7 +5,6 @@ import { logger } from "../logger";
import { db, gameAchievementsSublevel, levelKeys } from "@main/level";
import { AxiosError } from "axios";
const getModifiedSinceHeader = (
cachedAchievements: GameAchievement | undefined,
userLanguage: string
@@ -32,8 +31,7 @@ export const getGameAchievementData = async (
const cachedAchievements = await gameAchievementsSublevel.get(gameKey);
if(cachedAchievements?.achievements && useCachedData) {
if (cachedAchievements?.achievements && useCachedData) {
return cachedAchievements.achievements;
}

View File

@@ -190,21 +190,17 @@ export const mergeAchievements = async (
);
}
// Capture and upload screenshot AFTER achievements are synced to server
if (
newAchievements.length &&
userPreferences.enableAchievementScreenshots === true
) {
try {
// Import and trigger the upload process
const { uploadAchievementImage } = await import(
"@main/events/achievements/upload-achievement-image"
);
// Upload the screenshot for each new achievement
for (const achievement of newAchievements) {
try {
// Find the achievement data to get the display name
const achievementData = achievementsData.find(
(steamAchievement) => {
return (
@@ -217,7 +213,6 @@ export const mergeAchievements = async (
const achievementDisplayName =
achievementData?.displayName || achievement.name;
// Capture screenshot with game title and achievement name
const screenshotPath =
await ScreenshotService.captureDesktopScreenshot(
game.title,

View File

@@ -5,20 +5,17 @@ import { app } from "electron";
import { logger } from "./logger";
export class ScreenshotService {
private static readonly SCREENSHOT_QUALITY = 60; // Reduced for better compression
private static readonly SCREENSHOT_QUALITY = 80;
private static readonly SCREENSHOT_FORMAT = "jpeg";
private static readonly MAX_WIDTH = 1280; // Maximum width for compression
private static readonly MAX_HEIGHT = 720; // Maximum height for compression
private static readonly MAX_WIDTH = 1280;
private static readonly MAX_HEIGHT = 720;
/**
* Compresses an image by resizing and adjusting quality
*/
private static compressImage(
image: Electron.NativeImage
): Electron.NativeImage {
const size = image.getSize();
// Calculate new dimensions while maintaining aspect ratio
let newWidth = size.width;
let newHeight = size.height;
@@ -34,7 +31,6 @@ export class ScreenshotService {
}
}
// Resize the image if dimensions changed
if (newWidth !== size.width || newHeight !== size.height) {
return image.resize({ width: newWidth, height: newHeight });
}
@@ -47,7 +43,6 @@ export class ScreenshotService {
achievementName?: string
): Promise<string> {
try {
// Get all available desktop sources
const sources = await desktopCapturer.getSources({
types: ["screen"],
thumbnailSize: { width: 1920, height: 1080 },
@@ -57,18 +52,14 @@ export class ScreenshotService {
throw new Error("No desktop sources available for screenshot");
}
// Use the primary screen (first source)
const primaryScreen = sources[0];
// Convert the thumbnail to a higher quality image
const originalImage = nativeImage.createFromDataURL(
primaryScreen.thumbnail.toDataURL()
);
// Compress the image to reduce file size
const compressedImage = this.compressImage(originalImage);
// Create screenshots directory structure
const userDataPath = app.getPath("userData");
const screenshotsDir = path.join(userDataPath, "screenshots");
@@ -76,31 +67,26 @@ export class ScreenshotService {
let filename: string;
if (gameTitle && achievementName) {
// Create game-specific directory
const sanitizedGameTitle = gameTitle.replace(/[<>:"/\\|?*]/g, "_");
const gameDir = path.join(screenshotsDir, sanitizedGameTitle);
finalDir = gameDir;
// Use achievement name as filename (sanitized)
const sanitizedAchievementName = achievementName.replace(
/[<>:"/\\|?*]/g,
"_"
);
filename = `${sanitizedAchievementName}.${this.SCREENSHOT_FORMAT}`;
} else {
// Fallback to timestamp-based naming
const timestamp = Date.now();
filename = `achievement_screenshot_${timestamp}.${this.SCREENSHOT_FORMAT}`;
}
// Ensure directory exists
if (!fs.existsSync(finalDir)) {
fs.mkdirSync(finalDir, { recursive: true });
}
const screenshotPath = path.join(finalDir, filename);
// Save the compressed screenshot as JPEG with specified quality
const jpegBuffer = compressedImage.toJPEG(this.SCREENSHOT_QUALITY);
fs.writeFileSync(screenshotPath, jpegBuffer);
@@ -121,7 +107,6 @@ export class ScreenshotService {
return;
}
// Get all files recursively from screenshots directory and subdirectories
const getAllFiles = (
dir: string
): Array<{ name: string; path: string; mtime: Date }> => {
@@ -133,7 +118,6 @@ export class ScreenshotService {
const stat = fs.statSync(itemPath);
if (stat.isDirectory()) {
// Recursively get files from subdirectories
files.push(...getAllFiles(itemPath));
} else if (item.endsWith(`.${this.SCREENSHOT_FORMAT}`)) {
files.push({
@@ -151,7 +135,6 @@ export class ScreenshotService {
(a, b) => b.mtime.getTime() - a.mtime.getTime()
);
// Keep only the 50 most recent screenshots (increased from 10 to accommodate multiple games)
const filesToDelete = allFiles.slice(50);
for (const file of filesToDelete) {
@@ -163,9 +146,8 @@ export class ScreenshotService {
}
}
// Clean up empty directories
const cleanupEmptyDirs = (dir: string) => {
if (dir === screenshotsDir) return; // Don't delete the main screenshots directory
if (dir === screenshotsDir) return;
try {
const items = fs.readdirSync(dir);
@@ -174,11 +156,9 @@ export class ScreenshotService {
logger.log(`Cleaned up empty directory: ${dir}`);
}
} catch (error) {
// Directory might not be empty or might not exist, ignore
}
};
// Check for empty game directories and clean them up
const gameDirectories = fs
.readdirSync(screenshotsDir)
.map((item) => path.join(screenshotsDir, item))