@ponderdev/justfits 1.3.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 +46 -10
- package/agents/skills/justfits/SKILL.md +12 -10
- package/package.json +2 -2
- package/src/cli.cjs +42 -20
- package/src/engine.cjs +79 -12
- 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 +2 -2
- package/src/kit/window.cjs +22 -2
- package/src/main.cjs +49 -14
- package/src/plan.js +128 -29
- package/src/preload.cjs +11 -0
- package/src/renderer/app.js +332 -117
- package/src/renderer/index.html +11 -4
- package/src/renderer/kit/kit.css +16 -3
- package/src/renderer/kit/kit.js +351 -34
- package/src/renderer/licenses.html +1 -1
- package/src/renderer/strings.js +1562 -0
- package/src/scan.cjs +39 -2
|
@@ -0,0 +1,136 @@
|
|
|
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: a Linux AppImage puts itself in the applications menu, once
|
|
5
|
+
* asked (decided 2026-11-21).
|
|
6
|
+
*
|
|
7
|
+
* An AppImage run straight from Downloads has no menu entry, so GNOME's dock
|
|
8
|
+
* shows a grey gear for it and the person has to find the file again next
|
|
9
|
+
* time. On its first run the tool asks once: "Add Just Zip to your
|
|
10
|
+
* applications menu?" Yes writes a menu entry and the icon into the person's
|
|
11
|
+
* own folders (~/.local/share, nothing system wide, no password); Not now is
|
|
12
|
+
* remembered and never asked again. Once there is an entry, a run from a new
|
|
13
|
+
* place (the file was moved) quietly points the entry at the new place.
|
|
14
|
+
*
|
|
15
|
+
* const { offerMenuEntry } = require('./kit/desktop.cjs');
|
|
16
|
+
* app.whenReady().then(() => { ...make the window...; offerMenuEntry({ app, dialog, win, words }); });
|
|
17
|
+
*
|
|
18
|
+
* Only on Linux, only when run as an AppImage (APPIMAGE is set), never under
|
|
19
|
+
* a test (JUST_TEST_NO_WINDOW) and never when the person said Not now. A
|
|
20
|
+
* folder that cannot be written is left alone: the tool runs as before.
|
|
21
|
+
*/
|
|
22
|
+
const fs = require('node:fs');
|
|
23
|
+
const path = require('node:path');
|
|
24
|
+
const os = require('node:os');
|
|
25
|
+
|
|
26
|
+
// The menu entry's file name and the icon's name: the app id, lower case,
|
|
27
|
+
// no spaces ("Just Zip" -> "justzip").
|
|
28
|
+
const idOf = (app) => String(app.getName()).toLowerCase().replace(/[^a-z0-9]+/g, '');
|
|
29
|
+
|
|
30
|
+
function places(app, env = process.env, home = os.homedir()) {
|
|
31
|
+
const data = env.XDG_DATA_HOME && path.isAbsolute(env.XDG_DATA_HOME) ? env.XDG_DATA_HOME : path.join(home, '.local', 'share');
|
|
32
|
+
const id = idOf(app);
|
|
33
|
+
return {
|
|
34
|
+
id,
|
|
35
|
+
entry: path.join(data, 'applications', `ponderdev-${id}.desktop`),
|
|
36
|
+
icon: path.join(data, 'icons', 'hicolor', '256x256', 'apps', `ponderdev-${id}.png`),
|
|
37
|
+
answer: path.join(app.getPath('userData'), 'kit-menu-entry.json'),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Quoted for a desktop entry's Exec line (the spec's rules: double quotes,
|
|
42
|
+
// with backslash before ", `, $ and \).
|
|
43
|
+
const quoteExec = (p) => `"${String(p).replace(/(["`$\\])/g, '\\$1')}"`;
|
|
44
|
+
|
|
45
|
+
function entryText({ name, exec, icon, comment }) {
|
|
46
|
+
return [
|
|
47
|
+
'[Desktop Entry]',
|
|
48
|
+
'Type=Application',
|
|
49
|
+
`Name=${name}`,
|
|
50
|
+
comment ? `Comment=${comment.replace(/\n/g, ' ')}` : null,
|
|
51
|
+
`Exec=${quoteExec(exec)} %U`,
|
|
52
|
+
`Icon=${icon}`,
|
|
53
|
+
// the window's app id is the product name (window.cjs), so the dock ties the window to this entry
|
|
54
|
+
`StartupWMClass=${name}`,
|
|
55
|
+
'Terminal=false',
|
|
56
|
+
'Categories=Utility;',
|
|
57
|
+
'X-PonderDev-Kit=menu-entry',
|
|
58
|
+
'',
|
|
59
|
+
].filter((l) => l !== null).join('\n');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// The AppImage carries its icon at the mount point's root (.DirIcon) and in usr/share/icons.
|
|
63
|
+
function iconSource(env = process.env, id = '') {
|
|
64
|
+
const dir = env.APPDIR;
|
|
65
|
+
if (!dir) return null;
|
|
66
|
+
const tries = [
|
|
67
|
+
path.join(dir, 'usr', 'share', 'icons', 'hicolor', '256x256', 'apps', `${id}.png`),
|
|
68
|
+
path.join(dir, `${id}.png`),
|
|
69
|
+
path.join(dir, '.DirIcon'),
|
|
70
|
+
];
|
|
71
|
+
return tries.find((p) => { try { return fs.statSync(p).isFile(); } catch { return false; } }) || null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function readAnswer(file) {
|
|
75
|
+
try { const a = JSON.parse(fs.readFileSync(file, 'utf8')); return a && typeof a === 'object' ? a : {}; } catch { return {}; }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function write(p, { app, env = process.env }) {
|
|
79
|
+
const exec = env.APPIMAGE;
|
|
80
|
+
fs.mkdirSync(path.dirname(p.entry), { recursive: true });
|
|
81
|
+
const src = iconSource(env, p.id);
|
|
82
|
+
let icon = p.id;
|
|
83
|
+
if (src) {
|
|
84
|
+
fs.mkdirSync(path.dirname(p.icon), { recursive: true });
|
|
85
|
+
fs.copyFileSync(src, p.icon);
|
|
86
|
+
icon = p.icon;
|
|
87
|
+
}
|
|
88
|
+
fs.writeFileSync(p.entry, entryText({ name: app.getName(), exec, icon }), { mode: 0o644 });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// What the entry says it runs, or null.
|
|
92
|
+
function entryExec(file) {
|
|
93
|
+
try {
|
|
94
|
+
const m = /^Exec="((?:\\.|[^"\\])*)"/m.exec(fs.readFileSync(file, 'utf8'));
|
|
95
|
+
return m ? m[1].replace(/\\(.)/g, '$1') : null;
|
|
96
|
+
} catch { return null; }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Returns what it did: 'not-appimage', 'test', 'declined', 'moved' (the entry
|
|
101
|
+
* now points at the new place), 'current', 'added', 'not-now', or 'failed'.
|
|
102
|
+
*/
|
|
103
|
+
async function offerMenuEntry({ app, dialog, win, words, env = process.env, platform = process.platform, home } = {}) {
|
|
104
|
+
if (platform !== 'linux' || !env.APPIMAGE) return 'not-appimage';
|
|
105
|
+
if (env.JUST_TEST_NO_WINDOW) return 'test';
|
|
106
|
+
const p = places(app, env, home);
|
|
107
|
+
const t = (s, v) => (words ? words.t(s, v) : String(s).replace(/\{(\w+)\}/g, (m, k) => (v && k in v ? v[k] : m)));
|
|
108
|
+
try {
|
|
109
|
+
if (fs.existsSync(p.entry)) {
|
|
110
|
+
if (entryExec(p.entry) === env.APPIMAGE) return 'current';
|
|
111
|
+
write(p, { app, env });
|
|
112
|
+
return 'moved';
|
|
113
|
+
}
|
|
114
|
+
const answer = readAnswer(p.answer);
|
|
115
|
+
if (answer.menuEntry === 'not-now') return 'declined';
|
|
116
|
+
const { response } = await dialog.showMessageBox(win, {
|
|
117
|
+
type: 'question',
|
|
118
|
+
buttons: [t('Add it'), t('Not now')],
|
|
119
|
+
defaultId: 0,
|
|
120
|
+
cancelId: 1,
|
|
121
|
+
message: t('Add {name} to your applications menu?', { name: app.getName() }),
|
|
122
|
+
detail: t('Then you can open it from the menu and the dock like any other app. It is only added for you, and you will not be asked again.'),
|
|
123
|
+
});
|
|
124
|
+
if (response !== 0) {
|
|
125
|
+
fs.mkdirSync(path.dirname(p.answer), { recursive: true });
|
|
126
|
+
fs.writeFileSync(p.answer, JSON.stringify(Object.assign(answer, { menuEntry: 'not-now' })) + '\n');
|
|
127
|
+
return 'not-now';
|
|
128
|
+
}
|
|
129
|
+
write(p, { app, env });
|
|
130
|
+
return 'added';
|
|
131
|
+
} catch (e) {
|
|
132
|
+
return 'failed';
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
module.exports = { offerMenuEntry, entryText, quoteExec, places, entryExec, iconSource };
|
|
@@ -0,0 +1,29 @@
|
|
|
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: family hints. The window's "Try Just Zip" asks for
|
|
5
|
+
* a sibling by id; this opens that tool's page on ponderdev.com and nothing
|
|
6
|
+
* else. The window never sends an address.
|
|
7
|
+
*
|
|
8
|
+
* const { family } = require('./kit/family.cjs');
|
|
9
|
+
* family({ ipcMain, shell });
|
|
10
|
+
*
|
|
11
|
+
* The preload exposes it as `openSibling: (id) => ipcRenderer.invoke('kit:open-sibling', id)`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// The released tools a hint may point to (kit/src/parts/family.js holds the same list).
|
|
15
|
+
const FAMILY = ['justzip', 'justfits', 'justjpeg', 'justcut'];
|
|
16
|
+
|
|
17
|
+
const pageOf = (id) => (FAMILY.includes(id) ? `https://ponderdev.com/${id}` : null);
|
|
18
|
+
|
|
19
|
+
function family({ ipcMain, shell } = {}) {
|
|
20
|
+
if (!ipcMain) return;
|
|
21
|
+
ipcMain.handle('kit:open-sibling', async (_event, id) => {
|
|
22
|
+
const url = pageOf(id);
|
|
23
|
+
if (!url) return false;
|
|
24
|
+
if (shell) await shell.openExternal(url);
|
|
25
|
+
return true;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = { family, pageOf, FAMILY };
|
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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* PonderDev kit 1.
|
|
1
|
+
/* PonderDev kit 1.1.0, built from kit/src. Do not edit: run bin/kit-sync. */
|
|
2
2
|
'use strict';
|
|
3
3
|
/*
|
|
4
4
|
* The family's intake for several files or a folder (decided 2026-11-20:
|
|
@@ -102,4 +102,4 @@ function resultDir(file, into) {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
module.exports = { scan, resultsFolder, resultDir };
|
|
105
|
-
module.exports.VERSION = '1.
|
|
105
|
+
module.exports.VERSION = '1.1.0';
|
package/src/kit/window.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* PonderDev kit 1.
|
|
1
|
+
/* PonderDev kit 1.1.0, built from kit/src. Do not edit: run bin/kit-sync. */
|
|
2
2
|
'use strict';
|
|
3
3
|
/*
|
|
4
4
|
* kit, main side: every Just tool window's frame (decided 2026-11-20).
|
|
@@ -28,6 +28,26 @@
|
|
|
28
28
|
* window by StartupWMClass, which the tool's Linux build sets to the same name.
|
|
29
29
|
*/
|
|
30
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
|
+
|
|
31
51
|
// The kit's --bg and --text (kit/src/tokens.css; the kit's tests compare them).
|
|
32
52
|
const BG = '#12131a';
|
|
33
53
|
const TEXT = '#eceef5';
|
|
@@ -90,4 +110,4 @@ function dress(win, platform = process.platform) {
|
|
|
90
110
|
win.on('page-title-updated', () => { contents.executeJavaScript(PUT).catch(() => {}); });
|
|
91
111
|
}
|
|
92
112
|
|
|
93
|
-
module.exports = { frame, dress, linuxName, BG, TEXT, HEIGHT, CSS };
|
|
113
|
+
module.exports = { frame, dress, linuxName, BG, TEXT, HEIGHT, CSS, externalOpened: () => externalOpened.slice() };
|
package/src/main.cjs
CHANGED
|
@@ -27,7 +27,26 @@ const fs = require('node:fs');
|
|
|
27
27
|
const engine = require('./engine.cjs');
|
|
28
28
|
const plan = require('./plan.js');
|
|
29
29
|
const binaries = require('./binaries.cjs');
|
|
30
|
-
const { scan, places } = require('./scan.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 });
|
|
31
50
|
|
|
32
51
|
let win = null;
|
|
33
52
|
let ctl = null;
|
|
@@ -67,7 +86,7 @@ const gathered = new Map();
|
|
|
67
86
|
let placing = null;
|
|
68
87
|
|
|
69
88
|
function registerHandlers() {
|
|
70
|
-
ipcMain.handle('targets', () => plan.
|
|
89
|
+
ipcMain.handle('targets', () => plan.targets());
|
|
71
90
|
|
|
72
91
|
ipcMain.handle('probe', async (_e, file) => {
|
|
73
92
|
let ffprobe;
|
|
@@ -82,8 +101,10 @@ function registerHandlers() {
|
|
|
82
101
|
return { ok: true, info };
|
|
83
102
|
} catch (err) {
|
|
84
103
|
// Read fine but refused on purpose: its own sentence already names the file.
|
|
85
|
-
|
|
86
|
-
return { ok: false,
|
|
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) };
|
|
87
108
|
}
|
|
88
109
|
});
|
|
89
110
|
|
|
@@ -110,8 +131,8 @@ function registerHandlers() {
|
|
|
110
131
|
return { ok: true, copied: true, path: to, bytes: info.bytes, before: info.bytes, kind: info.kind, folder: where.folder };
|
|
111
132
|
}
|
|
112
133
|
const args = { ffmpeg: binary('ffmpeg'), file, info, targetBytes, onProgress, ctl, outDir: where.outDir, suffix: where.suffix };
|
|
113
|
-
const result = info.kind === 'image' ? await engine.fitImage(args) : await engine.fitVideo(args);
|
|
114
|
-
return { ok: true, ...result, before: info.bytes, kind: info.kind, folder: where.folder, note: info.kind === 'video' ? plan.lengthNote(result.plan) : '' };
|
|
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) : '' };
|
|
115
136
|
} catch (err) {
|
|
116
137
|
// Stopped or failed: a results folder made for this file and left empty
|
|
117
138
|
// goes again, up to the results folder itself, so nothing empty is left.
|
|
@@ -153,7 +174,7 @@ function registerHandlers() {
|
|
|
153
174
|
licenceWindow = new BrowserWindow({
|
|
154
175
|
width: 720,
|
|
155
176
|
height: 680,
|
|
156
|
-
title: 'Licences and credits',
|
|
177
|
+
title: words.t('Licences and credits'),
|
|
157
178
|
...frame(),
|
|
158
179
|
webPreferences: { contextIsolation: true, nodeIntegration: false },
|
|
159
180
|
});
|
|
@@ -171,8 +192,9 @@ function registerHandlers() {
|
|
|
171
192
|
defaultPath: lastOpenDir || app.getPath('documents'),
|
|
172
193
|
properties: process.platform === 'darwin' ? ['openFile', 'openDirectory', 'multiSelections'] : ['openFile', 'multiSelections'],
|
|
173
194
|
filters: [{
|
|
174
|
-
name: 'Video and
|
|
175
|
-
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'],
|
|
176
198
|
}],
|
|
177
199
|
});
|
|
178
200
|
if (r.canceled || !r.filePaths.length) return [];
|
|
@@ -198,7 +220,9 @@ function registerHandlers() {
|
|
|
198
220
|
const found = await scan(list);
|
|
199
221
|
for (const f of found.files) gathered.set(f.path, f.from);
|
|
200
222
|
if (found.files[0]) lastOpenDir = path.dirname(found.files[0].path);
|
|
201
|
-
|
|
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 };
|
|
202
226
|
});
|
|
203
227
|
}
|
|
204
228
|
|
|
@@ -206,11 +230,17 @@ function registerHandlers() {
|
|
|
206
230
|
// Invalid data found when processing input"), which in the window is long,
|
|
207
231
|
// technical and wraps across the error box. The window says it as a sentence
|
|
208
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
|
+
}
|
|
209
238
|
function probeMessage(file, reason) {
|
|
210
239
|
const name = path.basename(String(file || ''));
|
|
211
|
-
|
|
212
|
-
if (
|
|
213
|
-
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 });
|
|
214
244
|
}
|
|
215
245
|
|
|
216
246
|
|
|
@@ -247,6 +277,11 @@ function registerHandlers() {
|
|
|
247
277
|
dress(win);
|
|
248
278
|
win.setMenuBarVisibility(false);
|
|
249
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
|
+
});
|
|
250
285
|
}
|
|
251
286
|
|
|
252
287
|
// Guarded so requiring this file from a test registers the handlers without
|
|
@@ -262,4 +297,4 @@ function registerHandlers() {
|
|
|
262
297
|
});
|
|
263
298
|
}
|
|
264
299
|
|
|
265
|
-
module.exports = { registerHandlers, binary, probeMessage };
|
|
300
|
+
module.exports = { registerHandlers, binary, probeMessage, probeCode };
|