Skip to content

Commit

Permalink
feat: toggle to autostart
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo310 committed Mar 12, 2024
1 parent 4f55097 commit 9f156ee
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/components/Chat/QuickSettingsDrawer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@
>
<div class="flex h-full w-full max-w-[500px] flex-col items-center justify-center">
{#if isOpen}
{#if $papaState === 'loading' || $papaState === 'uninitialized'}
{#if $papaState === 'uninitialized' && !$data.isAutostart}
<h2 class="text-center">{$t('quick_settings.initialize')}</h2>
<button
aria-label={$t('quick_settings.initialize')}
on:click={() => $plugin.s2b.init()}
class="h-8 rounded-l-md px-4 py-2 transition duration-300 ease-in-out hover:bg-[--text-accent-hover]"
use:icon={'play'}
/>
<!-- TODO User should be able to enable autostart from here or point to the settings page -->
{:else if $papaState === 'loading' || $papaState === 'uninitialized'}
<LoadingAnimation />
{:else if $papaState === 'indexing'}
<h2 class="m-0">{$t('quick_settings.indexing_vault')}</h2>
Expand Down Expand Up @@ -127,15 +136,15 @@
/>
{/if}
{:else if $papaState === 'mode-change'}
<h2 class="text-center text-[--text-normal]">{$t('quick_settings.mode_changed')}{$data.isIncognitoMode ? 'Ollama' : 'OpenAI'}.</h2>
<h2 class="text-center">{$t('quick_settings.mode_changed')}{$data.isIncognitoMode ? 'Ollama' : 'OpenAI'}.</h2>
<button
aria-label={$t('quick_settings.reinitialize')}
on:click={() => initSecondBrain()}
class="h-8 rounded-l-md px-4 py-2 transition duration-300 ease-in-out hover:bg-[--text-accent-hover]"
use:icon={'play'}
use:icon={'refresh-cw'}
/>
{:else if $papaState === 'settings-change'}
<h2 class="text-center text-[--text-normal]">{$t('quick_settings.settings_change')}</h2>
<h2 class="text-center">{$t('quick_settings.settings_change')}</h2>
<button
aria-label={$t('quick_settings.reinitialize')}
on:click={() => $plugin.s2b.init()}
Expand Down
8 changes: 8 additions & 0 deletions src/components/Settings/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
Papa.setLogLevel($data.isVerbose ? LogLvl.DEBUG : LogLvl.DISABLED);
$plugin.saveSettings();
};
const changeAutostart = () => {
$data.isAutostart = !$data.isAutostart;
$plugin.saveSettings();
};
</script>

<!-- Exclude Folders -->
Expand Down Expand Up @@ -106,6 +111,9 @@
<!-- <SettingContainer name="Num. of Docs to Retrieve"> -->
<!-- <TextComponent inputType="number" value={$data.docRetrieveNum} changeFunc={(docNum) => changeDocNum(parseInt(docNum))} /> -->
<!-- </SettingContainer> -->
<SettingContainer name={$t('settings.autostart')}>
<ToggleComponent isEnabled={$data.isAutostart} changeFunc={changeAutostart} />
</SettingContainer>
<!-- Clear Plugin Data -->
<SettingContainer name={$t('settings.clear')}>
<!-- TODO Add a warning modal -->
Expand Down
1 change: 0 additions & 1 deletion src/components/Settings/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO translate model descriptions
export const OpenAIGenModels = {
'gpt-3.5-turbo': {
contextWindow: 4096,
Expand Down
2 changes: 2 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"description": "Are you sure you want to delete the plugin data? Note that only the plugin data and the vector store data will be removed. All chat files inside your vault will not be affected."
},
"clear_label": "Clear",
"autostart": "Autostart",
"debugging": "Debugging",
"langsmith_key": "Langsmith API Key",
"verbose": "Verbose",
Expand Down Expand Up @@ -141,6 +142,7 @@
}
},
"quick_settings": {
"initialize": "Initialize your Smart Second Brain",
"indexing_vault": "Indexing Vault",
"assistant_language": "Assistant language",
"pause_indexing": "Pause Indexing",
Expand Down
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface PluginData {
isVerbose: boolean;
isOnboarded: boolean;
hideIncognitoWarning: boolean;
isAutostart: boolean;
}

export type PluginDataKey = keyof PluginData;
Expand Down Expand Up @@ -68,6 +69,7 @@ export const DEFAULT_SETTINGS: Partial<PluginData> = {
isVerbose: false,
isOnboarded: false,
hideIncognitoWarning: false,
isAutostart: false,
};

export default class SecondBrainPlugin extends Plugin {
Expand Down Expand Up @@ -98,7 +100,7 @@ export default class SecondBrainPlugin extends Plugin {
this.leaf = leaves[0];
this.activateView();
}
if (get(data).isOnboarded) this.s2b.init();
if (get(data).isOnboarded && get(data).isAutostart) this.s2b.init();
});
this.registerEvent(
this.app.workspace.on('layout-change', () => {
Expand Down

0 comments on commit 9f156ee

Please sign in to comment.