Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CodeSnip — Next-Generation Code & Prompt Manager

<p align="center">
<img src="https://img.shields.io/badge/Version-26Q3-00adb5?style=for-the-badge" alt="Version">
<img src="https://img.shields.io/badge/Version-26Q3.1-00adb5?style=for-the-badge" alt="Version">
<img src="https://img.shields.io/badge/Built%20With-Electron-47848F?style=for-the-badge" alt="Electron">
<img src="https://img.shields.io/badge/License-MIT-green?style=for-the-badge" alt="MIT License">
</p>
Expand Down
749 changes: 453 additions & 296 deletions index.html

Large diffs are not rendered by default.

199 changes: 125 additions & 74 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,126 @@
const { app, BrowserWindow, globalShortcut, ipcMain } = require('electron');
const path = require('path');

let mainWindow;

function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
icon: path.join(__dirname, 'icon.ico'),
frame: false, // Custom titlebar için çerçeveyi kaldırdık
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});

// Menüyü güvenli bir şekilde fonksiyon içinde kaldırıyoruz
mainWindow.setMenu(null);
mainWindow.loadFile('index.html');

mainWindow.on('closed', () => {
mainWindow = null;
});
}

// 🎛️ Frontend'den (index.html) gelen Pencere Buton Kontrolleri
ipcMain.on('window-minimize', () => {
if (mainWindow) mainWindow.minimize();
});

ipcMain.on('window-maximize', () => {
if (mainWindow) {
if (mainWindow.isMaximized()) {
mainWindow.unmaximize();
} else {
mainWindow.maximize();
}
}
});

ipcMain.on('window-close', () => {
if (mainWindow) mainWindow.close();
});

// 🎹 Uygulama hazır olduğunda tetiklenen alan
app.whenReady().then(() => {
createWindow();

// Global Kısayol Kaydı (Ctrl + Shift + S)
globalShortcut.register('CommandOrControl+Shift+S', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.show();
mainWindow.focus();

// Frontend sürecine spotlight sinyali gönder
mainWindow.webContents.send('global-spotlight-trigger');
}
});

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});

// Tüm pencereler kapandığında uygulamayı kapat
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});

// Uygulama tamamen kapatılırken kısayolları hafızadan temizle
app.on('will-quit', () => {
globalShortcut.unregisterAll();
const { app, BrowserWindow, globalShortcut, ipcMain, dialog } = require('electron');
const path = require('path');
const fs = require('fs');

let mainWindow;

function createWindow() {
const isMac = process.platform === 'darwin';

mainWindow = new BrowserWindow({
width: 1200,
height: 800,
icon: path.join(__dirname, 'icon.ico'),
frame: false,
titleBarStyle: isMac ? 'hidden' : 'default',
trafficLightPosition: isMac ? { x: 18, y: 18 } : undefined,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});

mainWindow.setMenu(null);
mainWindow.loadFile('index.html');
// mainWindow.webContents.toggleDevTools();

mainWindow.on('closed', () => {
mainWindow = null;
});
}

// Pencere Buton Kontrolleri
ipcMain.on('window-minimize', () => {
if (mainWindow) mainWindow.minimize();
});

ipcMain.on('window-maximize', () => {
if (mainWindow) {
if (mainWindow.isMaximized()) {
mainWindow.unmaximize();
} else {
mainWindow.maximize();
}
}
});

ipcMain.on('window-close', () => {
if (mainWindow) mainWindow.close();
});

// 💾 JSON Dışa Aktarma (Export) Handleri
ipcMain.handle('export-data', async (event, dataString) => {
const { canceled, filePath } = await dialog.showSaveDialog(mainWindow, {
title: 'CodeSnip Verilerini Yedekle',
defaultPath: path.join(app.getPath('downloads'), 'codesnip_backup_26Q3.1.json'),
filters: [
{ name: 'JSON Dosyası', extensions: ['json'] }
]
});

if (canceled || !filePath) {
return { success: false, message: 'Yedekleme iptal edildi.' };
}

try {
fs.writeFileSync(filePath, dataString, 'utf-8');
return { success: true, message: 'Veriler başarıyla yedeklendi!' };
} catch (error) {
return { success: false, message: `Hata oluştu: ${error.message}` };
}
});

// 📂 EKSİK OLAN KISIM EKLENDİ: JSON İçe Aktarma (Import) Handleri
ipcMain.handle('import-data', async () => {
try {
const { canceled, filePaths } = await dialog.showOpenDialog(mainWindow, {
title: 'CodeSnip Yedeği Seçin',
properties: ['openFile'],
filters: [
{ name: 'JSON Dosyaları', extensions: ['json'] },
{ name: 'Tüm Dosyalar', extensions: ['*'] }
]
});

if (canceled || filePaths.length === 0) {
return { success: false, message: 'İçe aktarma iptal edildi.' };
}

const filePath = filePaths[0];
const rawData = fs.readFileSync(filePath, 'utf-8');

// Yüklenen dosyanın geçerli bir JSON olup olmadığını doğrula
JSON.parse(rawData);

return { success: true, data: rawData };
} catch (error) {
return { success: false, message: 'Seçilen dosya geçerli bir JSON yedeği değil veya okunamadı!' };
}
});

// Uygulama Başlatma Alanı
app.whenReady().then(() => {
createWindow();

globalShortcut.register('CommandOrControl+Shift+S', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.show();
mainWindow.focus();

mainWindow.webContents.send('global-spotlight-trigger');
}
});

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});

app.on('will-quit', () => {
globalShortcut.unregisterAll();
});
Loading