|
| 1 | +import { Millennium, IconsModule, definePlugin, Field, DialogButton, callable } from '@steambrew/client'; |
| 2 | + |
| 3 | +class classname { |
| 4 | + static method(country: string, age: number) { |
| 5 | + console.log(`age: ${age}, country: ${country}`); |
| 6 | + return 'method called'; |
| 7 | + } |
| 8 | +} |
| 9 | + |
| 10 | +// export classname class to global context |
| 11 | +Millennium.exposeObj({ classname }); |
| 12 | + |
| 13 | +function windowCreated(context: any) { |
| 14 | + // window create event. |
| 15 | + // you can interact directly with the document and monitor it with dom observers |
| 16 | + // you can then render components in specific pages. |
| 17 | + console.log(context); |
| 18 | +} |
| 19 | + |
| 20 | +// Declare a function that exists on the backend |
| 21 | +const backendMethod = callable<[{ message: string; status: boolean; count: number }], boolean>('test_frontend_message_callback'); |
| 22 | + |
| 23 | +const SettingsContent = () => { |
| 24 | + return ( |
| 25 | + <Field label="Plugin Settings" description="This is a description of the plugin settings." icon={<IconsModule.Settings />} bottomSeparator="standard" focusable> |
| 26 | + <DialogButton |
| 27 | + onClick={() => { |
| 28 | + console.log('Button clicked!'); |
| 29 | + }} |
| 30 | + > |
| 31 | + Click Me |
| 32 | + </DialogButton> |
| 33 | + </Field> |
| 34 | + ); |
| 35 | +}; |
| 36 | + |
| 37 | +export default definePlugin(() => { |
| 38 | + // Call the backend method |
| 39 | + backendMethod({ |
| 40 | + message: 'Hello World From Frontend!', |
| 41 | + status: true, |
| 42 | + count: 69, |
| 43 | + }).then((message: any) => { |
| 44 | + console.log('Result from backendMethod:', message); |
| 45 | + }); |
| 46 | + |
| 47 | + Millennium.AddWindowCreateHook(windowCreated); |
| 48 | + |
| 49 | + return { |
| 50 | + title: 'My Plugin', |
| 51 | + icon: <IconsModule.Settings />, |
| 52 | + content: <SettingsContent />, |
| 53 | + }; |
| 54 | +}); |
0 commit comments