-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked client persistance retrieval
- Loading branch information
1 parent
9ceb420
commit 7d4cb60
Showing
5 changed files
with
67 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,66 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
|
||
// Used for opening the manifest file of the newly created project | ||
export namespace OpenManifestOnInit { | ||
export const KEY = "OpenManifestOnInit"; | ||
|
||
export class Memento { | ||
public workspaceUri: vscode.Uri; | ||
public manifestUri: vscode.Uri; | ||
|
||
constructor(workspaceUri: vscode.Uri, manifestUri: vscode.Uri) { | ||
this.workspaceUri = workspaceUri; | ||
this.manifestUri = manifestUri; | ||
} | ||
|
||
public async store(context: vscode.ExtensionContext) { | ||
const dto: MementoDto = { | ||
workspaceUriStr: this.workspaceUri.toString(), | ||
manifestUriStr: this.manifestUri.toString(), | ||
}; | ||
export function getPersistence(ctx: vscode.ExtensionContext): Persistence { | ||
return new Persistence(ctx) | ||
} | ||
|
||
await context.globalState.update(KEY, dto); | ||
} | ||
export class Persistence { | ||
constructor( | ||
readonly ctx: vscode.ExtensionContext | ||
) {} | ||
|
||
public static fetch(context: vscode.ExtensionContext): Memento | undefined { | ||
const dto = context.globalState.get<MementoDto>(KEY); | ||
if (dto) { | ||
const memento = new Memento( | ||
vscode.Uri.parse(dto.workspaceUriStr), | ||
vscode.Uri.parse(dto.manifestUriStr), | ||
); | ||
|
||
return memento; | ||
} else { | ||
return undefined; | ||
// Used for opening the manifest file of the newly created project | ||
get openManifestOnInit(): OpenManifestOnInit | undefined { | ||
const dto = this.ctx.globalState.get<OpenManifestOnInitDto>("OpenManifestOnInit"); | ||
if (dto) { | ||
return { | ||
workspaceUri: vscode.Uri.parse(dto.workspaceUriStr), | ||
manifestUri: vscode.Uri.parse(dto.manifestUriStr), | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
} | ||
|
||
public static erase(context: vscode.ExtensionContext) { | ||
context.globalState.update(KEY, undefined); | ||
set openManifestOnInit(value: OpenManifestOnInit | undefined) { | ||
let dto: OpenManifestOnInitDto | undefined = undefined; | ||
if (value) { | ||
dto = { | ||
workspaceUriStr: value.workspaceUri.toString(), | ||
manifestUriStr: value.manifestUri.toString(), | ||
} | ||
} | ||
} | ||
|
||
interface MementoDto { | ||
workspaceUriStr: string, | ||
manifestUriStr: string | ||
this.ctx.globalState.update("OpenManifestOnInit", dto); | ||
} | ||
} | ||
|
||
export namespace RememberedChoices { | ||
export const KEY = "RememberedChoices"; | ||
|
||
export class Memento { | ||
public neverShowAgainDebugAstNotif: boolean; | ||
public neverShowAgainForeignScriptWarning: boolean; | ||
|
||
constructor(dto: MementoDto) { | ||
this.neverShowAgainDebugAstNotif = dto.neverShowAgainDebugAstNotif; | ||
this.neverShowAgainForeignScriptWarning = dto.neverShowAgainForeignScriptWarning; | ||
} | ||
|
||
public async store(context: vscode.ExtensionContext) { | ||
const dto: MementoDto = { | ||
neverShowAgainDebugAstNotif: this.neverShowAgainDebugAstNotif, | ||
neverShowAgainForeignScriptWarning: this.neverShowAgainForeignScriptWarning | ||
}; | ||
get neverShowAgainDebugAstNotif(): boolean { | ||
return this.ctx.globalState.get<boolean>("NeverShowAgainDebugAstNotif") ?? false; | ||
} | ||
|
||
context.globalState.update(KEY, dto); | ||
} | ||
set neverShowAgainDebugAstNotif(value: boolean) { | ||
this.ctx.globalState.update("NeverShowAgainDebugAstNotif", value) | ||
} | ||
|
||
public static fetchOrDefault(context: vscode.ExtensionContext): Memento { | ||
const dto = context.globalState.get<MementoDto>(KEY); | ||
|
||
if (dto) { | ||
return new Memento(dto); | ||
} else { | ||
return new Memento({ | ||
neverShowAgainDebugAstNotif: false, | ||
neverShowAgainForeignScriptWarning: false | ||
}) | ||
} | ||
} | ||
get neverShowAgainForeignScriptWarning(): boolean { | ||
return this.ctx.globalState.get<boolean>("NeverShowAgainForeignScriptWarning") ?? false; | ||
} | ||
|
||
interface MementoDto { | ||
neverShowAgainDebugAstNotif: boolean; | ||
neverShowAgainForeignScriptWarning: boolean; | ||
set neverShowAgainForeignScriptWarning(value: boolean) { | ||
this.ctx.globalState.update("NeverShowAgainForeignScriptWarning", value) | ||
} | ||
} | ||
} | ||
|
||
export interface OpenManifestOnInit { | ||
workspaceUri: vscode.Uri, | ||
manifestUri: vscode.Uri | ||
} | ||
|
||
interface OpenManifestOnInitDto { | ||
workspaceUriStr: string, | ||
manifestUriStr: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters