|
| 1 | +import React from '@theia/core/shared/react'; |
| 2 | +import { inject, injectable } from '@theia/core/shared/inversify'; |
| 3 | +import { Message } from '@theia/core/shared/@phosphor/messaging'; |
| 4 | +import { ReactDialog } from '../theia/dialogs/dialogs'; |
| 5 | +import { nls } from '@theia/core'; |
| 6 | +import { DialogProps } from '@theia/core/lib/browser'; |
| 7 | +import { WindowService } from '@theia/core/lib/browser/window/window-service'; |
| 8 | +import { AppService } from '../app-service'; |
| 9 | + |
| 10 | +@injectable() |
| 11 | +export class VersionWelcomeDialogProps extends DialogProps {} |
| 12 | + |
| 13 | +@injectable() |
| 14 | +export class VersionWelcomeDialog extends ReactDialog<void> { |
| 15 | + // @inject(LocalStorageService) |
| 16 | + // private readonly localStorageService: LocalStorageService; |
| 17 | + |
| 18 | + @inject(AppService) |
| 19 | + private readonly appService: AppService; |
| 20 | + |
| 21 | + @inject(WindowService) |
| 22 | + private readonly windowService: WindowService; |
| 23 | + |
| 24 | + constructor( |
| 25 | + @inject(VersionWelcomeDialogProps) |
| 26 | + protected override readonly props: VersionWelcomeDialogProps |
| 27 | + ) { |
| 28 | + super({ |
| 29 | + title: nls.localize( |
| 30 | + 'arduino/versionWelcome/versionWelcomeDialog', |
| 31 | + 'Welcome to the new Arduino IDE!' |
| 32 | + ), |
| 33 | + }); |
| 34 | + |
| 35 | + this.node.id = 'version-welcome-dialog-container'; |
| 36 | + this.contentNode.classList.add('version-welcome-dialog'); |
| 37 | + } |
| 38 | + |
| 39 | + protected render(): React.ReactNode { |
| 40 | + return ( |
| 41 | + <div> |
| 42 | + <p> |
| 43 | + {nls.localize( |
| 44 | + 'arduino/versionWelcome/donateMessage', |
| 45 | + 'Arduino is committed to keeping software free and open-source for everyone. Your donation helps us develop new features, improve libraries, and support millions of users worldwide.' |
| 46 | + )} |
| 47 | + </p> |
| 48 | + <p className="bold"> |
| 49 | + {nls.localize( |
| 50 | + 'arduino/versionWelcome/donateMessage2', |
| 51 | + 'Please consider supporting our efforts to keep Arduino IDE free.' |
| 52 | + )} |
| 53 | + </p> |
| 54 | + </div> |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + override get value(): void { |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | + private appendButtons(): void { |
| 63 | + const cancelButton = this.createButton( |
| 64 | + nls.localize('arduino/versionWelcome/cancelButton', 'Maybe later') |
| 65 | + ); |
| 66 | + cancelButton.classList.add('secondary'); |
| 67 | + cancelButton.classList.add('cancel-button'); |
| 68 | + this.addAction(cancelButton, this.close.bind(this), 'click'); |
| 69 | + this.controlPanel.appendChild(cancelButton); |
| 70 | + |
| 71 | + const donateButton = this.createButton( |
| 72 | + nls.localize('arduino/versionWelcome/donateButton', 'Donate now') |
| 73 | + ); |
| 74 | + this.addAction(donateButton, this.openDonationPage.bind(this), 'click'); |
| 75 | + this.controlPanel.appendChild(donateButton); |
| 76 | + donateButton.focus(); |
| 77 | + } |
| 78 | + |
| 79 | + private readonly openDonationPage = () => { |
| 80 | + const url = 'https://www.arduino.cc/en/donate'; |
| 81 | + this.windowService.openNewWindow(url, { external: true }); |
| 82 | + }; |
| 83 | + |
| 84 | + // FIXME: AppInfo is not available in the browser? |
| 85 | + private async updateTitleVersion(): Promise<void> { |
| 86 | + const appInfo = await this.appService.info(); |
| 87 | + const { appVersion } = appInfo; |
| 88 | + const title = nls.localize( |
| 89 | + 'arduino/versionWelcome/versionWelcomeDialog', |
| 90 | + `Welcome to the new Arduino IDE ${appVersion}!`, |
| 91 | + appVersion |
| 92 | + ); |
| 93 | + this.titleNode.innerHTML = title; |
| 94 | + } |
| 95 | + |
| 96 | + protected override onAfterAttach(msg: Message): void { |
| 97 | + this.update(); |
| 98 | + this.appendButtons(); |
| 99 | + this.updateTitleVersion(); |
| 100 | + super.onAfterAttach(msg); |
| 101 | + } |
| 102 | +} |
0 commit comments