| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import type {Platform} from '../platform'; |
| 9 | import type {ThemeColor} from '../theme'; |
| 10 | import type {OneIndexedLineNumber, RepoRelativePath} from '../types'; |
| 11 | |
| 12 | import {makeBrowserLikePlatformImpl} from './browserPlatformImpl'; |
| 13 | |
| 14 | declare global { |
| 15 | interface Window { |
| 16 | __IdeBridge: { |
| 17 | openFileInAndroidStudio: (path: string, line?: number, col?: number) => void; |
| 18 | clipboardCopy?: (data: string) => void; |
| 19 | getIDETheme(): ThemeColor; |
| 20 | }; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | // important: this file should not try to import other code from 'isl', |
| 25 | // since it will end up getting duplicated when bundling. |
| 26 | |
| 27 | const androidStudioPlatform: Platform = { |
| 28 | ...makeBrowserLikePlatformImpl('androidStudio'), |
| 29 | |
| 30 | confirm: (message: string, details?: string) => { |
| 31 | // TODO: Android Studio-style confirm modal |
| 32 | const ok = window.confirm(message + '\n' + (details ?? '')); |
| 33 | return Promise.resolve(ok); |
| 34 | }, |
| 35 | |
| 36 | openFile: (_path: RepoRelativePath, _options?: {line?: OneIndexedLineNumber}) => { |
| 37 | window.__IdeBridge.openFileInAndroidStudio(_path, _options?.line); |
| 38 | }, |
| 39 | openFiles: (paths: Array<RepoRelativePath>, _options?: {line?: OneIndexedLineNumber}) => { |
| 40 | for (const path of paths) { |
| 41 | window.__IdeBridge.openFileInAndroidStudio(path, _options?.line); |
| 42 | } |
| 43 | }, |
| 44 | canCustomizeFileOpener: false, |
| 45 | upsellExternalMergeTool: false, |
| 46 | |
| 47 | openExternalLink(_url: string): void { |
| 48 | window.open(_url, '_blank'); |
| 49 | }, |
| 50 | |
| 51 | clipboardCopy(text: string, _html?: string) { |
| 52 | window.__IdeBridge.clipboardCopy?.(text); |
| 53 | }, |
| 54 | |
| 55 | theme: { |
| 56 | getTheme(): ThemeColor { |
| 57 | return 'dark'; // default to dark, IDE will adjust the theme if necessary |
| 58 | }, |
| 59 | onDidChangeTheme(callback: (theme: ThemeColor) => unknown) { |
| 60 | const updateTheme = (data: CustomEvent<ThemeColor>) => { |
| 61 | callback(data.detail); |
| 62 | }; |
| 63 | |
| 64 | window.addEventListener('onIDEThemeChange', updateTheme as EventListener, false); |
| 65 | |
| 66 | return { |
| 67 | dispose: () => { |
| 68 | window.removeEventListener('onIDEThemeChange', updateTheme as EventListener, false); |
| 69 | }, |
| 70 | }; |
| 71 | }, |
| 72 | }, |
| 73 | }; |
| 74 | |
| 75 | window.islPlatform = androidStudioPlatform; |
| 76 | |
| 77 | // Load the actual app entry, which must be done after the platform has been set up. |
| 78 | import('../index'); |
| 79 | |