Skip to content

Commit

Permalink
[WIP]feat: only enable early access features to users that self host;…
Browse files Browse the repository at this point in the history
… too complex, will most likely be scrapped
  • Loading branch information
aexshafii committed Apr 19, 2024
1 parent c4cf65a commit bb12da3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
56 changes: 48 additions & 8 deletions src/FileOrganizerSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class FileOrganizerSettingTab extends PluginSettingTab {
.setPlaceholder("Enter access code for Early Access Features")
.setValue(this.plugin.settings.earlyAccessCode)
.onChange(async (value) => {
if (value.length !== 8) {
if (value.length !== 8) {
return;
}
const jsonPayload = {
Expand Down Expand Up @@ -211,22 +211,38 @@ export class FileOrganizerSettingTab extends PluginSettingTab {
})
);

let aiAssistantToggle;

new Setting(containerEl)
.setName("Use Self-hosted")
.setDesc("Toggle to use a custom server instead of the default.")
.addToggle((toggle) =>
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.useCustomServer)
.onChange(async (value) => {
this.plugin.settings.useCustomServer = value;
await this.plugin.saveSettings();

if (!value) {
logMessage("Disabling early access features");
this.plugin.settings.enableEarlyAccess = false;
customServerSetting.settingEl.hide();

aiAssistantToggle.setDisabled(true); // Disable AI Assistant toggle when custom server is disabled
aiAssistantToggle.setValue(false); // Turn off AI Assistant toggle when custom server is disabled

return;
}

logMessage("Enabling early access features on custom server");
this.plugin.settings.enableEarlyAccess = true;
customServerSetting.settingEl.show();
})
);
aiAssistantToggle.setDisabled(false); // Enable AI Assistant toggle when custom server is enabled
await this.plugin.saveSettings(); // Save settings after enabling early access features
});
});



const customServerSetting = new Setting(containerEl)
.setName("Self-hosted URL")
Expand Down Expand Up @@ -263,12 +279,36 @@ export class FileOrganizerSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);
// Function to initialize the AI Assistant toggle
const initAIAssistantToggle = () => {
new Setting(containerEl)
.setName("AI Assistant (available in early access)")
.setDesc("A sidebar that gives you more control in your file management.")
.addToggle((toggle) => {
aiAssistantToggle = toggle; // Store the toggle instance in the aiAssistantToggle variable

new Setting(containerEl)
.setName("AI Assistant (available in early access)")
.setDesc("A sidebar that gives you more control in your file management.")
.addToggle((toggle) => toggle.setDisabled(true));
toggle
.setValue(this.plugin.settings.enableEarlyAccess)
.onChange(async (newValue) => { // Wrap the onChange callback function in an async function
this.plugin.settings.enableEarlyAccess = newValue;
await this.plugin.saveSettings(); // Save settings when AI Assistant toggle is changed
});

// Disable AI Assistant toggle based if early access or custom server is not enabled
if (!this.plugin.settings.useCustomServer || !this.plugin.settings.enableEarlyAccess) {
toggle.setValue(false);
toggle.setDisabled(true);
}
});
};
initAIAssistantToggle();

// Initially disable AI Assistant setting if custom server and early access are not enabled
if (!this.plugin.settings.useCustomServer && !this.plugin.settings.enableEarlyAccess) {
aiAssistantToggle.setDisabled(true);
} else {
aiAssistantToggle.setDisabled(false); // Enable AI Assistant toggle when custom server is enabled on load
}
new Setting(containerEl)
.setName("Experimental: Describe workflow (in progress)")
.setDesc(
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ class FileOrganizerSettings {
useAutoAppend = false;
defaultServerUrl = "https://app.fileorganizer2000.com";
customServerUrl = "https://file-organizer-2000.vercel.app/";
useCustomServer = false;
useCustomServer = false; // for self-hosted setup
useSimilarTagsInFrontmatter = false;
enableEarlyAccess = false;
enableEarlyAccess = false; // default value is false
earlyAccessCode = "";
enableAIAssistant = false; // default value is false
}

const validAudioExtensions = ["mp3", "wav", "webm", "m4a"];
Expand Down Expand Up @@ -413,8 +414,7 @@ export default class FileOrganizer extends Plugin {

// Get the most similar folder based on the content and file name
const mostSimilarFolder = await useText(
`Given the text content "${content}" (and if the file name "${
file.basename
`Given the text content "${content}" (and if the file name "${file.basename
}"), which of the following folders would be the most appropriate location for the file? Available folders: ${uniqueFolders.join(
", "
)}`,
Expand Down

0 comments on commit bb12da3

Please sign in to comment.