| 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 {readAtom, writeAtom} from 'isl/src/jotaiUtils'; |
| b69ab31 | | | 9 | import {registerDisposable} from 'isl/src/utils'; |
| b69ab31 | | | 10 | import {atom} from 'jotai'; |
| b69ab31 | | | 11 | import serverAPI from '../../isl/src/ClientToServerAPI'; |
| b69ab31 | | | 12 | |
| b69ab31 | | | 13 | /** Should match the sapling.comparisonPanelMode enum in package.json */ |
| b69ab31 | | | 14 | export enum ComparisonPanelMode { |
| b69ab31 | | | 15 | Auto = 'Auto', |
| b69ab31 | | | 16 | AlwaysOpenPanel = 'Always Separate Panel', |
| b69ab31 | | | 17 | } |
| b69ab31 | | | 18 | |
| b69ab31 | | | 19 | export const comparisonPanelMode = atom<undefined | ComparisonPanelMode>(ComparisonPanelMode.Auto); |
| b69ab31 | | | 20 | serverAPI.postMessage({ |
| b69ab31 | | | 21 | type: 'platform/subscribeToVSCodeConfig', |
| b69ab31 | | | 22 | config: 'sapling.comparisonPanelMode', |
| b69ab31 | | | 23 | }); |
| b69ab31 | | | 24 | registerDisposable( |
| b69ab31 | | | 25 | comparisonPanelMode, |
| b69ab31 | | | 26 | serverAPI.onMessageOfType('platform/vscodeConfigChanged', config => { |
| b69ab31 | | | 27 | if (config.config === 'sapling.comparisonPanelMode' && typeof config.value === 'string') { |
| b69ab31 | | | 28 | writeAtom(comparisonPanelMode, config.value as ComparisonPanelMode); |
| b69ab31 | | | 29 | } |
| b69ab31 | | | 30 | }), |
| b69ab31 | | | 31 | import.meta.hot, |
| b69ab31 | | | 32 | ); |
| b69ab31 | | | 33 | |
| b69ab31 | | | 34 | export const setComparisonPanelMode = (mode: ComparisonPanelMode) => { |
| b69ab31 | | | 35 | // Optimistically set the state locally, and later get rewritten to the same value by the server. |
| b69ab31 | | | 36 | // NOTE: This relies on the server responding to these events in-order to ensure eventual consistency. |
| b69ab31 | | | 37 | writeAtom(comparisonPanelMode, mode); |
| b69ab31 | | | 38 | serverAPI.postMessage({ |
| b69ab31 | | | 39 | type: 'platform/setVSCodeConfig', |
| b69ab31 | | | 40 | config: 'sapling.comparisonPanelMode', |
| b69ab31 | | | 41 | value: mode, |
| b69ab31 | | | 42 | scope: 'global', |
| b69ab31 | | | 43 | }); |
| b69ab31 | | | 44 | }; |
| b69ab31 | | | 45 | |
| b69ab31 | | | 46 | export const getComparisonPanelMode = () => { |
| b69ab31 | | | 47 | return readAtom(comparisonPanelMode) ?? 'Auto'; |
| b69ab31 | | | 48 | }; |