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