mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-01 11:33:41 +03:00
webterm: fix broken imports
This commit is contained in:
parent
3b3564cae9
commit
3fa572b53a
8
pkg/interface/webterm/api.ts
Normal file
8
pkg/interface/webterm/api.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import Urbit from '@urbit/http-api';
|
||||||
|
const api = new Urbit('', '', (window as any).desk);
|
||||||
|
api.ship = window.ship;
|
||||||
|
// api.verbose = true;
|
||||||
|
// @ts-ignore TODO window typings
|
||||||
|
window.api = api;
|
||||||
|
|
||||||
|
export default api;
|
24
pkg/interface/webterm/join.ts
Normal file
24
pkg/interface/webterm/join.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useTheme } from './settings';
|
||||||
|
import useTermState from './state';
|
||||||
|
|
||||||
|
export function useDark() {
|
||||||
|
const [osDark, setOsDark] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const themeWatcher = window.matchMedia('(prefers-color-scheme: dark)');
|
||||||
|
const update = (e: MediaQueryListEvent) => {
|
||||||
|
setOsDark(e.matches);
|
||||||
|
};
|
||||||
|
setOsDark(themeWatcher.matches);
|
||||||
|
themeWatcher.addListener(update);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
themeWatcher.removeListener(update);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const theme = useTermState(s => s.theme);
|
||||||
|
return theme === 'dark' || (osDark && theme === 'auto');
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
import { Terminal } from 'xterm';
|
import { Terminal } from 'xterm';
|
||||||
import { FitAddon } from 'xterm-addon-fit';
|
import { FitAddon } from 'xterm-addon-fit';
|
||||||
|
import create from 'zustand';
|
||||||
|
import produce from 'immer';
|
||||||
|
|
||||||
import { createState } from "../src/logic/state/base";
|
|
||||||
|
|
||||||
type Session = { term: Terminal, fit: FitAddon };
|
type Session = { term: Terminal, fit: FitAddon };
|
||||||
type Sessions = { [id: string]: Session; }
|
type Sessions = { [id: string]: Session; }
|
||||||
@ -10,12 +11,17 @@ export interface TermState {
|
|||||||
sessions: Sessions,
|
sessions: Sessions,
|
||||||
selected: string,
|
selected: string,
|
||||||
slogstream: null | EventSource,
|
slogstream: null | EventSource,
|
||||||
|
theme: 'auto' | 'light' | 'dark'
|
||||||
};
|
};
|
||||||
|
|
||||||
const useTermState = createState<TermState>('Term', {
|
const useTermState = create<TermState>((set, get) => ({
|
||||||
sessions: {},
|
sessions: {} as Sessions,
|
||||||
selected: '', // empty string is default session
|
selected: '', // empty string is default session
|
||||||
slogstream: null,
|
slogstream: null,
|
||||||
}, ['sessions', 'slogstream']); //TODO consider persisting
|
theme: 'auto',
|
||||||
|
set: (f: (draft: TermState) => void) => {
|
||||||
|
set(produce(f));
|
||||||
|
}
|
||||||
|
} as TermState))
|
||||||
|
|
||||||
export default useTermState;
|
export default useTermState;
|
||||||
|
Loading…
Reference in New Issue
Block a user