提交 f32ba85e 编写于 作者: B Benjamin Pasero

fix #57272

上级 5a4c9902
......@@ -14,13 +14,14 @@ import { Event as CommonEvent, Emitter } from 'vs/base/common/event';
import { isWindows, isMacintosh } from 'vs/base/common/platform';
import { IWorkspaceIdentifier, IWorkspacesMainService, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { IHistoryMainService, IRecentlyOpened, isRecentWorkspace, isRecentFolder, IRecent, isRecentFile, IRecentFolder, IRecentWorkspace, IRecentFile } from 'vs/platform/history/common/history';
import { RunOnceScheduler } from 'vs/base/common/async';
import { ThrottledDelayer } from 'vs/base/common/async';
import { isEqual as areResourcesEqual, dirname, originalFSPath } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { getSimpleWorkspaceLabel } from 'vs/platform/label/common/label';
import { toStoreData, restoreRecentlyOpened, RecentlyOpenedStorageData } from 'vs/platform/history/electron-main/historyStorage';
import { exists } from 'vs/base/node/pfs';
export class HistoryMainService implements IHistoryMainService {
......@@ -35,7 +36,7 @@ export class HistoryMainService implements IHistoryMainService {
private _onRecentlyOpenedChange = new Emitter<void>();
onRecentlyOpenedChange: CommonEvent<void> = this._onRecentlyOpenedChange.event;
private macOSRecentDocumentsUpdater: RunOnceScheduler;
private macOSRecentDocumentsUpdater: ThrottledDelayer<void>;
constructor(
@IStateService private readonly stateService: IStateService,
......@@ -43,7 +44,7 @@ export class HistoryMainService implements IHistoryMainService {
@IWorkspacesMainService private readonly workspacesMainService: IWorkspacesMainService,
@IEnvironmentService private readonly environmentService: IEnvironmentService
) {
this.macOSRecentDocumentsUpdater = new RunOnceScheduler(() => this.updateMacOSRecentDocuments(), 800);
this.macOSRecentDocumentsUpdater = new ThrottledDelayer<void>(800);
}
addRecentlyOpened(newlyAdded: IRecent[]): void {
......@@ -77,7 +78,7 @@ export class HistoryMainService implements IHistoryMainService {
// Schedule update to recent documents on macOS dock
if (isMacintosh) {
this.macOSRecentDocumentsUpdater.schedule();
this.macOSRecentDocumentsUpdater.trigger(() => this.updateMacOSRecentDocuments());
}
}
}
......@@ -103,12 +104,12 @@ export class HistoryMainService implements IHistoryMainService {
// Schedule update to recent documents on macOS dock
if (isMacintosh) {
this.macOSRecentDocumentsUpdater.schedule();
this.macOSRecentDocumentsUpdater.trigger(() => this.updateMacOSRecentDocuments());
}
}
}
private updateMacOSRecentDocuments(): void {
private async updateMacOSRecentDocuments(): Promise<void> {
if (!isMacintosh) {
return;
}
......@@ -125,8 +126,11 @@ export class HistoryMainService implements IHistoryMainService {
for (let i = 0, entries = 0; i < mru.workspaces.length && entries < HistoryMainService.MAX_MACOS_DOCK_RECENT_FOLDERS; i++) {
const loc = location(mru.workspaces[i]);
if (loc.scheme === Schemas.file) {
app.addRecentDocument(originalFSPath(loc));
entries++;
const workspacePath = originalFSPath(loc);
if (await exists(workspacePath)) {
app.addRecentDocument(workspacePath);
entries++;
}
}
}
......@@ -134,8 +138,11 @@ export class HistoryMainService implements IHistoryMainService {
for (let i = 0, entries = 0; i < mru.files.length && entries < HistoryMainService.MAX_MACOS_DOCK_RECENT_FILES; i++) {
const loc = location(mru.files[i]);
if (loc.scheme === Schemas.file) {
app.addRecentDocument(originalFSPath(loc));
entries++;
const filePath = originalFSPath(loc);
if (await exists(filePath)) {
app.addRecentDocument(filePath);
entries++;
}
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册