Skip to content

Commit b9497b1

Browse files
committed
plugin support
1 parent 961d002 commit b9497b1

4 files changed

Lines changed: 324 additions & 217 deletions

File tree

src/main/initPlugin.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
const mupdfProps = {
2+
from: {
3+
text: [
4+
"pdf",
5+
"epub",
6+
"xps",
7+
"cbz",
8+
"mobi",
9+
"fb2",
10+
"svg",
11+
"png",
12+
"jpg",
13+
"bmp"
14+
],
15+
},
16+
to: {
17+
text: [
18+
"cbz",
19+
"png",
20+
"pnm",
21+
"pgm",
22+
"ppm",
23+
"pam",
24+
"pbm",
25+
"pkm",
26+
"pcl",
27+
"pclm",
28+
"ps",
29+
"pwg",
30+
"pdf",
31+
"svg",
32+
"html",
33+
"xhtml",
34+
"text",
35+
"stext"
36+
],
37+
}
38+
}
39+
import {execFile} from 'node:child_process';
40+
import path from 'path';
41+
import { join } from 'path';
42+
import fs from 'fs'
43+
const converterPath = join(__dirname, '../Plugins', 'mutool.exe');
44+
export async function documentConvert(filename,inputPath,outputPath, options = {}) {
45+
return new Promise((resolve, reject) => {
46+
const outputFormat = options.format;
47+
const args = [
48+
'convert',
49+
'-F',outputFormat,
50+
'-o',`${outputPath}\\${filename}.${outputFormat}`,
51+
inputPath
52+
];
53+
54+
execFile(converterPath, args, (error, stdout, stderr) => {
55+
if (error) {
56+
console.error('Conversion Error:', error);
57+
reject(new Error(`Conversion failed: ${error.message}`));
58+
return;
59+
}
60+
61+
if (stderr) {
62+
console.error('Conversion stderr:', stderr);
63+
reject(new Error(`Conversion error: ${stderr}`));
64+
return;
65+
}
66+
67+
// Check if output file was created
68+
if (!fs.existsSync(outputPath)) {
69+
reject(new Error('Output file was not created'));
70+
return;
71+
}
72+
73+
resolve({
74+
success: true,
75+
outputPath,
76+
message: 'File converted successfully',
77+
stdout
78+
});
79+
});
80+
});
81+
}
82+
export function getSupportedFormats() {
83+
return {
84+
input: mupdfProps.from.text,
85+
output: mupdfProps.to.text
86+
};
87+
}
88+
// Add validation function for supported formats
89+
export function isFormatSupported(format, type = 'input') {
90+
const formats = type === 'input' ? mupdfProps.from.text : mupdfProps.to.text;
91+
return formats.includes(format.toLowerCase());
92+
}
93+
94+
// Update checkPluginInstalled to be more robust
95+
export async function checkPluginInstalled() {
96+
try {
97+
const pluginPath = path.join('out', 'Plugins', 'mutool.exe');
98+
const exists = fs.existsSync(pluginPath);
99+
if (!exists) {
100+
return false;
101+
}
102+
await new Promise((resolve, reject) => {
103+
execFile(pluginPath, ['--version'], (error, stdout, stderr) => {
104+
if (error) {
105+
reject(error);
106+
} else {
107+
resolve(stdout);
108+
}
109+
});
110+
});
111+
112+
return true;
113+
} catch (error) {
114+
console.error('Plugin check failed:', error);
115+
return false;
116+
}
117+
}

src/preload/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ if (process.contextIsolated) {
2222
} else {
2323
window.electron = electronAPI
2424
window.api = api
25-
}
25+
}
26+
contextBridge.exposeInMainWorld('electronAPI',{
27+
dwnPlugin: (url) => ipcRenderer.send('plugin:install',url)
28+
})

src/renderer/src/components/Plugins.vue

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
<script setup>
2-
import { ref } from 'vue'
3-
2+
import { ref,onMounted } from 'vue'
3+
const {ipcRenderer} = window.electron
4+
const isInstalling = ref(false)
45
const plugins = ref([
56
{
6-
id: 'pandoc',
7-
name: 'Pandoc Document Converter',
8-
publisher: 'OpenConvert',
9-
summary: 'Universal document converter supporting Markdown, HTML, LaTeX, DOCX, PDF and many more formats',
10-
github: 'https://github.com/jgm/pandoc',
11-
version: '3.1.11',
12-
fileSize: '23.4 MB',
7+
id: 'mutool',
8+
name: 'MuPDF',
9+
publisher: 'utmp',
10+
summary: 'Universal document converter supporting HTML, EPUB, MOBI, DOCX, PDF and many more formats',
11+
github: 'https://github.com/ArtifexSoftware/mupdf',
12+
version: '1.25.2',
13+
fileSize: '39.9 MB',
1314
installed: false,
14-
formats: {
15-
input: ['markdown', 'html', 'latex', 'docx', 'odt', 'epub'],
16-
output: ['pdf', 'docx', 'html', 'markdown', 'epub', 'latex']
17-
}
1815
}
1916
])
20-
17+
onMounted(async () => {
18+
for (const plugin of plugins.value) {
19+
const isInstalled = await ipcRenderer.invoke('plugin:check-installed', plugin.id)
20+
plugin.installed = isInstalled
21+
}
22+
})
2123
async function installPlugin(pluginId) {
2224
const plugin = plugins.value.find(p => p.id === pluginId)
2325
if (!plugin) return
24-
26+
isInstalling.value = true
2527
try {
26-
// Here we would normally call the electron API to install the plugin
27-
// For now just simulate installation
28+
await ipcRenderer.invoke('plugin:install',{
29+
url: 'https://github.com/OpenConvert/website/releases/download/0.0.0/mutool.exe',
30+
id: pluginId
31+
})
2832
plugin.installed = true
33+
isInstalling.value = false
2934
} catch (error) {
3035
console.error('Failed to install plugin:', error)
3136
}
@@ -36,7 +41,7 @@ async function uninstallPlugin(pluginId) {
3641
if (!plugin) return
3742
3843
try {
39-
// Here we would normally call the electron API to uninstall the plugin
44+
await ipcRenderer.invoke('plugin:uninstall',pluginId)
4045
plugin.installed = false
4146
} catch (error) {
4247
console.error('Failed to uninstall plugin:', error)
@@ -56,7 +61,7 @@ async function uninstallPlugin(pluginId) {
5661
<!-- Plugin Icon (maybe in future releases)-->
5762
<div class="flex-shrink-0">
5863
<div class="bg-gray-600 h-32 w-32 rounded flex items-center justify-center">
59-
<img src="https://pandoc.org/pandoc-cartoon.svgz">
64+
<img src="https://mupdf.readthedocs.io/en/latest/_static/mupdf-sidebar-logo-light.png">
6065

6166
</div>
6267
</div>
@@ -96,7 +101,9 @@ async function uninstallPlugin(pluginId) {
96101
@click="plugin.installed ? uninstallPlugin(plugin.id) : installPlugin(plugin.id)"
97102
class="btn btn-sm"
98103
:class="plugin.installed ? 'btn-error' : 'btn-primary'"
99-
>
104+
> <span v-if="isInstalling" class="loading loading-spinner">
105+
{{ isInstalling ? 'Installing' : 'Install' }}
106+
</span>
100107
{{ plugin.installed ? 'Uninstall' : 'Install' }}
101108
</button>
102109
</div>

0 commit comments

Comments
 (0)