Skip to content
Merged
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
6 changes: 4 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ function createWindow() {
titleBarStyle: isMac ? 'hidden' : 'default',
trafficLightPosition: isMac ? { x: 18, y: 18 } : undefined,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: true,
sandbox: true
}
});

Expand Down
19 changes: 19 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('codeSnipAPI', {
minimize: () => ipcRenderer.send('window-minimize'),
maximize: () => ipcRenderer.send('window-maximize'),
close: () => ipcRenderer.send('window-close'),

onGlobalSpotlight: (callback) => {
if (typeof callback !== 'function') return () => {};

const listener = () => callback();
ipcRenderer.on('global-spotlight-trigger', listener);

return () => ipcRenderer.removeListener('global-spotlight-trigger', listener);
},

exportData: (dataString) => ipcRenderer.invoke('export-data', dataString),
importData: () => ipcRenderer.invoke('import-data')
});
15 changes: 6 additions & 9 deletions renderer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { ipcRenderer } = require('electron');

let currentCategory = 'all';
let currentLang = 'tr';

Expand Down Expand Up @@ -102,16 +100,15 @@ document.addEventListener("DOMContentLoaded", () => {
const maxBtn = document.getElementById('max-btn');
const closeBtn = document.getElementById('close-btn');

if (minBtn) minBtn.addEventListener('click', () => ipcRenderer.send('window-minimize'));
if (maxBtn) maxBtn.addEventListener('click', () => ipcRenderer.send('window-maximize'));
if (closeBtn) closeBtn.addEventListener('click', () => ipcRenderer.send('window-close'));
if (minBtn) minBtn.addEventListener('click', () => window.codeSnipAPI.minimize());
if (maxBtn) maxBtn.addEventListener('click', () => window.codeSnipAPI.maximize());
if (closeBtn) closeBtn.addEventListener('click', () => window.codeSnipAPI.close());

const allCodesBtn = document.querySelector('.sidebar-menu li:first-child');
if (allCodesBtn) allCodesBtn.classList.add('active');

// ⚡ IPC Dinleyici Bellek Temizliği (Global Spotlight)
ipcRenderer.removeAllListeners('global-spotlight-trigger');
ipcRenderer.on('global-spotlight-trigger', () => {
window.codeSnipAPI.onGlobalSpotlight(() => {
const spotlightOverlay = document.getElementById('spotlight-overlay');
const spotlightInput = document.getElementById('spotlight-input');
if (spotlightOverlay && spotlightInput) {
Expand Down Expand Up @@ -822,7 +819,7 @@ window.exportCodeSnipData = async function () {
alert(currentLang === 'tr' ? 'Yedeklenecek herhangi bir kod veya prompt bulunamadı!' : 'No snippets found to backup!');
return;
}
const result = await ipcRenderer.invoke('export-data', localData);
const result = await window.codeSnipAPI.exportData(localData);
if (result && result.success) alert(result.message);
} catch (error) {
console.error("Export hatası:", error);
Expand All @@ -835,7 +832,7 @@ window.importCodeSnipData = async function () {
if (!onay) return;

try {
const result = await ipcRenderer.invoke('import-data');
const result = await window.codeSnipAPI.importData();
if (result && result.success) {
localStorage.setItem('all_snippets_data', result.data);
alert(currentLang === 'tr' ? 'Verileriniz başarıyla geri yüklendi! Uygulama yenilenecektir.' : 'Data successfully restored! App will reload.');
Expand Down
Loading