Skip to content

Commit c64d668

Browse files
tutman96Nevexo
authored andcommitted
Better handle install and re-install lifecycle. Also display all the juicy bits about the plugin
1 parent 79bb1ef commit c64d668

File tree

6 files changed

+70
-27
lines changed

6 files changed

+70
-27
lines changed

internal/plugin/install.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type PluginInstall struct {
1919
ExtractedVersions map[string]string `json:"extracted_versions"`
2020

2121
manifest *PluginManifest
22-
runningVersion *string
22+
runningVersion string
2323
processManager *ProcessManager
2424
rpcServer *PluginRpcServer
2525
}
@@ -84,10 +84,7 @@ func (p *PluginInstall) ReconcileSubprocess() error {
8484
return fmt.Errorf("failed to get plugin manifest: %v", err)
8585
}
8686

87-
versionRunning := ""
88-
if p.runningVersion != nil {
89-
versionRunning = *p.runningVersion
90-
}
87+
versionRunning := p.runningVersion
9188

9289
versionShouldBeRunning := p.Version
9390
if !p.Enabled {
@@ -105,7 +102,7 @@ func (p *PluginInstall) ReconcileSubprocess() error {
105102
log.Printf("Stopping plugin %s running version %s", manifest.Name, versionRunning)
106103
p.processManager.Disable()
107104
p.processManager = nil
108-
p.runningVersion = nil
105+
p.runningVersion = ""
109106
err = p.rpcServer.Stop()
110107
if err != nil {
111108
return fmt.Errorf("failed to stop rpc server: %v", err)
@@ -146,7 +143,11 @@ func (p *PluginInstall) ReconcileSubprocess() error {
146143
})
147144
p.processManager.StartMonitor()
148145
p.processManager.Enable()
149-
p.runningVersion = &p.Version
146+
p.runningVersion = p.Version
147+
148+
// Clear out manifest so the new version gets pulled next time
149+
p.manifest = nil
150+
150151
log.Printf("Started plugin %s version %s", manifest.Name, p.Version)
151152
return nil
152153
}
@@ -155,7 +156,7 @@ func (p *PluginInstall) Shutdown() {
155156
if p.processManager != nil {
156157
p.processManager.Disable()
157158
p.processManager = nil
158-
p.runningVersion = nil
159+
p.runningVersion = ""
159160
}
160161

161162
if p.rpcServer != nil {

internal/plugin/plugin.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ func RpcPluginExtract(filename string) (*PluginManifest, error) {
120120
}
121121

122122
func RpcPluginInstall(name string, version string) error {
123-
// TODO: find the plugin version in the plugins.json file
124123
pluginInstall, ok := pluginDatabase.Plugins[name]
125124
if !ok {
126125
return fmt.Errorf("plugin not found: %s", name)
@@ -136,8 +135,6 @@ func RpcPluginInstall(name string, version string) error {
136135
return fmt.Errorf("plugin version not found: %s", version)
137136
}
138137

139-
// TODO: If there is a running plugin with the same name, stop it and start the new version
140-
141138
pluginInstall.Version = version
142139
pluginInstall.Enabled = true
143140
pluginDatabase.Plugins[name] = pluginInstall
@@ -151,7 +148,7 @@ func RpcPluginInstall(name string, version string) error {
151148
return fmt.Errorf("failed to start plugin %s: %v", name, err)
152149
}
153150

154-
// TODO: Determine if the old version should be removed
151+
// TODO: Determine if the old extract should be removed
155152

156153
return nil
157154
}

ui/src/components/PluginConfigureDialog.tsx

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PluginStatus } from "@/hooks/stores";
1+
import { PluginStatus, usePluginStore } from "@/hooks/stores";
22
import Modal from "@components/Modal";
33
import AutoHeight from "@components/AutoHeight";
44
import Card, { GridCard } from "@components/Card";
@@ -33,6 +33,8 @@ function Dialog({ plugin, setOpen }: { plugin: PluginStatus | null, setOpen: (op
3333
const [loading, setLoading] = useState(false);
3434
const [error, setError] = useState<string | null>(null);
3535

36+
const {setIsPluginUploadModalOpen} = usePluginStore();
37+
3638
useEffect(() => {
3739
setLoading(false);
3840
}, [plugin])
@@ -73,6 +75,11 @@ function Dialog({ plugin, setOpen }: { plugin: PluginStatus | null, setOpen: (op
7375
});
7476
}, [send, plugin, setOpen])
7577

78+
const uploadPlugin = useCallback(() => {
79+
setOpen(false);
80+
setIsPluginUploadModalOpen(true);
81+
}, [setIsPluginUploadModalOpen, setOpen])
82+
7683
return (
7784
<AutoHeight>
7885
<div className="mx-auto max-w-4xl px-4 transition-all duration-300 ease-in-out">
@@ -118,6 +125,30 @@ function Dialog({ plugin, setOpen }: { plugin: PluginStatus | null, setOpen: (op
118125
</div>
119126
</div>
120127

128+
<div className="grid grid-cols-[auto,1fr] gap-x-4 text-sm text-black dark:text-white">
129+
<span className="font-semibold">
130+
Name
131+
</span>
132+
<span>{plugin?.name}</span>
133+
134+
<span className="font-semibold">
135+
Active Version
136+
</span>
137+
<span>{plugin?.version}</span>
138+
139+
<span className="font-semibold">
140+
Description
141+
</span>
142+
<span>{plugin?.description}</span>
143+
144+
<span className="font-semibold">
145+
Homepage
146+
</span>
147+
<a href={plugin?.homepage} target="_blank" rel="noopener noreferrer" className="text-blue-600 hover:text-blue-800 dark:text-blue-500 dark:hover:text-blue-400">
148+
{plugin?.homepage}
149+
</a>
150+
</div>
151+
121152
<div className="h-[1px] w-full bg-slate-800/10 dark:bg-slate-300/20" />
122153

123154
<div
@@ -129,15 +160,15 @@ function Dialog({ plugin, setOpen }: { plugin: PluginStatus | null, setOpen: (op
129160
{error && <p className="text-red-500 dark:text-red-400">{error}</p>}
130161
{plugin?.message && (
131162
<>
132-
<p className="text-sm text-gray-500 dark:text-gray-400">
133-
Plugin message:
134-
</p>
135-
<Card className={cx(
136-
"text-gray-500 dark:text-gray-400 p-4 border",
137-
plugin.status === "error" && "border-red-200 bg-red-50 text-red-800 dark:text-red-400",
138-
)}>
139-
{plugin.message}
140-
</Card>
163+
<p className="text-sm text-gray-500 dark:text-gray-400">
164+
Plugin message:
165+
</p>
166+
<Card className={cx(
167+
"text-gray-500 dark:text-gray-400 p-4 border",
168+
plugin.status === "error" && "border-red-200 bg-red-50 text-red-800 dark:text-red-400",
169+
)}>
170+
{plugin.message}
171+
</Card>
141172
</>
142173
)}
143174
<p className="text-sm text-gray-500 dark:text-gray-400 py-10">
@@ -154,6 +185,13 @@ function Dialog({ plugin, setOpen }: { plugin: PluginStatus | null, setOpen: (op
154185
}}
155186
>
156187
<div className="flex items-center w-full space-x-2">
188+
<Button
189+
size="MD"
190+
theme="primary"
191+
text="Upload New Version"
192+
disabled={loading}
193+
onClick={uploadPlugin}
194+
/>
157195
<Button
158196
size="MD"
159197
theme="blank"

ui/src/components/PluginList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default function PluginList() {
6767
theme="light"
6868
text="Settings"
6969
onClick={() => {
70-
setConfiguringPlugin(plugin);
70+
setConfiguringPlugin(plugin.name);
7171
setPluginConfigureModalOpen(true);
7272
}}
7373
/>
@@ -85,7 +85,7 @@ export default function PluginList() {
8585
updatePlugins();
8686
}
8787
}}
88-
plugin={plugins.find(p => p.name == configuringPlugin?.name) ?? null}
88+
plugin={plugins.find(p => p.name == configuringPlugin) ?? null}
8989
/>
9090

9191
<div className="flex items-center gap-x-2">

ui/src/components/UploadPluginDialog.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ function Dialog({ setOpen }: { setOpen: (open: boolean) => void }) {
4545
setPluginUploadFilename,
4646
pluginUploadManifest,
4747
setPluginUploadManifest,
48+
setConfiguringPlugin,
49+
setPluginConfigureModalOpen,
4850
} = usePluginStore();
4951
const [send] = useJsonRpc();
5052
const [extractError, setExtractError] = useState<string | null>(null);
@@ -112,7 +114,12 @@ function Dialog({ setOpen }: { setOpen: (open: boolean) => void }) {
112114
onInstall={() => {
113115
setOpen(false)
114116
setPluginUploadFilename(null)
115-
// TODO: Open plugin settings dialog
117+
if (pluginUploadManifest) {
118+
setConfiguringPlugin(pluginUploadManifest.name)
119+
setPluginConfigureModalOpen(true)
120+
}
121+
setPluginUploadManifest(null)
122+
setPluginUploadModalView("upload")
116123
}}
117124
onBack={() => {
118125
setPluginUploadModalView("upload")

ui/src/hooks/stores.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,8 @@ interface PluginState {
584584
pluginConfigureModalOpen: boolean;
585585
setPluginConfigureModalOpen: (isOpen: boolean) => void;
586586

587-
configuringPlugin: PluginStatus | null;
588-
setConfiguringPlugin: (plugin: PluginStatus | null) => void;
587+
configuringPlugin: string | null;
588+
setConfiguringPlugin: (pluginName: string | null) => void;
589589
}
590590

591591
export const usePluginStore = create<PluginState>(set => ({

0 commit comments

Comments
 (0)