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
31 changes: 2 additions & 29 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -271,36 +271,9 @@ <h4 class="lang-txt" data-tr="Görünüm Tasarımı" data-en="Appearance Design"
</div>
</div>

<div class="setting-item">
<div>
<strong class="lang-txt" data-tr="Liquid Glass Efekti" data-en="Liquid Glass Effect">Liquid
Glass Efekti</strong>
<p class="lang-txt" data-tr="Buzlu cam ve saydamlık efektlerini yönetir."
data-en="Controls frosted glass and transparency effects.">Buzlu cam ve saydamlık
efektlerini yönetir.</p>
</div>
<label class="switch">
<input type="checkbox" id="setting-glass" onchange="applySettings()" checked>
<span class="slider"></span>
</label>
</div>


<div class="setting-item">
<div>
<strong class="lang-txt" data-tr="Yazı Tipi Boyutu (Kodlar)" data-en="Font Size (Codes)">Yazı
Tipi Boyutu (Kodlar)</strong>
<p class="lang-txt" data-tr="Kod bloklarının metin boyutunu ayarlar."
data-en="Adjusts text size of code blocks.">Kod bloklarının metin boyutunu ayarlar.</p>
</div>
<select id="setting-font-size" onchange="applySettings()">
<option value="12px" class="lang-txt" data-tr="Küçük (12px)" data-en="Small (12px)">Küçük
(12px)</option>
<option value="14px" class="lang-txt" data-tr="Normal (14px)" data-en="Normal (14px)" selected>
Normal (14px)</option>
<option value="16px" class="lang-txt" data-tr="Büyük (16px)" data-en="Large (16px)">Büyük
(16px)</option>
</select>
</div>

</div>

<div class="settings-section">
Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ipcMain.on('window-close', () => {
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.5.json'),
defaultPath: path.join(app.getPath('downloads'), 'codesnip_backup_26Q3.6.json'),
filters: [
{ name: 'JSON Dosyası', extensions: ['json'] }
]
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codesnip-app",
"version": "26Q3.5",
"version": "26Q3.6",
"main": "main.js",
"license": "MIT",
"scripts": {
Expand All @@ -26,7 +26,10 @@
"category": "public.app-category.developer-tools"
},
"linux": {
"target": ["AppImage", "deb"],
"target": [
"AppImage",
"deb"
],
"category": "Development"
},
"directories": {
Expand All @@ -38,4 +41,4 @@
"ipados": true,
"entry": "index.html"
}
}
}
38 changes: 24 additions & 14 deletions renderer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
function readJsonStorage(key, fallback) {
try {
const rawValue = localStorage.getItem(key);
return rawValue === null ? fallback : JSON.parse(rawValue);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply the fallback to parsed null values

When a user imports a file containing the valid JSON value null, the import handler accepts it and stores it as the snippets value. This returns null rather than [], so renderSnips() throws when it calls .forEach during startup; the previous JSON.parse(...) || [] handling recovered from this input. Apply the fallback to parsed null values as well.

Useful? React with 👍 / 👎.

} catch (error) {
console.warn(`CodeSnip could not read "${key}" from local storage:`, error);
return fallback;
}
}

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

Expand Down Expand Up @@ -138,7 +148,7 @@ document.addEventListener("DOMContentLoaded", () => {
});

function renderSnips() {
const allSnips = JSON.parse(localStorage.getItem('all_snippets_data')) || [];
const allSnips = readJsonStorage('all_snippets_data', []);
const container = document.getElementById('snip-list-container');
if (!container) return;
container.innerHTML = '';
Expand Down Expand Up @@ -213,7 +223,7 @@ function renderSnips() {
}

function renderCategories() {
const categories = JSON.parse(localStorage.getItem('codesnip_categories')) || [];
const categories = readJsonStorage('codesnip_categories', []);
const container = document.getElementById('dynamic-categories');
const selectCategory = document.getElementById('new-category');

Expand Down Expand Up @@ -254,12 +264,12 @@ function renderCategories() {
});

container.appendChild(fragment);
const allSnips = JSON.parse(localStorage.getItem('all_snippets_data')) || [];
const allSnips = readJsonStorage('all_snippets_data', []);
updateBadges(allSnips);
}

function kartiKopruyeDonustur(id) {
const allSnips = JSON.parse(localStorage.getItem('all_snippets_data')) || [];
const allSnips = readJsonStorage('all_snippets_data', []);
const snip = allSnips.find(s => s.id === id);

if (!snip) return;
Expand All @@ -280,15 +290,15 @@ function kartiKopruyeDonustur(id) {
}

function hariciKartEkle(title, code, category) {
let allSnips = JSON.parse(localStorage.getItem('all_snippets_data')) || [];
let allSnips = readJsonStorage('all_snippets_data', []);
const newId = 'snip-' + Date.now();
allSnips.push({ id: newId, title, category, code, isFavorite: false });
localStorage.setItem('all_snippets_data', JSON.stringify(allSnips));
renderSnips();
}

window.toggleFavorite = function (id) {
let allSnips = JSON.parse(localStorage.getItem('all_snippets_data')) || [];
let allSnips = readJsonStorage('all_snippets_data', []);
const snip = allSnips.find(s => s.id === id);
if (snip) {
snip.isFavorite = !snip.isFavorite;
Expand All @@ -300,15 +310,15 @@ window.toggleFavorite = function (id) {
window.deleteSnip = function (id) {
const confirmMsg = currentLang === 'tr' ? 'Bu kod kartını silmek istediğinize emin misiniz?' : 'Are you sure you want to delete this snippet?';
if (confirm(confirmMsg)) {
let allSnips = JSON.parse(localStorage.getItem('all_snippets_data')) || [];
let allSnips = readJsonStorage('all_snippets_data', []);
allSnips = allSnips.filter(snip => snip.id !== id);
localStorage.setItem('all_snippets_data', JSON.stringify(allSnips));
renderSnips();
}
};

window.editCard = function (cardId) {
const allSnips = JSON.parse(localStorage.getItem('all_snippets_data')) || [];
const allSnips = readJsonStorage('all_snippets_data', []);
const snip = allSnips.find(s => s.id === cardId);

if (snip) {
Expand All @@ -333,7 +343,7 @@ window.saveSnipAction = function () {

if (!title || !code) return;

let allSnips = JSON.parse(localStorage.getItem('all_snippets_data')) || [];
let allSnips = readJsonStorage('all_snippets_data', []);

if (editId) {
allSnips = allSnips.map(snip => snip.id === editId ? { ...snip, title, category, code } : snip);
Expand Down Expand Up @@ -470,7 +480,7 @@ function applySettings() {

function loadSettings() {
const defaultBackgroundImage = 'abstract_beta.png';
let saved = JSON.parse(localStorage.getItem('app_settings'));
let saved = readJsonStorage('app_settings', null);

if (!saved) {
saved = {
Expand Down Expand Up @@ -546,7 +556,7 @@ window.filterCategory = function (category, element) {
if (category === 'all' || category === 'favorites') {
pageTitle.innerText = titleMap[category][currentLang];
} else {
const categories = JSON.parse(localStorage.getItem('codesnip_categories')) || [];
const categories = readJsonStorage('codesnip_categories', []);
const cat = categories.find(c => c.id === category);
if (cat) pageTitle.innerText = cat.name[currentLang] || cat.name.tr;
}
Expand Down Expand Up @@ -575,7 +585,7 @@ function updateBadges(allSnips) {
if (badgeAll) badgeAll.innerText = allSnips.length;
if (badgeFav) badgeFav.innerText = allSnips.filter(s => s.isFavorite).length;

const categories = JSON.parse(localStorage.getItem('codesnip_categories')) || [];
const categories = readJsonStorage('codesnip_categories', []);
categories.forEach(cat => {
const count = allSnips.filter(s => s.category === cat.id).length;
const bEl = document.getElementById(`badge-${cat.id}`);
Expand Down Expand Up @@ -852,7 +862,7 @@ function addCategoryProcess() {

if (!nameTr) return;

let categories = JSON.parse(localStorage.getItem('codesnip_categories')) || [];
let categories = readJsonStorage('codesnip_categories', []);

categories.push({
id: nameTr.toLowerCase().replace(/\s+/g, '-'),
Expand All @@ -870,7 +880,7 @@ function deleteCategory(event, categoryId) {

if (!confirm("Bu kategoriyi silmek istediğine emin misin?")) return;

let categories = JSON.parse(localStorage.getItem('codesnip_categories')) || [];
let categories = readJsonStorage('codesnip_categories', []);
const updatedCategories = categories.filter(c => c.id !== categoryId);

localStorage.setItem('codesnip_categories', JSON.stringify(updatedCategories));
Expand Down
Loading