Skip to content

Commit

Permalink
Revert "chore: run some task when Idle"
Browse files Browse the repository at this point in the history
This reverts commit 6a9a686.
  • Loading branch information
Aaaaash committed Oct 11, 2022
1 parent ff0b39a commit fd9f031
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 44 deletions.
8 changes: 3 additions & 5 deletions packages/core-browser/src/services/storage-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Autowired, Injectable, Optional } from '@opensumi/di';
import { isObject, isUndefinedOrNull, runWhenIdle } from '@opensumi/ide-core-common';
import { isObject, isUndefinedOrNull } from '@opensumi/ide-core-common';

import { Logger } from '../logger';

Expand Down Expand Up @@ -63,10 +63,8 @@ abstract class BaseBrowserStorageService implements StorageService {

private init() {
if (typeof window !== 'undefined' && window.localStorage) {
runWhenIdle(() => {
this.clearLocalStorage();
this.testLocalStorage();
});
this.clearLocalStorage();
this.testLocalStorage();
} else {
this.logger.warn("The browser doesn't support localStorage. state will not be persisted across sessions.");
}
Expand Down
23 changes: 9 additions & 14 deletions packages/editor/src/browser/editor.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
IEventBus,
MaybeNull,
PreferenceService,
runWhenIdle,
URI,
useDisposable,
View,
Expand Down Expand Up @@ -336,28 +335,24 @@ export const EditorGroupBody = observer(({ group }: { group: EditorGroup }) => {
cachedEditor[group.name].remove();
codeEditorRef.current.appendChild(cachedEditor[group.name]);
} else {
runWhenIdle(() => {
const container = document.createElement('div');
codeEditorRef.current!.appendChild(container);
cachedEditor[group.name] = container;
group.createEditor(container);
}, 1);
const container = document.createElement('div');
codeEditorRef.current.appendChild(container);
cachedEditor[group.name] = container;
group.createEditor(container);
}
}
if (diffEditorRef.current) {
if (cachedDiffEditor[group.name]) {
cachedDiffEditor[group.name].remove();
diffEditorRef.current.appendChild(cachedDiffEditor[group.name]);
} else {
runWhenIdle(() => {
const container = document.createElement('div');
diffEditorRef.current!.appendChild(container);
cachedDiffEditor[group.name] = container;
group.createDiffEditor(container);
}, 1);
const container = document.createElement('div');
diffEditorRef.current.appendChild(container);
cachedDiffEditor[group.name] = container;
group.createDiffEditor(container);
}
}
}, [codeEditorRef, diffEditorRef]);
}, [codeEditorRef.current]);

useDisposable(
() =>
Expand Down
7 changes: 2 additions & 5 deletions packages/keymaps/src/browser/keymaps.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
Deferred,
Throttler,
Schemes,
runWhenIdle,
} from '@opensumi/ide-core-browser';
import { IProgressService } from '@opensumi/ide-core-browser/lib/progress';
import { IFileServiceClient } from '@opensumi/ide-file-service';
Expand Down Expand Up @@ -292,11 +291,9 @@ export class KeymapService implements IKeymapService {
if (this.currentSearchValue) {
this.doSearchKeybindings(this.currentSearchValue);
} else {
runWhenIdle(() => {
this.keybindings = this.getKeybindingItems();
this.keymapChangeEmitter.fire(this.keybindings);
});
this.keybindings = this.getKeybindingItems();
}
this.keymapChangeEmitter.fire(this.keybindings);
}

/**
Expand Down
10 changes: 3 additions & 7 deletions packages/output/src/browser/output.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { observable, action } from 'mobx';

import { Injectable, Autowired } from '@opensumi/di';
import { AppConfig, PreferenceService } from '@opensumi/ide-core-browser';
import { Deferred, WithEventBus } from '@opensumi/ide-core-common';
import { WithEventBus } from '@opensumi/ide-core-common';
import {
IEditorDocumentModelService,
EditorCollectionService,
Expand Down Expand Up @@ -38,8 +38,6 @@ export class OutputService extends WithEventBus {
@observable
public keys: string = '' + Math.random();

private editorReady: Deferred<void> = new Deferred();

private monacoDispose: monaco.IDisposable;

private autoReveal = true;
Expand All @@ -65,14 +63,14 @@ export class OutputService extends WithEventBus {
this.monacoDispose.dispose();
}
this.selectedChannel = channel;
Promise.all([this.editorReady.promise, this.selectedChannel.modelReady.promise]).then(() => {
this.selectedChannel.modelReady.promise.then(() => {
const model = this.selectedChannel.outputModel.instance.getMonacoModel();
this.outputEditor?.open(this.selectedChannel.outputModel);
if (this.enableSmartScroll) {
this.outputEditor?.monacoEditor.revealLine(model.getLineCount());
this.autoReveal = true;
}
this.outputEditor?.layout();

this.monacoDispose = model.onDidChangeContent(() => {
if (this.autoReveal && this.enableSmartScroll) {
this.outputEditor?.monacoEditor.revealLine(model.getLineCount(), 0);
Expand Down Expand Up @@ -125,8 +123,6 @@ export class OutputService extends WithEventBus {
},
});

this.editorReady.resolve();

this.addDispose(
this.outputEditor.monacoEditor.onMouseUp((e) => {
/**
Expand Down
15 changes: 2 additions & 13 deletions packages/output/src/browser/output.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import { useEffect, createRef } from 'react';

import { Select, Option } from '@opensumi/ide-components';
import { useInjectable, isElectronRenderer, ViewState } from '@opensumi/ide-core-browser';
import { OUTPUT_CONTAINER_ID } from '@opensumi/ide-core-browser/lib/common/container-id';
import { Select as NativeSelect } from '@opensumi/ide-core-browser/lib/components/select';
import { IMainLayoutService } from '@opensumi/ide-main-layout';

import styles from './output.module.less';
import { OutputService } from './output.service';

export const Output = observer(({ viewState }: { viewState: ViewState }) => {
const outputService = useInjectable<OutputService>(OutputService);
const layoutService: IMainLayoutService = useInjectable(IMainLayoutService);
const outputRef = createRef<HTMLDivElement>();

useEffect(() => {
Expand All @@ -22,17 +19,9 @@ export const Output = observer(({ viewState }: { viewState: ViewState }) => {

useEffect(() => {
if (outputRef.current) {
const handler = layoutService.getTabbarHandler(OUTPUT_CONTAINER_ID);
if (handler?.isActivated()) {
outputService.initOutputMonacoInstance(outputRef.current);
} else {
const dispose = handler?.onActivate(() => {
outputService.initOutputMonacoInstance(outputRef.current!);
dispose?.dispose();
});
}
outputService.initOutputMonacoInstance(outputRef.current);
}
}, [outputRef]);
}, []);

return (
<React.Fragment>
Expand Down

0 comments on commit fd9f031

Please sign in to comment.