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