Add FileBow Windows app, Store identity and optional Ko-fi link

This commit is contained in:
nordik committed 2026-10-27 01:13:56 +01:00
commit 65cebb31ca
139 files changed
+375057

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
const {test}=require('node:test');
const assert=require('node:assert/strict');
const fs=require('node:fs/promises'),os=require('node:os'),path=require('node:path');
const {Engine}=require('../src/main/engine.cjs');
test('cancelling a worker stops its process tree and cleans unpublished output',async()=>{
const root=path.resolve(__dirname,'..'),folder=await fs.mkdtemp(path.join(os.tmpdir(),'filebow-cancel-test-'));
try{
const image=path.join(folder,'image.png');await fs.copyFile(path.join(root,'assets/icon.png'),image);
const engine=new Engine(root,true),controller=new AbortController();
const timer=setTimeout(()=>controller.abort(),450);
try{await assert.rejects(engine.run({op:'convert',files:Array(500).fill(image),target:'avif'},()=>{},controller.signal),/Cancelled/);}
finally{clearTimeout(timer);engine.stop();}
assert.equal(engine.children.size,0);
assert.ok(!(await fs.readdir(folder)).some(name=>name.startsWith('.filebow-')));
assert.ok((await fs.stat(image)).size>0);
}finally{await fs.rm(folder,{recursive:true,force:true});}
});
+17
View File
@@ -0,0 +1,17 @@
const { test } = require('node:test');
const assert = require('node:assert/strict');
const { wheelContent,categoryOf } = require('../src/main/wheel-options.cjs');
test('all advertised file categories expose valid bounded radial actions',()=>{
for(const file of ['photo.HEIC','video.mkv','audio.flac','paper.pdf','notes.txt','table.xlsx','unknown.bin']) {
for(const mode of ['quick','tools']) {
const options=wheelContent([file],mode).options;
assert.ok(options.length>0&&options.length<=7);
assert.equal(new Set(options.map(x=>x.id)).size,options.length);
for(const option of options)assert.ok(option.op&&option.label);
}
}
assert.equal(categoryOf('photo.HEIC'),'image');assert.equal(categoryOf('old.doc'),'other');
});
test('PDF password removal stays available without guessing encryption from bytes',()=>{
assert.ok(wheelContent(['encrypted.pdf'],'tools').options.some(x=>x.id==='password-remove'));
});
+101
View File
@@ -0,0 +1,101 @@
import contextlib
import hashlib
import importlib.util
import io
import json
import os
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
from PIL import Image
from pypdf import PdfReader
ROOT=Path(__file__).resolve().parents[1]
os.environ['FILEBOW_FFMPEG']=str(ROOT/'vendor/ffmpeg/ffmpeg.exe')
spec=importlib.util.spec_from_file_location('worker',ROOT/'engine/filebow_engine.py')
worker=importlib.util.module_from_spec(spec);spec.loader.exec_module(worker)
class ConversionTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.folder=tempfile.TemporaryDirectory(prefix='filebow-test-');cls.root=Path(cls.folder.name)
cls.image=cls.root/'Bild ä.png';image=Image.new('RGBA',(120,90),(230,80,60,160));image.save(cls.image)
cls.text=cls.root/'Notizen.txt';cls.text.write_text('Hallo FileBow\nGrüße aus Köln\nZweite Zeile',encoding='utf-8')
cls.video=cls.root/'Video.mp4'
worker.media(['-f','lavfi','-i','color=c=blue:s=128x96:d=1','-f','lavfi','-i','sine=frequency=440:duration=1',*worker.video_args('mp4'),'-shortest',cls.video])
cls.originals={p:hashlib.sha256(p.read_bytes()).hexdigest() for p in [cls.image,cls.text,cls.video]}
@classmethod
def tearDownClass(cls):
for p,checksum in cls.originals.items(): assert hashlib.sha256(p.read_bytes()).hexdigest()==checksum
cls.folder.cleanup()
def run_job(self,op,files,target=None,**options):
job={'op':op,'files':[str(x) for x in files],'target':target,'options':options}
if os.environ.get('FILEBOW_PACKAGED_ENGINE'):
request=self.root/'job.json';request.write_text(json.dumps(job),encoding='utf-8')
process=subprocess.run([os.environ['FILEBOW_PACKAGED_ENGINE'],'--job',str(request)],capture_output=True,text=True,encoding='utf-8')
messages=[json.loads(line) for line in process.stdout.splitlines()]
self.assertEqual(process.returncode,0,process.stderr+process.stdout)
results=next(x['results'] for x in messages if x['type']=='result')
else:
with contextlib.redirect_stdout(io.StringIO()): results=worker.run_job(job)
for result in results:self.assertTrue(result['ok'],result)
return results
def output(self,*args,**kwargs): return Path(self.run_job(*args,**kwargs)[0]['output'])
def test_images(self):
for fmt in ['jpg','png','webp','avif','tiff','bmp','gif','ico','heic','pdf']:
with self.subTest(fmt=fmt):
out=self.output('convert',[self.image],fmt)
self.assertGreater(out.stat().st_size,0)
if fmt!='pdf':
with Image.open(out) as image:self.assertGreater(image.width,0)
def test_edit(self):
out=self.output('edit',[self.image],crop={'x':10,'y':5,'width':60,'height':40},width=30,height=20,rotate=90,flipH=True)
with Image.open(out) as image:self.assertEqual(image.size,(20,30))
def test_unicode_pdf_and_text(self):
out=self.output('convert',[self.text],'pdf');text=PdfReader(out).pages[0].extract_text();self.assertIn('Grüße',text)
back=self.output('convert',[out],'txt');self.assertIn('Köln',back.read_text(encoding='utf-8'))
docx=self.output('convert',[self.text],'docx');back=self.output('convert',[docx],'md');self.assertIn('Hallo FileBow',back.read_text(encoding='utf-8'))
def test_password(self):
pdf=self.output('convert',[self.text],'pdf')
encrypted=self.output('pdf-password',[pdf],password='test-pass',mode='add');self.assertTrue(PdfReader(encrypted).is_encrypted)
unlocked=self.output('pdf-password',[encrypted],password='test-pass',mode='remove');self.assertFalse(PdfReader(unlocked).is_encrypted)
def test_combine(self):
pdf=self.output('convert',[self.text],'pdf');merged=self.output('combine',[pdf,pdf],'pdf');self.assertEqual(len(PdfReader(merged).pages),2)
images=self.output('image-to-pdf',[self.image,self.image]);self.assertEqual(len(PdfReader(images).pages),2)
text=self.output('combine',[self.text,self.text],'txt');self.assertEqual(text.read_text(encoding='utf-8').count('Hallo'),2)
def test_compress_metadata(self):
result=self.run_job('compress',[self.image],quality=65,maxSizeMB=.05)[0];self.assertTrue(result['targetMet'])
pdf=self.output('convert',[self.text],'pdf');self.output('compress',[pdf]);out=self.output('strip-metadata',[pdf]);self.assertFalse(PdfReader(out).metadata)
self.output('strip-metadata',[self.image]);self.output('strip-metadata',[self.video])
def test_media(self):
for fmt in ['mp4','webm','gif']:
with self.subTest(fmt=fmt):self.output('convert',[self.video],fmt)
frame=self.output('frame',[self.video],time=.2)
with Image.open(frame) as image:self.assertEqual(image.size,(128,96))
audio=self.output('extract-audio',[self.video],'mp3')
for fmt in ['wav','m4a','flac','ogg']:self.output('convert',[audio],fmt)
self.output('compress',[self.video],maxSizeMB=.1)
self.output('compress',[audio],maxSizeMB=.03)
resized=self.output('edit',[self.video],width=64,height=48);self.assertEqual(worker.probe(resized)['width'],64)
def test_office(self):
from openpyxl import Workbook
xlsx=self.root/'Tabelle.xlsx';book=Workbook();book.active.append(['FileBow',42]);book.save(xlsx)
self.assertIn('42',self.output('convert',[xlsx],'txt').read_text())
from pptx import Presentation
pptx=self.root/'Folien.pptx';slides=Presentation();slide=slides.slides.add_slide(slides.slide_layouts[0]);slide.shapes.title.text='FileBow Präsentation';slides.save(pptx)
self.assertIn('FileBow',self.output('convert',[pptx],'md').read_text())
def test_collision_zip_and_preview(self):
first=self.output('convert',[self.text],'txt',outputName='Gleich');second=self.output('convert',[self.text],'txt',outputName='Gleich');self.assertNotEqual(first,second)
import zipfile
archive=self.output('zip',[self.text,self.image]);self.assertEqual(len(zipfile.ZipFile(archive).namelist()),2)
preview=self.run_job('preview',[self.image])[0];self.assertTrue(preview['dataUrl'].startswith('data:image/png;base64,'))
def test_reject_traversal_and_invalid_batch_member(self):
with contextlib.redirect_stdout(io.StringIO()):
result=worker.run_job({'op':'convert','files':[str(self.image)],'target':'jpg','options':{'outputName':'../escape'}})
self.assertFalse(result[0]['ok'])
invalid=self.root/'broken.png';invalid.write_bytes(b'not a picture')
with contextlib.redirect_stdout(io.StringIO()):result=worker.run_job({'op':'convert','files':[str(invalid),str(self.image)],'target':'jpg'})
self.assertFalse(result[0]['ok']);self.assertTrue(result[1]['ok'])
if __name__=='__main__':unittest.main(verbosity=2)
+4
View File
@@ -0,0 +1,4 @@
const {WindowsBridge}=require('../src/main/windows.cjs');
const fs=require('node:fs'),path=require('node:path');
const root=path.resolve(__dirname,'..'),log=path.join(root,'test-results/native-drag.json');
(async()=>{const bridge=new WindowsBridge(root);const events=[];await bridge.startFileDragMonitor(event=>{events.push(event);fs.writeFileSync(log,JSON.stringify(events,null,2));});console.log('Monitor ready');setTimeout(()=>bridge.close(),60000);})().catch(error=>{console.error(error);process.exitCode=1;});
+46
View File
@@ -0,0 +1,46 @@
const { _electron: electron } = require('playwright');
const fs=require('node:fs/promises'),path=require('node:path'),assert=require('node:assert/strict');
const root=path.resolve(__dirname,'..'),out=path.join(root,'test-results');
(async()=>{
await fs.mkdir(out,{recursive:true});
const profile=await fs.mkdtemp(path.join(out,'profile-'));
const app=await electron.launch({executablePath:process.env.FILEBOW_EXECUTABLE||require('electron'),args:process.env.FILEBOW_EXECUTABLE?[]:[root],env:{...process.env,FILEBOW_TEST:'1',FILEBOW_USER_DATA:profile},timeout:30000});
const errors=[];app.on('window',window=>window.on('pageerror',error=>errors.push(error.message)));
app.process().stderr.on('data',data=>{const text=data.toString();if(/Error|Exception/.test(text))process.stderr.write(text);});
try{
const page=await app.firstWindow();await page.waitForSelector('#pick');
await page.screenshot({path:path.join(out,'01-home.png')});
const state=await page.evaluate(()=>window.orbit.state());assert.equal(state.name,'FileBow');assert.ok(state.native.available,state.native.error);
const textFile=path.join(out,'Beispiel.txt');await fs.writeFile(textFile,'FileBow\nGrüße aus Köln.\nLokale Dateikonvertierung.');
await page.evaluate(file=>window.orbit.selectFiles([file]),textFile);
await page.locator('[data-action="convert-pdf"]').click();
await page.waitForFunction(()=>document.querySelector('#recent-list').textContent.includes('Ergebnisdatei(en)'),{timeout:30000});
let updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success',JSON.stringify(updated.history[0]));
await fs.access(updated.history[0].outputs[0]);
const pdf=updated.history[0].outputs[0];await page.evaluate(file=>window.orbit.selectFiles([file]),pdf);
await page.locator('#tab-tools').click();
const passwordPromise=app.waitForEvent('window');await page.locator('[data-action="password-add"]').click();const password=await passwordPromise;
await password.locator('#password').fill('FileBow-Test');await password.locator('#confirm').fill('FileBow-Test');await password.locator('#save').click();
await page.waitForFunction(()=>!document.querySelector('#job:not([hidden])'));updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success');
await page.evaluate(file=>window.orbit.selectFiles([file]),updated.history[0].outputs[0]);
const unlockPromise=app.waitForEvent('window');await page.locator('[data-action="password-remove"]').click();const unlock=await unlockPromise;await unlock.locator('#password').fill('FileBow-Test');await unlock.locator('#save').click();
await page.waitForFunction(()=>!document.querySelector('#job:not([hidden])'));updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success');
await page.evaluate(files=>window.orbit.selectFiles(files),[pdf,updated.history[0].outputs[0]]);
const combinePromise=app.waitForEvent('window');await page.locator('[data-action="combine"]').click();const combine=await combinePromise;await combine.locator('#save').click();
await page.waitForFunction(()=>!document.querySelector('#job:not([hidden])'));updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success');
const imageFile=path.join(out,'Beispielbild.png');await fs.copyFile(path.join(root,'assets/icon.png'),imageFile);await page.evaluate(file=>window.orbit.selectFiles([file]),imageFile);
await page.locator('#tab-tools').click();
const dialogPromise=app.waitForEvent('window');await page.locator('[data-action="edit-resize"]').click();const edit=await dialogPromise;
await edit.waitForSelector('#width',{timeout:30000});await edit.locator('#width').fill('96');await edit.screenshot({path:path.join(out,'02-resize.png')});
await edit.locator('#save').click();await page.waitForFunction(()=>!document.querySelector('#job:not([hidden])'));
updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success');
const compressPromise=app.waitForEvent('window');await page.locator('[data-action="compress"]').click();const compress=await compressPromise;await compress.locator('#quality').fill('65');await compress.locator('#save').click();
await page.waitForFunction(()=>!document.querySelector('#job:not([hidden])'));updated=await page.evaluate(()=>window.orbit.state());assert.equal(updated.history[0].status,'success');
const wheelPromise=app.waitForEvent('window');await page.locator('#wheel-open').click();const wheel=await wheelPromise;
await wheel.waitForSelector('.action');await wheel.screenshot({path:path.join(out,'03-wheel.png')});await wheel.keyboard.press('Escape');
await page.locator('[data-page="settings"]').click();await page.locator('#theme').selectOption('light');await page.waitForFunction(()=>document.documentElement.dataset.theme==='light');await page.screenshot({path:path.join(out,'04-settings-light.png')});
await page.locator('#theme').selectOption('dark');await page.locator('[data-page="history"]').click();await page.screenshot({path:path.join(out,'05-history.png')});
assert.deepEqual(errors,[]);await fs.writeFile(path.join(out,'ui-result.json'),JSON.stringify({passed:true,native:state.native,history:updated.history.map(x=>({label:x.label,status:x.status})),errors},null,2));
console.log('UI smoke passed: startup, native bridge, conversion, PDF passwords, combining, compression, editor, radial menu, themes, history.');
}finally{await app.close();}
})().catch(error=>{console.error(error);process.exitCode=1;});