@ponderdev/justfits 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -15
- package/THIRD-PARTY-NOTICES.md +21 -10
- package/agents/skills/justfits/SKILL.md +104 -0
- package/package.json +19 -10
- package/scripts/link-skill.cjs +99 -0
- package/src/binaries.cjs +26 -10
- package/src/cli.cjs +245 -19
- package/src/engine.cjs +181 -26
- package/src/heif.cjs +156 -0
- package/src/kit/desktop.cjs +136 -0
- package/src/kit/family.cjs +29 -0
- package/src/kit/lang.cjs +166 -0
- package/src/kit/scan.cjs +105 -0
- package/src/kit/window.cjs +113 -0
- package/src/main.cjs +131 -20
- package/src/plan.js +136 -26
- package/src/preload.cjs +25 -1
- package/src/renderer/app.js +728 -104
- package/src/renderer/index.html +39 -56
- package/src/renderer/kit/kit.css +780 -0
- package/src/renderer/kit/kit.js +1057 -0
- package/src/renderer/licenses.html +44 -111
- package/src/renderer/strings.js +1562 -0
- package/src/renderer/styles.css +6 -256
- package/src/scan.cjs +80 -0
package/src/kit/lang.cjs
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/* PonderDev kit 1.1.0, built from kit/src. Do not edit: run bin/kit-sync. */
|
|
2
|
+
'use strict';
|
|
3
|
+
const KitScope = {};
|
|
4
|
+
/* kit: words, the one way a Just tool says anything in the window
|
|
5
|
+
* (languages in the kit).
|
|
6
|
+
*
|
|
7
|
+
* The English sentence is its own key: the code reads as it always did, and a
|
|
8
|
+
* sentence nobody has translated yet simply shows in English.
|
|
9
|
+
*
|
|
10
|
+
* const w = KitWords.words(strings, 'de');
|
|
11
|
+
* w.t('Choose a file') // "Datei auswählen"
|
|
12
|
+
* w.t('Unpacked into {folder}', { folder }) // {name} slots are filled in
|
|
13
|
+
* w.tn(count, '{n} file', '{n} files') // the right plural for the language
|
|
14
|
+
* w.num(59400) // "59.400"
|
|
15
|
+
*
|
|
16
|
+
* strings is { de: { 'Choose a file': 'Datei auswählen', '{n} file|{n} files':
|
|
17
|
+
* { one: '{n} Datei', other: '{n} Dateien' }, ... }, ... }, built from each
|
|
18
|
+
* tool's strings/<code>.json and the kit's own by bin/strings.
|
|
19
|
+
*
|
|
20
|
+
* This file runs in the window (inside kit.js) and on the main side (inside
|
|
21
|
+
* src/kit/lang.cjs), so a dialog's title and a button say the same thing.
|
|
22
|
+
*/
|
|
23
|
+
(function (root) {
|
|
24
|
+
// The languages a tool can be in, each named in its own language, in the
|
|
25
|
+
// order the menu lists them (decided 2026-11-24: English plus the five
|
|
26
|
+
// named on 11-21). Portuguese is Brazil's, the larger audience.
|
|
27
|
+
const LANGUAGES = [
|
|
28
|
+
['en', 'English'],
|
|
29
|
+
['es', 'Español'],
|
|
30
|
+
['pt', 'Português'],
|
|
31
|
+
['fr', 'Français'],
|
|
32
|
+
['de', 'Deutsch'],
|
|
33
|
+
['ja', '日本語'],
|
|
34
|
+
];
|
|
35
|
+
const CODES = LANGUAGES.map(([code]) => code);
|
|
36
|
+
|
|
37
|
+
// The first language the system asks for that we have, else English.
|
|
38
|
+
// 'pt-BR' and 'pt-PT' both take 'pt'; 'en-GB' takes 'en'.
|
|
39
|
+
function pick(wanted) {
|
|
40
|
+
const list = Array.isArray(wanted) ? wanted : [wanted];
|
|
41
|
+
for (const w of list) {
|
|
42
|
+
const code = String(w || '').toLowerCase().split(/[-_]/)[0];
|
|
43
|
+
if (CODES.includes(code)) return code;
|
|
44
|
+
}
|
|
45
|
+
return 'en';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const fill = (text, vars) => String(text).replace(/\{(\w+)\}/g, (m, k) => (vars && Object.prototype.hasOwnProperty.call(vars, k) ? String(vars[k]) : m));
|
|
49
|
+
|
|
50
|
+
function words(strings, lang) {
|
|
51
|
+
const code = CODES.includes(lang) ? lang : 'en';
|
|
52
|
+
const table = (strings && strings[code]) || {};
|
|
53
|
+
let rules = null;
|
|
54
|
+
try { rules = new Intl.PluralRules(code); } catch (e) { rules = null; }
|
|
55
|
+
const num = (n, opts) => {
|
|
56
|
+
try { return new Intl.NumberFormat(code, opts).format(n); } catch (e) { return String(n); }
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
lang: code,
|
|
60
|
+
t(source, vars) { // strings: passes on
|
|
61
|
+
const said = table[source];
|
|
62
|
+
return fill(typeof said === 'string' && said ? said : source, vars);
|
|
63
|
+
},
|
|
64
|
+
// one and other are the English forms; the key is both, joined by '|'
|
|
65
|
+
tn(n, one, other, vars = {}) {
|
|
66
|
+
const v = Object.assign({ n: num(n) }, vars);
|
|
67
|
+
const said = table[`${one}|${other}`];
|
|
68
|
+
if (said && typeof said === 'object') {
|
|
69
|
+
const form = said[rules ? rules.select(n) : 'other'] || said.other;
|
|
70
|
+
if (form) return fill(form, v);
|
|
71
|
+
}
|
|
72
|
+
return fill(n === 1 ? one : other, v);
|
|
73
|
+
},
|
|
74
|
+
num,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const api = { LANGUAGES, CODES, pick, words, fill };
|
|
79
|
+
root.KitWords = api;
|
|
80
|
+
})(KitScope);
|
|
81
|
+
const { KitWords } = KitScope;
|
|
82
|
+
/* kit, main side: the window's language on the main side too, so a
|
|
83
|
+
* picker's title, a dialog and a message the main side sends say the same
|
|
84
|
+
* language as the window.
|
|
85
|
+
*
|
|
86
|
+
* const { language } = require('./kit/lang.cjs');
|
|
87
|
+
* const words = language({
|
|
88
|
+
* ipcMain, shell,
|
|
89
|
+
* strings: require('./renderer/strings.js'),
|
|
90
|
+
* issues: 'https://github.com/ponder-dev/just-zip/issues',
|
|
91
|
+
* tool: 'Just Zip',
|
|
92
|
+
* });
|
|
93
|
+
* dialog.showOpenDialog(win, { title: words.t('Choose files') });
|
|
94
|
+
*
|
|
95
|
+
* The window tells it the language as it starts (Kit.languages({ tell })),
|
|
96
|
+
* through 'kit:language'; until then, and for anything it is not told, it is
|
|
97
|
+
* English. 'kit:translation-mistake' opens the tool's issue page with a new
|
|
98
|
+
* issue titled for that language. The preload exposes the two:
|
|
99
|
+
*
|
|
100
|
+
* language: (code) => ipcRenderer.invoke('kit:language', code),
|
|
101
|
+
* translationMistake: (code) => ipcRenderer.invoke('kit:translation-mistake', code),
|
|
102
|
+
* reloadWindow: () => ipcRenderer.invoke('kit:reload'),
|
|
103
|
+
*
|
|
104
|
+
* 'kit:reload' reloads the window that asked. A page cannot reload itself in
|
|
105
|
+
* a tool that refuses every navigation (will-navigate cancelled, as the
|
|
106
|
+
* tools do), so picking a language in the footer would do nothing; a reload
|
|
107
|
+
* started here by main is not a navigation the page made, and is not blocked.
|
|
108
|
+
*
|
|
109
|
+
* The command line stays English (decided 2026-11-24): its output is read by
|
|
110
|
+
* scripts and assistants, and --json carries codes, not sentences.
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
function issueUrl(issues, tool, code, name) {
|
|
114
|
+
const title = `Translation (${name}): `;
|
|
115
|
+
const body = [
|
|
116
|
+
`Tool: ${tool}`,
|
|
117
|
+
`Language: ${name} (${code})`,
|
|
118
|
+
'',
|
|
119
|
+
'What it says:',
|
|
120
|
+
'',
|
|
121
|
+
'What it should say:',
|
|
122
|
+
'',
|
|
123
|
+
'Where in the window:',
|
|
124
|
+
].join('\n');
|
|
125
|
+
return `${issues.replace(/\/+$/, '')}/new?labels=translation&title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function language({ ipcMain, shell, strings = {}, issues, tool = '', later = setTimeout } = {}) {
|
|
129
|
+
let current = KitWords.words(strings, 'en');
|
|
130
|
+
const names = Object.fromEntries(KitWords.LANGUAGES);
|
|
131
|
+
const RELOAD_AFTER_MS = 250;
|
|
132
|
+
if (ipcMain) {
|
|
133
|
+
ipcMain.handle('kit:language', (_event, code) => {
|
|
134
|
+
if (typeof code === 'string' && KitWords.CODES.includes(code)) current = KitWords.words(strings, code);
|
|
135
|
+
return current.lang;
|
|
136
|
+
});
|
|
137
|
+
// What the page kept for after the switch (its keep hook, in localStorage)
|
|
138
|
+
// goes to the browser's storage on a channel of its own, not this one, so a
|
|
139
|
+
// reload done at once could load the new page before that write lands, and
|
|
140
|
+
// the work would come back empty (seen about one switch in three on a busy
|
|
141
|
+
// machine, 2026-11-27). So the storage is flushed and the reload waits a
|
|
142
|
+
// moment; the answer is given at once, so the page never reloads itself.
|
|
143
|
+
ipcMain.handle('kit:reload', (event) => {
|
|
144
|
+
const contents = event && event.sender;
|
|
145
|
+
if (!contents || typeof contents.reload !== 'function' || (contents.isDestroyed && contents.isDestroyed())) return false;
|
|
146
|
+
try { if (contents.session && contents.session.flushStorageData) contents.session.flushStorageData(); } catch (e) { /* the wait still covers it */ }
|
|
147
|
+
later(() => { if (!(contents.isDestroyed && contents.isDestroyed())) contents.reload(); }, RELOAD_AFTER_MS);
|
|
148
|
+
return true;
|
|
149
|
+
});
|
|
150
|
+
ipcMain.handle('kit:translation-mistake', async (_event, code) => {
|
|
151
|
+
// Only ever the tool's own issue page on GitHub, whatever the window sends.
|
|
152
|
+
if (!issues || !/^https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/issues\/?$/.test(issues)) return false;
|
|
153
|
+
const lang = KitWords.CODES.includes(code) ? code : current.lang;
|
|
154
|
+
if (shell) await shell.openExternal(issueUrl(issues, tool, lang, names[lang]));
|
|
155
|
+
return true;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
get lang() { return current.lang; },
|
|
160
|
+
t: (source, vars) => current.t(source, vars), // strings: passes on
|
|
161
|
+
tn: (n, one, other, vars) => current.tn(n, one, other, vars),
|
|
162
|
+
num: (n, opts) => current.num(n, opts),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
module.exports = { language, issueUrl, words: KitWords.words, pick: KitWords.pick, LANGUAGES: KitWords.LANGUAGES };
|
package/src/kit/scan.cjs
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/* PonderDev kit 1.1.0, built from kit/src. Do not edit: run bin/kit-sync. */
|
|
2
|
+
'use strict';
|
|
3
|
+
/*
|
|
4
|
+
* The family's intake for several files or a folder (decided 2026-11-20:
|
|
5
|
+
* every tool takes a dropped folder, and several files). It runs on the main
|
|
6
|
+
* side, and in a tool's command line, so a folder means the same thing in the
|
|
7
|
+
* window and in a terminal, and in every tool.
|
|
8
|
+
*
|
|
9
|
+
* const { scan } = require('./kit/scan.cjs');
|
|
10
|
+
* const { files, folders, missing } = await scan(paths, {
|
|
11
|
+
* extensions: ['.mp4', '.mov'], // what a tool takes from inside a folder
|
|
12
|
+
* ours: /-fits( \d+)?$/i, // its own results, passed over in a folder
|
|
13
|
+
* anyNamed: true, // a file named on its own is taken whatever its name
|
|
14
|
+
* word: 'fitted', // its results folders ("Holiday (fitted)"), passed over
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* files is [{ path, name, bytes, from }], resolved, each once, in the order a file
|
|
18
|
+
* browser lists them (numbers counted, so "clip 2" comes before "clip 10").
|
|
19
|
+
* folders counts the folders named; missing lists named paths that are not
|
|
20
|
+
* there. Inside a folder, subfolders too, only names with one of the
|
|
21
|
+
* extensions are taken, and hidden files and folders, the AppleDouble files
|
|
22
|
+
* ("._name") a Mac leaves on other disks, and the tool's own results are
|
|
23
|
+
* passed over, so a folder done once and then again is not done on top of
|
|
24
|
+
* itself. A file named on its own is taken when anyNamed is set (the tool's
|
|
25
|
+
* probe then says whether it can read it), or else only with one of the
|
|
26
|
+
* extensions. from is the folder named that the file was found in, or null
|
|
27
|
+
* for a file named on its own. It never throws: a folder it cannot read is
|
|
28
|
+
* passed over.
|
|
29
|
+
*
|
|
30
|
+
* Where results go (decided 2026-11-20): a file named on its own gets its
|
|
31
|
+
* result beside it, as always. A folder's results go into a new folder beside
|
|
32
|
+
* it, named for what the tool did ("Holiday (fitted)", "Holiday (JPEG)"),
|
|
33
|
+
* with the folder's subfolders mirrored inside and the folder itself left
|
|
34
|
+
* untouched. A name that is taken gets " 2", then 3: nothing is written over.
|
|
35
|
+
* A tool may offer "Save next to the originals instead", which puts every
|
|
36
|
+
* result beside its own original.
|
|
37
|
+
*
|
|
38
|
+
* const into = resultsFolder(file.from, 'fitted'); // once per folder, per run
|
|
39
|
+
* const dir = resultDir(file, into); // where this file's result goes
|
|
40
|
+
*/
|
|
41
|
+
const fs = require('node:fs');
|
|
42
|
+
const path = require('node:path');
|
|
43
|
+
|
|
44
|
+
async function scan(paths, options = {}) {
|
|
45
|
+
const extensions = new Set((options.extensions || []).map((e) => e.toLowerCase()));
|
|
46
|
+
const ours = options.ours || null;
|
|
47
|
+
const anyNamed = options.anyNamed !== false;
|
|
48
|
+
const resultsName = options.word ? new RegExp(` \\(${options.word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\)( \\d+)?$`, 'i') : null;
|
|
49
|
+
const found = [];
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
const missing = [];
|
|
52
|
+
let folders = 0;
|
|
53
|
+
|
|
54
|
+
async function walk(target, named, from) {
|
|
55
|
+
let stat;
|
|
56
|
+
try { stat = await fs.promises.stat(target); } catch { if (named) missing.push(target); return; }
|
|
57
|
+
|
|
58
|
+
if (stat.isDirectory()) {
|
|
59
|
+
if (named) folders++;
|
|
60
|
+
else if (resultsName && resultsName.test(path.basename(target))) return;
|
|
61
|
+
let entries;
|
|
62
|
+
try { entries = await fs.promises.readdir(target, { withFileTypes: true }); } catch { return; }
|
|
63
|
+
for (const entry of entries) {
|
|
64
|
+
if (entry.name.startsWith('.')) continue;
|
|
65
|
+
await walk(path.join(target, entry.name), false, named ? path.resolve(target) : from);
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!stat.isFile()) return;
|
|
71
|
+
const ext = path.extname(target).toLowerCase();
|
|
72
|
+
if (!(named && anyNamed) && !extensions.has(ext)) return;
|
|
73
|
+
if (!named && path.basename(target).startsWith('._')) return;
|
|
74
|
+
if (!named && ours && ours.test(path.parse(target).name)) return;
|
|
75
|
+
const key = path.resolve(target);
|
|
76
|
+
if (seen.has(key)) return;
|
|
77
|
+
seen.add(key);
|
|
78
|
+
found.push({ path: key, name: path.basename(target), bytes: stat.size, from: named ? null : from });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
for (const p of paths) await walk(p, true, null);
|
|
82
|
+
found.sort((a, b) => a.path.localeCompare(b.path, undefined, { numeric: true }));
|
|
83
|
+
return { files: found, folders, missing };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// A new folder beside the one named, for its results: "Holiday (fitted)", or
|
|
87
|
+
// "Holiday (fitted) 2" when that is taken (by anything: a file, a folder, an
|
|
88
|
+
// earlier run). Nothing is made here; the tool makes it when a result is ready.
|
|
89
|
+
function resultsFolder(folder, word, exists = fs.existsSync) {
|
|
90
|
+
const base = `${path.resolve(folder)} (${word})`;
|
|
91
|
+
let candidate = base;
|
|
92
|
+
for (let n = 2; exists(candidate) && n < 1000; n++) candidate = `${base} ${n}`;
|
|
93
|
+
return candidate;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Where one file's result goes: beside it when it was named on its own or no
|
|
97
|
+
// results folder is given (Save next to the originals), or else at the same
|
|
98
|
+
// place inside the results folder as it sits inside its own folder.
|
|
99
|
+
function resultDir(file, into) {
|
|
100
|
+
if (!file.from || !into) return path.dirname(file.path);
|
|
101
|
+
return path.join(into, path.relative(file.from, path.dirname(file.path)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = { scan, resultsFolder, resultDir };
|
|
105
|
+
module.exports.VERSION = '1.1.0';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/* PonderDev kit 1.1.0, built from kit/src. Do not edit: run bin/kit-sync. */
|
|
2
|
+
'use strict';
|
|
3
|
+
/*
|
|
4
|
+
* kit, main side: every Just tool window's frame (decided 2026-11-20).
|
|
5
|
+
*
|
|
6
|
+
* On Windows and Linux the app draws its own title bar in its own dark
|
|
7
|
+
* background, with the system's minimise, maximise and close buttons drawn
|
|
8
|
+
* over it in matching colours (Electron's titleBarOverlay), so no tool shows
|
|
9
|
+
* a white frame around a dark app. On a Mac the traffic lights sit over the
|
|
10
|
+
* page as before (hiddenInset).
|
|
11
|
+
*
|
|
12
|
+
* const { frame, dress } = require('./kit/window.cjs');
|
|
13
|
+
* win = new BrowserWindow({ width: 720, height: 780, ...frame(), webPreferences: {...} });
|
|
14
|
+
* dress(win);
|
|
15
|
+
*
|
|
16
|
+
* frame() gives the window's options: the frame, and backgroundColor (the
|
|
17
|
+
* kit's --bg, so nothing flashes white while the page loads). dress(win) puts
|
|
18
|
+
* the strip the title bar is drawn on into every page the window loads, a
|
|
19
|
+
* page of the tool's own or one without the kit (the licences page): the
|
|
20
|
+
* window's title on the left, room for the system buttons on the right, and
|
|
21
|
+
* the whole strip drags the window. A page that already has a .titlebar
|
|
22
|
+
* keeps it, and gets the title written into it.
|
|
23
|
+
*
|
|
24
|
+
* On Linux frame() also gives the window the tool's own name as its app id
|
|
25
|
+
* ("Just Cut"). A Linux desktop names a window it has no menu entry for by its
|
|
26
|
+
* app id alone (GNOME's dock does), so an AppImage run straight from Downloads
|
|
27
|
+
* shows "Just Cut" there, not "com.ponderdev.justcut". A menu entry finds the
|
|
28
|
+
* window by StartupWMClass, which the tool's Linux build sets to the same name.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
* Never a real browser from a test (decided 2026-11-27). With KIT_NO_EXTERNAL=1
|
|
33
|
+
* in the environment (every window test and every test room sets it), every
|
|
34
|
+
* shell.openExternal in this process, the kit's and the tool's own, only
|
|
35
|
+
* records the address and says so on stderr. It is replaced here because every
|
|
36
|
+
* tool's main requires this file before any window opens. externalOpened()
|
|
37
|
+
* gives the addresses, for a test to check.
|
|
38
|
+
*/
|
|
39
|
+
const externalOpened = [];
|
|
40
|
+
if (process.env.KIT_NO_EXTERNAL === '1') {
|
|
41
|
+
try {
|
|
42
|
+
const { shell } = require('electron');
|
|
43
|
+
if (shell && !(shell.openExternal && shell.openExternal.kitGuard)) {
|
|
44
|
+
const guarded = async (url) => { externalOpened.push(String(url)); process.stderr.write(`kit: not opening ${url} (KIT_NO_EXTERNAL=1)\n`); };
|
|
45
|
+
guarded.kitGuard = true;
|
|
46
|
+
shell.openExternal = guarded;
|
|
47
|
+
}
|
|
48
|
+
} catch (e) { /* not in Electron: nothing to open */ }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// The kit's --bg and --text (kit/src/tokens.css; the kit's tests compare them).
|
|
52
|
+
const BG = '#12131a';
|
|
53
|
+
const TEXT = '#eceef5';
|
|
54
|
+
const MUTED = '#9aa0b4';
|
|
55
|
+
// The strip's height on Windows and Linux: the system buttons' own height.
|
|
56
|
+
const HEIGHT = 32;
|
|
57
|
+
|
|
58
|
+
// Electron reads the app id from the desktop name (minus ".desktop") each
|
|
59
|
+
// time it makes a window, so this has to run before the first window: frame()
|
|
60
|
+
// is called in the window's options. Only in Electron's main process.
|
|
61
|
+
function linuxName(app, platform = process.platform) {
|
|
62
|
+
if (platform !== 'linux' || !app || typeof app.setDesktopName !== 'function') return;
|
|
63
|
+
app.setDesktopName(`${app.getName()}.desktop`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function frame(platform = process.platform) {
|
|
67
|
+
if (platform === 'linux' && process.type === 'browser') linuxName(require('electron').app, platform);
|
|
68
|
+
if (platform === 'darwin') return { titleBarStyle: 'hiddenInset', backgroundColor: BG };
|
|
69
|
+
return {
|
|
70
|
+
titleBarStyle: 'hidden',
|
|
71
|
+
titleBarOverlay: { color: BG, symbolColor: TEXT, height: HEIGHT },
|
|
72
|
+
backgroundColor: BG,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// The strip, for any page. env(titlebar-area-*) is where the page may draw
|
|
77
|
+
// beside the system buttons; the fallbacks are for a window without them.
|
|
78
|
+
const CSS = `
|
|
79
|
+
.titlebar { height: ${HEIGHT}px; flex: none; display: flex; align-items: center; -webkit-app-region: drag;
|
|
80
|
+
background: ${BG}; position: relative; z-index: 10; }
|
|
81
|
+
.titlebar .k-titlebar-name { padding-left: calc(env(titlebar-area-x, 0px) + 14px); max-width: env(titlebar-area-width, 100%);
|
|
82
|
+
font: 12px/1 system-ui, -apple-system, "Segoe UI", Ubuntu, sans-serif; color: ${MUTED};
|
|
83
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap; user-select: none; }
|
|
84
|
+
body.k-doc > .titlebar, body > .titlebar:first-child { margin: 0; }
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
// Runs in the page: a .titlebar first in the body (made if the page has none),
|
|
88
|
+
// with the window's title in it. DOM calls only, so a page's own
|
|
89
|
+
// Content-Security-Policy (no scripts, no inline styles) does not stop it.
|
|
90
|
+
const PUT = `(() => {
|
|
91
|
+
let bar = document.querySelector('.titlebar');
|
|
92
|
+
if (!bar) { bar = document.createElement('div'); bar.className = 'titlebar'; document.body.prepend(bar); }
|
|
93
|
+
if (!bar.querySelector('.k-titlebar-name')) {
|
|
94
|
+
const name = document.createElement('span');
|
|
95
|
+
name.className = 'k-titlebar-name';
|
|
96
|
+
bar.append(name);
|
|
97
|
+
}
|
|
98
|
+
bar.querySelector('.k-titlebar-name').textContent = document.title;
|
|
99
|
+
return true;
|
|
100
|
+
})()`;
|
|
101
|
+
|
|
102
|
+
function dress(win, platform = process.platform) {
|
|
103
|
+
if (platform === 'darwin') return;
|
|
104
|
+
const contents = win.webContents;
|
|
105
|
+
contents.on('dom-ready', () => {
|
|
106
|
+
contents.insertCSS(CSS).catch(() => {});
|
|
107
|
+
contents.executeJavaScript(PUT).catch(() => {});
|
|
108
|
+
});
|
|
109
|
+
// A page that changes its title (a file's name, say) keeps the strip true.
|
|
110
|
+
win.on('page-title-updated', () => { contents.executeJavaScript(PUT).catch(() => {}); });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = { frame, dress, linuxName, BG, TEXT, HEIGHT, CSS, externalOpened: () => externalOpened.slice() };
|
package/src/main.cjs
CHANGED
|
@@ -12,12 +12,41 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
const { app, BrowserWindow, screen, ipcMain, dialog, shell } = require('electron');
|
|
15
|
+
// The frame: a dark title bar of the app's own on Windows and Linux, the traffic lights on a Mac.
|
|
16
|
+
const { frame, dress } = require('./kit/window.cjs');
|
|
17
|
+
|
|
15
18
|
const path = require('node:path');
|
|
19
|
+
|
|
20
|
+
// The tool's own version, from its package.json. Not app.getVersion(): run by
|
|
21
|
+
// a test or a harness, Electron reports its own version instead.
|
|
22
|
+
const APP_VERSION = (() => {
|
|
23
|
+
try { return require(path.join(__dirname, '..', 'package.json')).version; } catch (e) { return app.getVersion(); }
|
|
24
|
+
})();
|
|
16
25
|
const fs = require('node:fs');
|
|
17
26
|
|
|
18
27
|
const engine = require('./engine.cjs');
|
|
19
28
|
const plan = require('./plan.js');
|
|
20
29
|
const binaries = require('./binaries.cjs');
|
|
30
|
+
const { scan, places, others } = require('./scan.cjs');
|
|
31
|
+
|
|
32
|
+
// The window's language on this side too, so a picker's title and every
|
|
33
|
+
// message sent to the window say the same language as the page. The window
|
|
34
|
+
// tells it the language as it starts; until then it is English. plan and the
|
|
35
|
+
// engine say things through the same words, so the targets, notes, progress
|
|
36
|
+
// and errors arrive translated (the command line never hands words over, and
|
|
37
|
+
// stays English). ffmpeg's own lines are passed on as they are.
|
|
38
|
+
const { language } = require('./kit/lang.cjs');
|
|
39
|
+
const { offerMenuEntry } = require('./kit/desktop.cjs');
|
|
40
|
+
const { family } = require('./kit/family.cjs');
|
|
41
|
+
const words = language({
|
|
42
|
+
ipcMain, shell,
|
|
43
|
+
strings: require('./renderer/strings.js'),
|
|
44
|
+
issues: 'https://github.com/ponder-dev/just-fits/issues',
|
|
45
|
+
tool: 'Just Fits',
|
|
46
|
+
});
|
|
47
|
+
plan.useWords(words);
|
|
48
|
+
// "Try Just Zip", "Try Just JPEG": a sibling's page on ponderdev.com, by id only.
|
|
49
|
+
family({ ipcMain, shell });
|
|
21
50
|
|
|
22
51
|
let win = null;
|
|
23
52
|
let ctl = null;
|
|
@@ -51,8 +80,13 @@ function binary(name) {
|
|
|
51
80
|
* own window. Without that the test would be checking a renderer that has
|
|
52
81
|
* nothing to talk to, and would miss a handler going missing here.
|
|
53
82
|
*/
|
|
83
|
+
// The folder each gathered file came in with (null for a file on its own),
|
|
84
|
+
// and where the current run is putting results (scan.cjs places).
|
|
85
|
+
const gathered = new Map();
|
|
86
|
+
let placing = null;
|
|
87
|
+
|
|
54
88
|
function registerHandlers() {
|
|
55
|
-
ipcMain.handle('targets', () => plan.
|
|
89
|
+
ipcMain.handle('targets', () => plan.targets());
|
|
56
90
|
|
|
57
91
|
ipcMain.handle('probe', async (_e, file) => {
|
|
58
92
|
let ffprobe;
|
|
@@ -66,21 +100,48 @@ function registerHandlers() {
|
|
|
66
100
|
lastOpenDir = path.dirname(file);
|
|
67
101
|
return { ok: true, info };
|
|
68
102
|
} catch (err) {
|
|
69
|
-
|
|
103
|
+
// Read fine but refused on purpose: its own sentence already names the file.
|
|
104
|
+
// code: which kind of failure, for the window's short reason in a queue.
|
|
105
|
+
if (err.code === 'animated-webp') return { ok: false, code: 'animated-webp', message: err.message };
|
|
106
|
+
const reason = String(err.message || err);
|
|
107
|
+
return { ok: false, code: probeCode(reason), message: probeMessage(file, reason) };
|
|
70
108
|
}
|
|
71
109
|
});
|
|
72
110
|
|
|
73
|
-
|
|
111
|
+
// run: a number the window gives each press of Compress, so a folder's
|
|
112
|
+
// results folder is chosen once per run ("Holiday (fitted)", then
|
|
113
|
+
// "Holiday (fitted) 2" the next time). Which folder a file came in with is
|
|
114
|
+
// main's own record from gather, never the page's word.
|
|
115
|
+
ipcMain.handle('fit', async (_e, { file, targetBytes, beside, run }) => {
|
|
74
116
|
ctl = engine.control();
|
|
75
117
|
const onProgress = (p) => {
|
|
76
118
|
if (win && !win.isDestroyed()) win.webContents.send('progress', p);
|
|
77
119
|
};
|
|
120
|
+
let where = null;
|
|
78
121
|
try {
|
|
79
122
|
const info = await engine.probe(binary('ffprobe'), file);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
123
|
+
if (!placing || placing.run !== run || placing.beside !== Boolean(beside)) placing = { run, beside: Boolean(beside), place: places({ beside }) };
|
|
124
|
+
where = placing.place({ path: path.resolve(file), from: gathered.get(path.resolve(file)) || null });
|
|
125
|
+
if (where.outDir) await fs.promises.mkdir(where.outDir, { recursive: true });
|
|
126
|
+
// Already small enough, in a folder's results folder: copied in under its
|
|
127
|
+
// -fits name, so the results folder holds the whole folder (decided 2026-11-20).
|
|
128
|
+
if (where.folder && info.bytes <= targetBytes) {
|
|
129
|
+
const to = engine.outputPath(path.join(where.outDir, path.basename(file)), path.extname(file), fs.existsSync, where.suffix);
|
|
130
|
+
await fs.promises.copyFile(file, to, fs.constants.COPYFILE_EXCL);
|
|
131
|
+
return { ok: true, copied: true, path: to, bytes: info.bytes, before: info.bytes, kind: info.kind, folder: where.folder };
|
|
132
|
+
}
|
|
133
|
+
const args = { ffmpeg: binary('ffmpeg'), file, info, targetBytes, onProgress, ctl, outDir: where.outDir, suffix: where.suffix };
|
|
134
|
+
const result = info.kind === 'image' ? await engine.fitImage(args) : info.kind === 'audio' ? await engine.fitAudio(args) : await engine.fitVideo(args);
|
|
135
|
+
return { ok: true, ...result, before: info.bytes, kind: info.kind, folder: where.folder, note: info.kind === 'video' || info.kind === 'audio' ? plan.lengthNote(result.plan) : '' };
|
|
83
136
|
} catch (err) {
|
|
137
|
+
// Stopped or failed: a results folder made for this file and left empty
|
|
138
|
+
// goes again, up to the results folder itself, so nothing empty is left.
|
|
139
|
+
if (where && where.folder) {
|
|
140
|
+
for (let dir = where.outDir; dir.startsWith(where.folder); dir = path.dirname(dir)) {
|
|
141
|
+
try { await fs.promises.rmdir(dir); } catch { break; }
|
|
142
|
+
if (dir === where.folder) break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
84
145
|
if (err && err.cancelled) return { ok: false, cancelled: true };
|
|
85
146
|
return { ok: false, message: String(err.message || err) };
|
|
86
147
|
} finally {
|
|
@@ -96,8 +157,15 @@ function registerHandlers() {
|
|
|
96
157
|
|
|
97
158
|
ipcMain.handle('reveal', (_e, file) => shell.showItemInFolder(file));
|
|
98
159
|
|
|
99
|
-
// Opens in the real browser, never in an app window.
|
|
160
|
+
// Opens in the real browser, never in an app window. The addresses are fixed
|
|
161
|
+
// here; the page never hands main a URL to open.
|
|
100
162
|
ipcMain.handle('open-site', () => shell.openExternal('https://ponderdev.com'));
|
|
163
|
+
ipcMain.handle('open-how-it-works', () => shell.openExternal('https://ponderdev.com/tools/just-fits/how-it-works'));
|
|
164
|
+
|
|
165
|
+
// The skill that ships with the app, for the start screen's Copy skill. Read
|
|
166
|
+
// beside the app's own files, so it is the same text inside the packaged app
|
|
167
|
+
// (electron-builder packs agents/) as from source.
|
|
168
|
+
ipcMain.handle('skill-text', () => fs.promises.readFile(path.join(__dirname, '..', 'agents', 'skills', 'justfits', 'SKILL.md'), 'utf8'));
|
|
101
169
|
|
|
102
170
|
// The GPL wants its notices readable by whoever has the app, not just by
|
|
103
171
|
// whoever finds the repo, so they open in a window of their own.
|
|
@@ -106,26 +174,55 @@ function registerHandlers() {
|
|
|
106
174
|
licenceWindow = new BrowserWindow({
|
|
107
175
|
width: 720,
|
|
108
176
|
height: 680,
|
|
109
|
-
title: 'Licences and credits',
|
|
110
|
-
|
|
177
|
+
title: words.t('Licences and credits'),
|
|
178
|
+
...frame(),
|
|
111
179
|
webPreferences: { contextIsolation: true, nodeIntegration: false },
|
|
112
180
|
});
|
|
181
|
+
dress(licenceWindow);
|
|
113
182
|
licenceWindow.setMenuBarVisibility(false);
|
|
114
183
|
licenceWindow.loadFile(path.join(__dirname, 'renderer', 'licenses.html'));
|
|
115
184
|
});
|
|
116
185
|
|
|
186
|
+
// Files and folders, several at once. Windows and Linux cannot offer files
|
|
187
|
+
// and folders in one window (asked for both, they show a folder picker), so
|
|
188
|
+
// there it picks files, and the start screen's Choose a folder (pick-folder)
|
|
189
|
+
// brings a folder in.
|
|
117
190
|
ipcMain.handle('pick-file', async () => {
|
|
118
191
|
const r = await dialog.showOpenDialog(win, {
|
|
119
192
|
defaultPath: lastOpenDir || app.getPath('documents'),
|
|
120
|
-
properties: ['openFile'],
|
|
193
|
+
properties: process.platform === 'darwin' ? ['openFile', 'openDirectory', 'multiSelections'] : ['openFile', 'multiSelections'],
|
|
121
194
|
filters: [{
|
|
122
|
-
name: 'Video and
|
|
123
|
-
extensions: ['mp4', 'mov', 'mkv', 'webm', 'avi', 'm4v', 'jpg', 'jpeg', 'png', 'heic', 'webp', 'gif'
|
|
195
|
+
name: words.t('Video, images and sound'),
|
|
196
|
+
extensions: ['mp4', 'mov', 'mkv', 'webm', 'avi', 'm4v', 'jpg', 'jpeg', 'png', 'heic', 'webp', 'gif',
|
|
197
|
+
'mp3', 'm4a', 'aac', 'wav', 'flac', 'ogg', 'opus', 'aif', 'aiff'],
|
|
124
198
|
}],
|
|
125
199
|
});
|
|
126
|
-
if (r.canceled) return
|
|
200
|
+
if (r.canceled || !r.filePaths.length) return [];
|
|
127
201
|
lastOpenDir = path.dirname(r.filePaths[0]);
|
|
128
|
-
return r.filePaths
|
|
202
|
+
return r.filePaths;
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Folders only, for Windows and Linux, where pick-file cannot offer them.
|
|
206
|
+
ipcMain.handle('pick-folder', async () => {
|
|
207
|
+
const r = await dialog.showOpenDialog(win, {
|
|
208
|
+
defaultPath: lastOpenDir || app.getPath('documents'),
|
|
209
|
+
properties: ['openDirectory', 'multiSelections'],
|
|
210
|
+
});
|
|
211
|
+
if (r.canceled || !r.filePaths.length) return [];
|
|
212
|
+
lastOpenDir = r.filePaths[0];
|
|
213
|
+
return r.filePaths;
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// What several paths, or a folder, hold (scan.cjs). single: one path that is
|
|
217
|
+
// not a folder, which the window takes the way it takes one file.
|
|
218
|
+
ipcMain.handle('gather', async (_e, paths) => {
|
|
219
|
+
const list = Array.isArray(paths) ? paths.filter((p) => typeof p === 'string' && p) : [];
|
|
220
|
+
const found = await scan(list);
|
|
221
|
+
for (const f of found.files) gathered.set(f.path, f.from);
|
|
222
|
+
if (found.files[0]) lastOpenDir = path.dirname(found.files[0].path);
|
|
223
|
+
// others: a folder holds files that are not videos or pictures, which the
|
|
224
|
+
// window points to Just Zip for.
|
|
225
|
+
return { ...found, others: found.folders ? await others(list) : false, single: list.length === 1 && found.folders === 0 };
|
|
129
226
|
});
|
|
130
227
|
}
|
|
131
228
|
|
|
@@ -133,11 +230,17 @@ function registerHandlers() {
|
|
|
133
230
|
// Invalid data found when processing input"), which in the window is long,
|
|
134
231
|
// technical and wraps across the error box. The window says it as a sentence
|
|
135
232
|
// that names the file. The command line keeps ffprobe's words, for scripts.
|
|
233
|
+
function probeCode(reason) {
|
|
234
|
+
if (/no such file/i.test(reason)) return 'missing';
|
|
235
|
+
if (/permission denied|operation not permitted/i.test(reason)) return 'denied';
|
|
236
|
+
return 'unreadable';
|
|
237
|
+
}
|
|
136
238
|
function probeMessage(file, reason) {
|
|
137
239
|
const name = path.basename(String(file || ''));
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
return
|
|
240
|
+
const code = probeCode(reason);
|
|
241
|
+
if (code === 'missing') return words.t('Could not find {name}. It may have been moved or deleted.', { name });
|
|
242
|
+
if (code === 'denied') return words.t('Just Fits is not allowed to open {name}.', { name });
|
|
243
|
+
return words.t('{name} is not a video, picture or sound file that Just Fits can read.', { name });
|
|
141
244
|
}
|
|
142
245
|
|
|
143
246
|
|
|
@@ -161,16 +264,24 @@ function registerHandlers() {
|
|
|
161
264
|
height: 780,
|
|
162
265
|
minWidth: 560,
|
|
163
266
|
minHeight: 640,
|
|
164
|
-
|
|
165
|
-
titleBarStyle: process.platform === 'darwin' ? 'hiddenInset' : 'default',
|
|
267
|
+
...frame(),
|
|
166
268
|
webPreferences: {
|
|
167
269
|
preload: path.join(__dirname, 'preload.cjs'),
|
|
168
270
|
contextIsolation: true,
|
|
169
271
|
nodeIntegration: false,
|
|
272
|
+
// The version, from package.json, for the start screen and the footer.
|
|
273
|
+
// A sandboxed preload cannot read package.json, so it comes on argv.
|
|
274
|
+
additionalArguments: ['--app-version=' + APP_VERSION],
|
|
170
275
|
},
|
|
171
276
|
}));
|
|
277
|
+
dress(win);
|
|
172
278
|
win.setMenuBarVisibility(false);
|
|
173
279
|
win.loadFile(path.join(__dirname, 'renderer', 'index.html'));
|
|
280
|
+
// A Linux AppImage asks once to be in the applications menu. After the
|
|
281
|
+
// page has told main its language, so the question is in it.
|
|
282
|
+
win.webContents.once('did-finish-load', () => {
|
|
283
|
+
setTimeout(() => { offerMenuEntry({ app, dialog, win, words }).catch(() => {}); }, 1500);
|
|
284
|
+
});
|
|
174
285
|
}
|
|
175
286
|
|
|
176
287
|
// Guarded so requiring this file from a test registers the handlers without
|
|
@@ -186,4 +297,4 @@ function registerHandlers() {
|
|
|
186
297
|
});
|
|
187
298
|
}
|
|
188
299
|
|
|
189
|
-
module.exports = { registerHandlers, binary, probeMessage };
|
|
300
|
+
module.exports = { registerHandlers, binary, probeMessage, probeCode };
|