Refactor types in svelte components.

This commit is contained in:
vorotamoroz
2026-06-01 11:18:23 +01:00
parent c6697327d5
commit cd2bff5fc7
19 changed files with 268 additions and 170 deletions
+23 -13
View File
@@ -1,12 +1,16 @@
import { import {
type BucketSyncSetting,
type CouchDBConnection,
type EncryptionSettings,
type ObsidianLiveSyncSettings, type ObsidianLiveSyncSettings,
type P2PSyncSetting,
DEFAULT_SETTINGS, DEFAULT_SETTINGS,
LOG_LEVEL_NOTICE, LOG_LEVEL_NOTICE,
LOG_LEVEL_VERBOSE, LOG_LEVEL_VERBOSE,
REMOTE_COUCHDB, REMOTE_COUCHDB,
REMOTE_MINIO, REMOTE_MINIO,
REMOTE_P2P, REMOTE_P2P,
} from "../../lib/src/common/types.ts"; } from "@lib/common/types.ts";
import { isObjectDifferent } from "@lib/common/utils.ts"; import { isObjectDifferent } from "@lib/common/utils.ts";
import Intro from "./SetupWizard/dialogs/Intro.svelte"; import Intro from "./SetupWizard/dialogs/Intro.svelte";
import SelectMethodNewUser from "./SetupWizard/dialogs/SelectMethodNewUser.svelte"; import SelectMethodNewUser from "./SetupWizard/dialogs/SelectMethodNewUser.svelte";
@@ -21,9 +25,15 @@ import SetupRemoteCouchDB from "./SetupWizard/dialogs/SetupRemoteCouchDB.svelte"
import SetupRemoteBucket from "./SetupWizard/dialogs/SetupRemoteBucket.svelte"; import SetupRemoteBucket from "./SetupWizard/dialogs/SetupRemoteBucket.svelte";
import SetupRemoteP2P from "./SetupWizard/dialogs/SetupRemoteP2P.svelte"; import SetupRemoteP2P from "./SetupWizard/dialogs/SetupRemoteP2P.svelte";
import SetupRemoteE2EE from "./SetupWizard/dialogs/SetupRemoteE2EE.svelte"; import SetupRemoteE2EE from "./SetupWizard/dialogs/SetupRemoteE2EE.svelte";
import { decodeSettingsFromQRCodeData } from "../../lib/src/API/processSetting.ts"; import { decodeSettingsFromQRCodeData } from "@lib/API/processSetting.ts";
import { AbstractModule } from "../AbstractModule.ts"; import { AbstractModule } from "../AbstractModule.ts";
import { ConnectionStringParser } from "@lib/common/ConnectionString.ts"; import { ConnectionStringParser } from "@lib/common/ConnectionString.ts";
import type {
OutroAskUserModeResultType, OutroExistingUserResultType, OutroNewUserResultType,
ScanQRCodeResultType, SetupRemoteBucketResultType, SetupRemoteCouchDBResultType,
SetupRemoteE2EEResultType, SetupRemoteP2PResultType,
SetupRemoteResultType, UseSetupURIResultType
} from "./SetupWizard/dialogs/setupDialogTypes.ts";
/** /**
* User modes for onboarding and setup * User modes for onboarding and setup
@@ -118,7 +128,7 @@ export class SetupManager extends AbstractModule {
* @returns Promise that resolves to true if onboarding completed successfully, false otherwise * @returns Promise that resolves to true if onboarding completed successfully, false otherwise
*/ */
async onUseSetupURI(userMode: UserMode, setupURI: string = ""): Promise<boolean> { async onUseSetupURI(userMode: UserMode, setupURI: string = ""): Promise<boolean> {
const newSetting = await this.dialogManager.openWithExplicitCancel(UseSetupURI, setupURI); const newSetting = await this.dialogManager.openWithExplicitCancel<UseSetupURIResultType, string>(UseSetupURI, setupURI);
if (newSetting === "cancelled") { if (newSetting === "cancelled") {
this._log("Setup URI dialog cancelled.", LOG_LEVEL_NOTICE); this._log("Setup URI dialog cancelled.", LOG_LEVEL_NOTICE);
return false; return false;
@@ -141,7 +151,7 @@ export class SetupManager extends AbstractModule {
): Promise<boolean> { ): Promise<boolean> {
const originalSetting = JSON.parse(JSON.stringify(currentSetting)) as ObsidianLiveSyncSettings; const originalSetting = JSON.parse(JSON.stringify(currentSetting)) as ObsidianLiveSyncSettings;
const baseSetting = JSON.parse(JSON.stringify(originalSetting)) as ObsidianLiveSyncSettings; const baseSetting = JSON.parse(JSON.stringify(originalSetting)) as ObsidianLiveSyncSettings;
const couchConf = await this.dialogManager.openWithExplicitCancel(SetupRemoteCouchDB, originalSetting); const couchConf = await this.dialogManager.openWithExplicitCancel<SetupRemoteCouchDBResultType, CouchDBConnection>(SetupRemoteCouchDB, originalSetting);
if (couchConf === "cancelled") { if (couchConf === "cancelled") {
this._log("Manual configuration cancelled.", LOG_LEVEL_NOTICE); this._log("Manual configuration cancelled.", LOG_LEVEL_NOTICE);
return await this.onOnboard(userMode); return await this.onOnboard(userMode);
@@ -165,7 +175,7 @@ export class SetupManager extends AbstractModule {
currentSetting: ObsidianLiveSyncSettings, currentSetting: ObsidianLiveSyncSettings,
activate = true activate = true
): Promise<boolean> { ): Promise<boolean> {
const bucketConf = await this.dialogManager.openWithExplicitCancel(SetupRemoteBucket, currentSetting); const bucketConf = await this.dialogManager.openWithExplicitCancel<SetupRemoteBucketResultType, BucketSyncSetting>(SetupRemoteBucket, currentSetting);
if (bucketConf === "cancelled") { if (bucketConf === "cancelled") {
this._log("Manual configuration cancelled.", LOG_LEVEL_NOTICE); this._log("Manual configuration cancelled.", LOG_LEVEL_NOTICE);
return await this.onOnboard(userMode); return await this.onOnboard(userMode);
@@ -189,7 +199,7 @@ export class SetupManager extends AbstractModule {
currentSetting: ObsidianLiveSyncSettings, currentSetting: ObsidianLiveSyncSettings,
activate = true activate = true
): Promise<boolean> { ): Promise<boolean> {
const p2pConf = await this.dialogManager.openWithExplicitCancel(SetupRemoteP2P, currentSetting); const p2pConf = await this.dialogManager.openWithExplicitCancel<SetupRemoteP2PResultType, P2PSyncSetting>(SetupRemoteP2P, currentSetting);
if (p2pConf === "cancelled") { if (p2pConf === "cancelled") {
this._log("Manual configuration cancelled.", LOG_LEVEL_NOTICE); this._log("Manual configuration cancelled.", LOG_LEVEL_NOTICE);
return await this.onOnboard(userMode); return await this.onOnboard(userMode);
@@ -224,7 +234,7 @@ export class SetupManager extends AbstractModule {
* @returns * @returns
*/ */
async onlyE2EEConfiguration(userMode: UserMode, currentSetting: ObsidianLiveSyncSettings): Promise<boolean> { async onlyE2EEConfiguration(userMode: UserMode, currentSetting: ObsidianLiveSyncSettings): Promise<boolean> {
const e2eeConf = await this.dialogManager.openWithExplicitCancel(SetupRemoteE2EE, currentSetting); const e2eeConf = await this.dialogManager.openWithExplicitCancel<SetupRemoteE2EEResultType, EncryptionSettings>(SetupRemoteE2EE, currentSetting);
if (e2eeConf === "cancelled") { if (e2eeConf === "cancelled") {
this._log("E2EE configuration cancelled.", LOG_LEVEL_NOTICE); this._log("E2EE configuration cancelled.", LOG_LEVEL_NOTICE);
return false; return false;
@@ -243,7 +253,7 @@ export class SetupManager extends AbstractModule {
* @returns * @returns
*/ */
async onConfigureManually(originalSetting: ObsidianLiveSyncSettings, userMode: UserMode): Promise<boolean> { async onConfigureManually(originalSetting: ObsidianLiveSyncSettings, userMode: UserMode): Promise<boolean> {
const e2eeConf = await this.dialogManager.openWithExplicitCancel(SetupRemoteE2EE, originalSetting); const e2eeConf = await this.dialogManager.openWithExplicitCancel<SetupRemoteE2EEResultType, EncryptionSettings>(SetupRemoteE2EE, originalSetting);
if (e2eeConf === "cancelled") { if (e2eeConf === "cancelled") {
this._log("Manual configuration cancelled.", LOG_LEVEL_NOTICE); this._log("Manual configuration cancelled.", LOG_LEVEL_NOTICE);
return await this.onOnboard(userMode); return await this.onOnboard(userMode);
@@ -262,7 +272,7 @@ export class SetupManager extends AbstractModule {
* @returns * @returns
*/ */
async onSelectServer(currentSetting: ObsidianLiveSyncSettings, userMode: UserMode): Promise<boolean> { async onSelectServer(currentSetting: ObsidianLiveSyncSettings, userMode: UserMode): Promise<boolean> {
const method = await this.dialogManager.openWithExplicitCancel(SetupRemote); const method = await this.dialogManager.openWithExplicitCancel<SetupRemoteResultType>(SetupRemote);
if (method === "couchdb") { if (method === "couchdb") {
return await this.onCouchDBManualSetup(userMode, currentSetting, true); return await this.onCouchDBManualSetup(userMode, currentSetting, true);
} else if (method === "bucket") { } else if (method === "bucket") {
@@ -290,7 +300,7 @@ export class SetupManager extends AbstractModule {
newConf: ObsidianLiveSyncSettings, newConf: ObsidianLiveSyncSettings,
_userMode: UserMode, _userMode: UserMode,
activate: boolean = true, activate: boolean = true,
extra: () => void = () => {} extra: () => void = () => { }
): Promise<boolean> { ): Promise<boolean> {
newConf = await this.services.setting.adjustSettings({ newConf = await this.services.setting.adjustSettings({
...this.settings, ...this.settings,
@@ -321,7 +331,7 @@ export class SetupManager extends AbstractModule {
this._log("Settings from wizard applied.", LOG_LEVEL_NOTICE); this._log("Settings from wizard applied.", LOG_LEVEL_NOTICE);
return true; return true;
} else { } else {
const userModeResult = await this.dialogManager.openWithExplicitCancel(OutroAskUserMode); const userModeResult = await this.dialogManager.openWithExplicitCancel<OutroAskUserModeResultType>(OutroAskUserMode);
if (userModeResult === "new-user") { if (userModeResult === "new-user") {
userMode = UserMode.NewUser; userMode = UserMode.NewUser;
} else if (userModeResult === "existing-user") { } else if (userModeResult === "existing-user") {
@@ -338,7 +348,7 @@ export class SetupManager extends AbstractModule {
} }
} }
const component = userMode === UserMode.NewUser ? OutroNewUser : OutroExistingUser; const component = userMode === UserMode.NewUser ? OutroNewUser : OutroExistingUser;
const confirm = await this.dialogManager.openWithExplicitCancel(component); const confirm = await this.dialogManager.openWithExplicitCancel<OutroNewUserResultType | OutroExistingUserResultType>(component);
if (confirm === "cancelled") { if (confirm === "cancelled") {
this._log("User cancelled applying settings from wizard..", LOG_LEVEL_NOTICE); this._log("User cancelled applying settings from wizard..", LOG_LEVEL_NOTICE);
return false; return false;
@@ -364,7 +374,7 @@ export class SetupManager extends AbstractModule {
*/ */
async onPromptQRCodeInstruction(): Promise<boolean> { async onPromptQRCodeInstruction(): Promise<boolean> {
const qrResult = await this.dialogManager.open(ScanQRCode); const qrResult = await this.dialogManager.open<ScanQRCodeResultType>(ScanQRCode);
this._log("QR Code dialog closed.", LOG_LEVEL_VERBOSE); this._log("QR Code dialog closed.", LOG_LEVEL_VERBOSE);
// Result is not used, but log it for debugging. // Result is not used, but log it for debugging.
this._log(qrResult, LOG_LEVEL_VERBOSE); this._log(qrResult, LOG_LEVEL_VERBOSE);
@@ -1,47 +1,30 @@
<script lang="ts"> <script lang="ts">
import DialogHeader from "@/lib/src/UI/components/DialogHeader.svelte"; import DialogHeader from "@lib/UI/components/DialogHeader.svelte";
import Guidance from "@/lib/src/UI/components/Guidance.svelte"; import Guidance from "@lib/UI/components/Guidance.svelte";
import Decision from "@/lib/src/UI/components/Decision.svelte"; import Decision from "@lib/UI/components/Decision.svelte";
import Question from "@/lib/src/UI/components/Question.svelte"; import Question from "@lib/UI/components/Question.svelte";
import Option from "@/lib/src/UI/components/Option.svelte"; import Option from "@lib/UI/components/Option.svelte";
import Options from "@/lib/src/UI/components/Options.svelte"; import Options from "@lib/UI/components/Options.svelte";
import Instruction from "@/lib/src/UI/components/Instruction.svelte"; import Instruction from "@lib/UI/components/Instruction.svelte";
import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte"; import UserDecisions from "@lib/UI/components/UserDecisions.svelte";
import InfoNote from "@/lib/src/UI/components/InfoNote.svelte"; import InfoNote from "@lib/UI/components/InfoNote.svelte";
import ExtraItems from "@/lib/src/UI/components/ExtraItems.svelte"; import ExtraItems from "@lib/UI/components/ExtraItems.svelte";
import Check from "@/lib/src/UI/components/Check.svelte"; import Check from "@lib/UI/components/Check.svelte";
const TYPE_IDENTICAL = "identical"; import {
const TYPE_INDEPENDENT = "independent"; TYPE_BACKUP_DONE,
const TYPE_UNBALANCED = "unbalanced"; TYPE_BACKUP_SKIPPED,
const TYPE_CANCEL = "cancelled"; TYPE_CANCEL,
TYPE_IDENTICAL,
TYPE_INDEPENDENT,
TYPE_UNABLE_TO_BACKUP,
TYPE_UNBALANCED,
type FetchEverythingResult,
type ResultTypeBackup,
type ResultTypeVault,
} from "./setupDialogTypes";
const TYPE_BACKUP_DONE = "backup_done";
const TYPE_BACKUP_SKIPPED = "backup_skipped";
const TYPE_UNABLE_TO_BACKUP = "unable_to_backup";
type ResultTypeVault =
| typeof TYPE_IDENTICAL
| typeof TYPE_INDEPENDENT
| typeof TYPE_UNBALANCED
| typeof TYPE_CANCEL;
type ResultTypeBackup =
| typeof TYPE_BACKUP_DONE
| typeof TYPE_BACKUP_SKIPPED
| typeof TYPE_UNABLE_TO_BACKUP
| typeof TYPE_CANCEL;
type ResultTypeExtra = {
preventFetchingConfig: boolean;
};
type ResultType =
| {
vault: ResultTypeVault;
backup: ResultTypeBackup;
extra: ResultTypeExtra;
}
| typeof TYPE_CANCEL;
type Props = { type Props = {
setResult: (result: ResultType) => void; setResult: (result: FetchEverythingResult) => void;
}; };
const { setResult }: Props = $props(); const { setResult }: Props = $props();
let vaultType = $state<ResultTypeVault>(TYPE_CANCEL); let vaultType = $state<ResultTypeVault>(TYPE_CANCEL);
@@ -1,21 +1,19 @@
<script lang="ts"> <script lang="ts">
import DialogHeader from "@/lib/src/UI/components/DialogHeader.svelte"; import DialogHeader from "@lib/UI/components/DialogHeader.svelte";
import Guidance from "@/lib/src/UI/components/Guidance.svelte"; import Guidance from "@lib/UI/components/Guidance.svelte";
import Decision from "@/lib/src/UI/components/Decision.svelte"; import Decision from "@lib/UI/components/Decision.svelte";
import Question from "@/lib/src/UI/components/Question.svelte"; import Question from "@lib/UI/components/Question.svelte";
import Option from "@/lib/src/UI/components/Option.svelte"; import Option from "@lib/UI/components/Option.svelte";
import Options from "@/lib/src/UI/components/Options.svelte"; import Options from "@lib/UI/components/Options.svelte";
import Instruction from "@/lib/src/UI/components/Instruction.svelte"; import Instruction from "@lib/UI/components/Instruction.svelte";
import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte"; import UserDecisions from "@lib/UI/components/UserDecisions.svelte";
const TYPE_NEW_USER = "new-user"; import { TYPE_NEW_USER, TYPE_EXISTING_USER, TYPE_CANCELLED, type IntroResultType } from "./setupDialogTypes";
const TYPE_EXISTING_USER = "existing-user";
const TYPE_CANCELLED = "cancelled";
type ResultType = typeof TYPE_NEW_USER | typeof TYPE_EXISTING_USER | typeof TYPE_CANCELLED;
type Props = { type Props = {
setResult: (result: ResultType) => void; setResult: (result: IntroResultType) => void;
}; };
const { setResult }: Props = $props(); const { setResult }: Props = $props();
let userType = $state<ResultType>(TYPE_CANCELLED); let userType = $state<IntroResultType>(TYPE_CANCELLED);
let proceedTitle = $derived.by(() => { let proceedTitle = $derived.by(() => {
if (userType === TYPE_NEW_USER) { if (userType === TYPE_NEW_USER) {
return "Yes, I want to set up a new synchronisation"; return "Yes, I want to set up a new synchronisation";
@@ -7,16 +7,19 @@
import Instruction from "@/lib/src/UI/components/Instruction.svelte"; import Instruction from "@/lib/src/UI/components/Instruction.svelte";
import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte"; import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte";
import InfoNote from "@/lib/src/UI/components/InfoNote.svelte"; import InfoNote from "@/lib/src/UI/components/InfoNote.svelte";
const TYPE_EXISTING = "existing-user"; import {
const TYPE_NEW = "new-user"; type OutroAskUserModeResultType,
const TYPE_COMPATIBLE_EXISTING = "compatible-existing-user"; TYPE_CANCELLED,
const TYPE_CANCELLED = "cancelled"; TYPE_EXISTING,
type ResultType = typeof TYPE_EXISTING | typeof TYPE_NEW | typeof TYPE_COMPATIBLE_EXISTING | typeof TYPE_CANCELLED; TYPE_NEW,
TYPE_COMPATIBLE_EXISTING,
} from "./setupDialogTypes";
type Props = { type Props = {
setResult: (result: ResultType) => void; setResult: (result: OutroAskUserModeResultType) => void;
}; };
const { setResult }: Props = $props(); const { setResult }: Props = $props();
let userType = $state<ResultType>(TYPE_CANCELLED); let userType = $state<OutroAskUserModeResultType>(TYPE_CANCELLED);
const canProceed = $derived.by(() => { const canProceed = $derived.by(() => {
return userType === TYPE_EXISTING || userType === TYPE_NEW || userType === TYPE_COMPATIBLE_EXISTING; return userType === TYPE_EXISTING || userType === TYPE_NEW || userType === TYPE_COMPATIBLE_EXISTING;
}); });
@@ -41,7 +44,11 @@
</Guidance> </Guidance>
<Instruction> <Instruction>
<Question>Please select your situation.</Question> <Question>Please select your situation.</Question>
<Option title="I am setting up a new server for the first time / I want to reset my existing server." bind:value={userType} selectedValue={TYPE_NEW}> <Option
title="I am setting up a new server for the first time / I want to reset my existing server."
bind:value={userType}
selectedValue={TYPE_NEW}
>
<InfoNote> <InfoNote>
Selecting this option will result in the current data on this device being used to initialise the server. Selecting this option will result in the current data on this device being used to initialise the server.
Any existing data on the server will be completely overwritten. Any existing data on the server will be completely overwritten.
@@ -1,15 +1,14 @@
<script lang="ts"> <script lang="ts">
import DialogHeader from "@/lib/src/UI/components/DialogHeader.svelte"; import DialogHeader from "@lib/UI/components/DialogHeader.svelte";
import Guidance from "@/lib/src/UI/components/Guidance.svelte"; import Guidance from "@lib/UI/components/Guidance.svelte";
import Decision from "@/lib/src/UI/components/Decision.svelte"; import Decision from "@lib/UI/components/Decision.svelte";
import Question from "@/lib/src/UI/components/Question.svelte"; import Question from "@lib/UI/components/Question.svelte";
import Instruction from "@/lib/src/UI/components/Instruction.svelte"; import Instruction from "@lib/UI/components/Instruction.svelte";
import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte"; import UserDecisions from "@lib/UI/components/UserDecisions.svelte";
const TYPE_APPLY = "apply";
const TYPE_CANCELLED = "cancelled"; import { TYPE_CANCELLED, TYPE_APPLY, type OutroExistingUserResultType } from "./setupDialogTypes";
type ResultType = typeof TYPE_APPLY | typeof TYPE_CANCELLED;
type Props = { type Props = {
setResult: (result: ResultType) => void; setResult: (result: OutroExistingUserResultType) => void;
}; };
const { setResult }: Props = $props(); const { setResult }: Props = $props();
</script> </script>
@@ -5,14 +5,13 @@
import Question from "@/lib/src/UI/components/Question.svelte"; import Question from "@/lib/src/UI/components/Question.svelte";
import Instruction from "@/lib/src/UI/components/Instruction.svelte"; import Instruction from "@/lib/src/UI/components/Instruction.svelte";
import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte"; import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte";
const TYPE_APPLY = "apply"; import { TYPE_APPLY, TYPE_CANCELLED, type OutroNewUserResultType } from "./setupDialogTypes";
const TYPE_CANCELLED = "cancelled";
type ResultType = typeof TYPE_APPLY | typeof TYPE_CANCELLED;
type Props = { type Props = {
setResult: (result: ResultType) => void; setResult: (result: OutroNewUserResultType) => void;
}; };
const { setResult }: Props = $props(); const { setResult }: Props = $props();
// let userType = $state<ResultType>(TYPE_CANCELLED); // let userType = $state<OutroNewUserResultType>(TYPE_CANCELLED);
</script> </script>
<DialogHeader title="Setup Complete: Preparing to Initialise Server" /> <DialogHeader title="Setup Complete: Preparing to Initialise Server" />
@@ -2,9 +2,9 @@
/** /**
* Panel to check and fix CouchDB configuration issues * Panel to check and fix CouchDB configuration issues
*/ */
import type { ObsidianLiveSyncSettings } from "../../../../lib/src/common/types"; import type { ObsidianLiveSyncSettings } from "@lib/common/types";
import Decision from "../../../../lib/src/UI/components/Decision.svelte"; import Decision from "@lib/UI/components/Decision.svelte";
import UserDecisions from "../../../../lib/src/UI/components/UserDecisions.svelte"; import UserDecisions from "@lib/UI/components/UserDecisions.svelte";
import { checkConfig, type ConfigCheckResult, type ResultError, type ResultErrorMessage } from "./utilCheckCouchDB"; import { checkConfig, type ConfigCheckResult, type ResultError, type ResultErrorMessage } from "./utilCheckCouchDB";
type Props = { type Props = {
trialRemoteSetting: ObsidianLiveSyncSettings; trialRemoteSetting: ObsidianLiveSyncSettings;
@@ -10,29 +10,17 @@
import InfoNote from "@/lib/src/UI/components/InfoNote.svelte"; import InfoNote from "@/lib/src/UI/components/InfoNote.svelte";
import ExtraItems from "@/lib/src/UI/components/ExtraItems.svelte"; import ExtraItems from "@/lib/src/UI/components/ExtraItems.svelte";
import Check from "@/lib/src/UI/components/Check.svelte"; import Check from "@/lib/src/UI/components/Check.svelte";
const TYPE_CANCEL = "cancelled"; import {
TYPE_CANCEL,
TYPE_BACKUP_DONE,
TYPE_BACKUP_SKIPPED,
TYPE_UNABLE_TO_BACKUP,
type RebuildEverythingResult,
type ResultTypeBackup,
} from "./setupDialogTypes";
const TYPE_BACKUP_DONE = "backup_done";
const TYPE_BACKUP_SKIPPED = "backup_skipped";
const TYPE_UNABLE_TO_BACKUP = "unable_to_backup";
type ResultTypeBackup =
| typeof TYPE_BACKUP_DONE
| typeof TYPE_BACKUP_SKIPPED
| typeof TYPE_UNABLE_TO_BACKUP
| typeof TYPE_CANCEL;
type ResultTypeExtra = {
preventFetchingConfig: boolean;
};
type ResultType =
| {
backup: ResultTypeBackup;
extra: ResultTypeExtra;
}
| typeof TYPE_CANCEL;
type Props = { type Props = {
setResult: (result: ResultType) => void; setResult: (result: RebuildEverythingResult) => void;
}; };
const { setResult }: Props = $props(); const { setResult }: Props = $props();
@@ -4,10 +4,10 @@
import Decision from "@/lib/src/UI/components/Decision.svelte"; import Decision from "@/lib/src/UI/components/Decision.svelte";
import Instruction from "@/lib/src/UI/components/Instruction.svelte"; import Instruction from "@/lib/src/UI/components/Instruction.svelte";
import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte"; import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte";
const TYPE_CLOSE = "close"; import { TYPE_CLOSE, type ScanQRCodeResultType } from "./setupDialogTypes";
type ResultType = typeof TYPE_CLOSE;
type Props = { type Props = {
setResult: (_result: ResultType) => void; setResult: (_result: ScanQRCodeResultType) => void;
}; };
const { setResult }: Props = $props(); const { setResult }: Props = $props();
</script> </script>
@@ -7,16 +7,19 @@
import Options from "@/lib/src/UI/components/Options.svelte"; import Options from "@/lib/src/UI/components/Options.svelte";
import Instruction from "@/lib/src/UI/components/Instruction.svelte"; import Instruction from "@/lib/src/UI/components/Instruction.svelte";
import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte"; import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte";
const TYPE_USE_SETUP_URI = "use-setup-uri"; import {
const TYPE_SCAN_QR_CODE = "scan-qr-code"; TYPE_USE_SETUP_URI,
const TYPE_CONFIGURE_MANUALLY = "configure-manually"; TYPE_SCAN_QR_CODE,
const TYPE_CANCELLED = "cancelled"; TYPE_CONFIGURE_MANUALLY,
type ResultType = typeof TYPE_USE_SETUP_URI | typeof TYPE_SCAN_QR_CODE | typeof TYPE_CONFIGURE_MANUALLY | typeof TYPE_CANCELLED; TYPE_CANCELLED,
type SelectMethodExistingResultType,
} from "./setupDialogTypes";
type Props = { type Props = {
setResult: (result: ResultType) => void; setResult: (result: SelectMethodExistingResultType) => void;
}; };
const { setResult }: Props = $props(); const { setResult }: Props = $props();
let userType = $state<ResultType>(TYPE_CANCELLED); let userType = $state<SelectMethodExistingResultType>(TYPE_CANCELLED);
let proceedTitle = $derived.by(() => { let proceedTitle = $derived.by(() => {
if (userType === TYPE_USE_SETUP_URI) { if (userType === TYPE_USE_SETUP_URI) {
return "Proceed with Setup URI"; return "Proceed with Setup URI";
@@ -7,15 +7,18 @@
import Options from "@/lib/src/UI/components/Options.svelte"; import Options from "@/lib/src/UI/components/Options.svelte";
import Instruction from "@/lib/src/UI/components/Instruction.svelte"; import Instruction from "@/lib/src/UI/components/Instruction.svelte";
import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte"; import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte";
const TYPE_USE_SETUP_URI = "use-setup-uri"; import {
const TYPE_CONFIGURE_MANUALLY = "configure-manually"; TYPE_USE_SETUP_URI,
const TYPE_CANCELLED = "cancelled"; TYPE_CONFIGURE_MANUALLY,
type ResultType = typeof TYPE_USE_SETUP_URI | typeof TYPE_CONFIGURE_MANUALLY | typeof TYPE_CANCELLED; TYPE_CANCELLED,
type SelectMethodNewUserResultType,
} from "./setupDialogTypes";
type Props = { type Props = {
setResult: (result: ResultType) => void; setResult: (result: SelectMethodNewUserResultType) => void;
}; };
const { setResult }: Props = $props(); const { setResult }: Props = $props();
let userType = $state<ResultType>(TYPE_CANCELLED); let userType = $state<SelectMethodNewUserResultType>(TYPE_CANCELLED);
let proceedTitle = $derived.by(() => { let proceedTitle = $derived.by(() => {
if (userType === TYPE_USE_SETUP_URI) { if (userType === TYPE_USE_SETUP_URI) {
return "Proceed with Setup URI"; return "Proceed with Setup URI";
@@ -6,16 +6,19 @@
import Options from "@/lib/src/UI/components/Options.svelte"; import Options from "@/lib/src/UI/components/Options.svelte";
import Instruction from "@/lib/src/UI/components/Instruction.svelte"; import Instruction from "@/lib/src/UI/components/Instruction.svelte";
import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte"; import UserDecisions from "@/lib/src/UI/components/UserDecisions.svelte";
const TYPE_COUCHDB = "couchdb"; import {
const TYPE_BUCKET = "bucket"; TYPE_COUCHDB,
const TYPE_P2P = "p2p"; TYPE_BUCKET,
const TYPE_CANCELLED = "cancelled"; TYPE_P2P,
type ResultType = typeof TYPE_COUCHDB | typeof TYPE_BUCKET | typeof TYPE_P2P | typeof TYPE_CANCELLED; TYPE_CANCELLED,
type SetupRemoteResultType,
} from "./setupDialogTypes";
type Props = { type Props = {
setResult: (result: ResultType) => void; setResult: (result: SetupRemoteResultType) => void;
}; };
const { setResult }: Props = $props(); const { setResult }: Props = $props();
let userType = $state<ResultType>(TYPE_CANCELLED); let userType = $state<SetupRemoteResultType>(TYPE_CANCELLED);
let proceedTitle = $derived.by(() => { let proceedTitle = $derived.by(() => {
if (userType === TYPE_COUCHDB) { if (userType === TYPE_COUCHDB) {
return "Continue to CouchDB setup"; return "Continue to CouchDB setup";
@@ -13,19 +13,18 @@
DEFAULT_SETTINGS, DEFAULT_SETTINGS,
PREFERRED_JOURNAL_SYNC, PREFERRED_JOURNAL_SYNC,
RemoteTypes, RemoteTypes,
} from "../../../../lib/src/common/types"; } from "@lib/common/types";
import { onMount } from "svelte"; import { onMount } from "svelte";
import { getDialogContext, type GuestDialogProps } from "../../../../lib/src/UI/svelteDialog"; import { getDialogContext, type GuestDialogProps } from "@lib/UI/svelteDialog";
import { copyTo, pickBucketSyncSettings } from "../../../../lib/src/common/utils"; import { copyTo, pickBucketSyncSettings } from "@lib/common/utils";
import { TYPE_CANCELLED, type SetupRemoteBucketResultType } from "./setupDialogTypes";
const default_setting = pickBucketSyncSettings(DEFAULT_SETTINGS); const default_setting = pickBucketSyncSettings(DEFAULT_SETTINGS);
let syncSetting = $state<BucketSyncSetting>({ ...default_setting }); let syncSetting = $state<BucketSyncSetting>({ ...default_setting });
type ResultType = typeof TYPE_CANCELLED | BucketSyncSetting; type Props = GuestDialogProps<SetupRemoteBucketResultType, BucketSyncSetting>;
type Props = GuestDialogProps<ResultType, BucketSyncSetting>;
const TYPE_CANCELLED = "cancelled";
const { setResult, getInitialData }: Props = $props(); const { setResult, getInitialData }: Props = $props();
@@ -14,20 +14,19 @@
RemoteTypes, RemoteTypes,
type CouchDBConnection, type CouchDBConnection,
type ObsidianLiveSyncSettings, type ObsidianLiveSyncSettings,
} from "../../../../lib/src/common/types"; } from "@lib/common/types";
import { isCloudantURI } from "../../../../lib/src/pouchdb/utils_couchdb"; import { isCloudantURI } from "@lib/pouchdb/utils_couchdb";
import { onMount } from "svelte"; import { onMount } from "svelte";
import { getDialogContext, type GuestDialogProps } from "../../../../lib/src/UI/svelteDialog"; import { getDialogContext, type GuestDialogProps } from "@lib/UI/svelteDialog";
import { copyTo, pickCouchDBSyncSettings } from "../../../../lib/src/common/utils"; import { copyTo, pickCouchDBSyncSettings } from "@lib/common/utils";
import PanelCouchDBCheck from "./PanelCouchDBCheck.svelte"; import PanelCouchDBCheck from "./PanelCouchDBCheck.svelte";
import { TYPE_CANCELLED, type SetupRemoteCouchDBResultType } from "./setupDialogTypes";
const default_setting = pickCouchDBSyncSettings(DEFAULT_SETTINGS); const default_setting = pickCouchDBSyncSettings(DEFAULT_SETTINGS);
let syncSetting = $state<CouchDBConnection>({ ...default_setting }); let syncSetting = $state<CouchDBConnection>({ ...default_setting });
type ResultType = typeof TYPE_CANCELLED | CouchDBConnection; type Props = GuestDialogProps<SetupRemoteCouchDBResultType, CouchDBConnection>;
const TYPE_CANCELLED = "cancelled";
type Props = GuestDialogProps<ResultType, CouchDBConnection>;
const { setResult, getInitialData }: Props = $props(); const { setResult, getInitialData }: Props = $props();
onMount(() => { onMount(() => {
if (getInitialData) { if (getInitialData) {
@@ -12,13 +12,13 @@
E2EEAlgorithmNames, E2EEAlgorithmNames,
E2EEAlgorithms, E2EEAlgorithms,
type EncryptionSettings, type EncryptionSettings,
} from "../../../../lib/src/common/types"; } from "@lib/common/types";
import { onMount } from "svelte"; import { onMount } from "svelte";
import type { GuestDialogProps } from "../../../../lib/src/UI/svelteDialog"; import type { GuestDialogProps } from "@lib/UI/svelteDialog";
import { copyTo, pickEncryptionSettings } from "../../../../lib/src/common/utils"; import { copyTo, pickEncryptionSettings } from "@lib/common/utils";
const TYPE_CANCELLED = "cancelled"; import { TYPE_CANCELLED, type SetupRemoteE2EEResultType } from "./setupDialogTypes";
type ResultType = typeof TYPE_CANCELLED | EncryptionSettings;
type Props = GuestDialogProps<ResultType, EncryptionSettings>; type Props = GuestDialogProps<SetupRemoteE2EEResultType, EncryptionSettings>;
const { setResult, getInitialData }: Props = $props(); const { setResult, getInitialData }: Props = $props();
let default_encryption: EncryptionSettings = { let default_encryption: EncryptionSettings = {
encrypt: true, encrypt: true,
@@ -26,16 +26,14 @@
import { getDialogContext, type GuestDialogProps } from "@lib/UI/svelteDialog"; import { getDialogContext, type GuestDialogProps } from "@lib/UI/svelteDialog";
import { SETTING_KEY_P2P_DEVICE_NAME } from "@lib/common/types"; import { SETTING_KEY_P2P_DEVICE_NAME } from "@lib/common/types";
import ExtraItems from "@lib/UI/components/ExtraItems.svelte"; import ExtraItems from "@lib/UI/components/ExtraItems.svelte";
import { TYPE_CANCELLED, type SetupRemoteP2PResultType } from "./setupDialogTypes";
const default_setting = pickP2PSyncSettings(DEFAULT_SETTINGS); const default_setting = pickP2PSyncSettings(DEFAULT_SETTINGS);
let syncSetting = $state<P2PConnectionInfo>({ ...default_setting }); let syncSetting = $state<P2PConnectionInfo>({ ...default_setting });
const context = getDialogContext(); const context = getDialogContext();
let error = $state(""); let error = $state("");
const TYPE_CANCELLED = "cancelled"; type Props = GuestDialogProps<SetupRemoteP2PResultType, P2PSyncSetting>;
type SettingInfo = P2PConnectionInfo;
type ResultType = typeof TYPE_CANCELLED | SettingInfo;
type Props = GuestDialogProps<ResultType, P2PSyncSetting>;
const { setResult, getInitialData }: Props = $props(); const { setResult, getInitialData }: Props = $props();
onMount(() => { onMount(() => {
@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { configURIBase } from "../../../../common/types"; import { configURIBase } from "@/common/types";
import type { ObsidianLiveSyncSettings } from "../../../../lib/src/common/types"; import type { ObsidianLiveSyncSettings } from "@lib/common/types";
import DialogHeader from "@/lib/src/UI/components/DialogHeader.svelte"; import DialogHeader from "@/lib/src/UI/components/DialogHeader.svelte";
import Guidance from "@/lib/src/UI/components/Guidance.svelte"; import Guidance from "@/lib/src/UI/components/Guidance.svelte";
import Decision from "@/lib/src/UI/components/Decision.svelte"; import Decision from "@/lib/src/UI/components/Decision.svelte";
@@ -10,11 +10,11 @@
import Password from "@/lib/src/UI/components/Password.svelte"; import Password from "@/lib/src/UI/components/Password.svelte";
import { onMount } from "svelte"; import { onMount } from "svelte";
import { decryptString } from "../../../../lib/src/encryption/stringEncryption.ts"; import { decryptString } from "@lib/encryption/stringEncryption.ts";
import type { GuestDialogProps } from "../../../../lib/src/UI/svelteDialog.ts"; import type { GuestDialogProps } from "@lib/UI/svelteDialog.ts";
const TYPE_CANCELLED = "cancelled"; import { TYPE_CANCELLED, type UseSetupURIResultType } from "./setupDialogTypes";
type ResultType = typeof TYPE_CANCELLED | ObsidianLiveSyncSettings;
type Props = GuestDialogProps<ResultType, string>; type Props = GuestDialogProps<UseSetupURIResultType, string>;
const { setResult, getInitialData }: Props = $props(); const { setResult, getInitialData }: Props = $props();
let setupURI = $state(""); let setupURI = $state("");
@@ -0,0 +1,108 @@
import type {
BucketSyncSetting,
CouchDBConnection,
EncryptionSettings,
ObsidianLiveSyncSettings,
P2PConnectionInfo,
} from "@lib/common/models/setting.type";
export const TYPE_IDENTICAL = "identical";
export const TYPE_INDEPENDENT = "independent";
export const TYPE_UNBALANCED = "unbalanced";
export const TYPE_CANCEL = "cancelled";
export const TYPE_BACKUP_DONE = "backup_done";
export const TYPE_BACKUP_SKIPPED = "backup_skipped";
export const TYPE_UNABLE_TO_BACKUP = "unable_to_backup";
// Intro
export const TYPE_NEW_USER = "new-user";
export const TYPE_EXISTING_USER = "existing-user";
export const TYPE_CANCELLED = "cancelled";
// Outro ask user mode
export const TYPE_EXISTING = "existing-user";
export const TYPE_NEW = "new-user";
export const TYPE_COMPATIBLE_EXISTING = "compatible-existing-user";
// OutroExistingUser
export const TYPE_APPLY = "apply";
// Select methods
export const TYPE_USE_SETUP_URI = "use-setup-uri";
export const TYPE_SCAN_QR_CODE = "scan-qr-code";
export const TYPE_CONFIGURE_MANUALLY = "configure-manually";
// ScanQRCode
export const TYPE_CLOSE = "close";
// SetupRemote
export const TYPE_COUCHDB = "couchdb";
export const TYPE_BUCKET = "bucket";
export const TYPE_P2P = "p2p";
export type ResultTypeVault =
| typeof TYPE_IDENTICAL
| typeof TYPE_INDEPENDENT
| typeof TYPE_UNBALANCED
| typeof TYPE_CANCEL;
export type ResultTypeBackup =
| typeof TYPE_BACKUP_DONE
| typeof TYPE_BACKUP_SKIPPED
| typeof TYPE_UNABLE_TO_BACKUP
| typeof TYPE_CANCEL;
export type ResultTypeExtra = {
preventFetchingConfig: boolean;
};
export type FetchEverythingResult =
| {
vault: ResultTypeVault;
backup: ResultTypeBackup;
extra: ResultTypeExtra;
}
| typeof TYPE_CANCEL;
export type RebuildEverythingResult =
| {
backup: ResultTypeBackup;
extra: ResultTypeExtra;
}
| typeof TYPE_CANCEL;
export type IntroResultType = typeof TYPE_NEW_USER | typeof TYPE_EXISTING_USER | typeof TYPE_CANCELLED;
export type OutroAskUserModeResultType =
| typeof TYPE_EXISTING
| typeof TYPE_NEW
| typeof TYPE_COMPATIBLE_EXISTING
| typeof TYPE_CANCELLED;
export type OutroExistingUserResultType = typeof TYPE_APPLY | typeof TYPE_CANCELLED;
export type OutroNewUserResultType = typeof TYPE_APPLY | typeof TYPE_CANCELLED;
export type SelectMethodNewUserResultType =
| typeof TYPE_USE_SETUP_URI
| typeof TYPE_CONFIGURE_MANUALLY
| typeof TYPE_CANCELLED;
export type SelectMethodExistingResultType =
| typeof TYPE_USE_SETUP_URI
| typeof TYPE_SCAN_QR_CODE
| typeof TYPE_CONFIGURE_MANUALLY
| typeof TYPE_CANCELLED;
export type SetupRemoteResultType = typeof TYPE_COUCHDB | typeof TYPE_BUCKET | typeof TYPE_P2P | typeof TYPE_CANCELLED;
export type UseSetupURIResultType = typeof TYPE_CANCELLED | ObsidianLiveSyncSettings;
export type SetupRemoteE2EEResultType = typeof TYPE_CANCELLED | EncryptionSettings;
export type SetupRemoteBucketResultType = typeof TYPE_CANCELLED | BucketSyncSetting;
export type SetupRemoteCouchDBResultType = typeof TYPE_CANCELLED | CouchDBConnection;
export type SetupRemoteP2PResultType = typeof TYPE_CANCELLED | P2PConnectionInfo;
export type ScanQRCodeResultType = typeof TYPE_CLOSE;
+3 -2
View File
@@ -8,6 +8,7 @@ import { extractObject } from "octagonal-wheels/object";
import { REMOTE_MINIO, REMOTE_P2P } from "@lib/common/models/setting.const"; import { REMOTE_MINIO, REMOTE_P2P } from "@lib/common/models/setting.const";
import type { ObsidianLiveSyncSettings } from "@lib/common/models/setting.type"; import type { ObsidianLiveSyncSettings } from "@lib/common/models/setting.type";
import { TweakValuesShouldMatchedTemplate } from "@lib/common/models/tweak.definition"; import { TweakValuesShouldMatchedTemplate } from "@lib/common/models/tweak.definition";
import type { FetchEverythingResult, RebuildEverythingResult } from "@/modules/features/SetupWizard/dialogs/setupDialogTypes";
/** /**
* Flag file handler interface, similar to target filter pattern. * Flag file handler interface, similar to target filter pattern.
@@ -65,7 +66,7 @@ export function createFetchAllFlagHandler(
// Handle the fetch all scheduled operation // Handle the fetch all scheduled operation
const onScheduled = async () => { const onScheduled = async () => {
const method = await host.services.UI.dialogManager.openWithExplicitCancel(FetchEverything); const method = await host.services.UI.dialogManager.openWithExplicitCancel<FetchEverythingResult>(FetchEverything);
if (method === "cancelled") { if (method === "cancelled") {
log("Fetch everything cancelled by user.", LOG_LEVEL_NOTICE); log("Fetch everything cancelled by user.", LOG_LEVEL_NOTICE);
await cleanupFlag(); await cleanupFlag();
@@ -296,7 +297,7 @@ export function createRebuildFlagHandler(
// Handle the rebuild everything scheduled operation // Handle the rebuild everything scheduled operation
const onScheduled = async () => { const onScheduled = async () => {
const method = await host.services.UI.dialogManager.openWithExplicitCancel(RebuildEverything); const method = await host.services.UI.dialogManager.openWithExplicitCancel<RebuildEverythingResult>(RebuildEverything);
if (method === "cancelled") { if (method === "cancelled") {
log("Rebuild everything cancelled by user.", LOG_LEVEL_NOTICE); log("Rebuild everything cancelled by user.", LOG_LEVEL_NOTICE);
await cleanupFlag(); await cleanupFlag();