Skip to content

Commit

Permalink
Merge pull request #276 from decaf-dev/dev
Browse files Browse the repository at this point in the history
* feat: simplify key logic

* docs: update network section of README

* refactor: rename to "Premium features are enabled"

* docs: fix grammar

* feat: clean up old values

* feat: implement digital signature validation

* refactor: add clean up message
  • Loading branch information
decaf-dev authored Jul 30, 2024
2 parents a3bc5d2 + c3b0626 commit e6f2e22
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 345 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Click the compass button on the left-hand sidebar to open the vault explorer vie

Premium features are available to users who purchase a [Vault Explorer license](https://vaultexplorer.com/docs/premium/).

Please do not share your license key with anyone. Shared license keys will be deactivated.

## Features

| Name | Categories | Documented |
Expand Down Expand Up @@ -159,11 +161,11 @@ Premium features are available to users who purchase a [Vault Explorer license](

## Network use

For general usage of the plugin, Vault Explorer does not make any network requests.
Vault Explorer is a privacy friendly plugin.

If you purchase a Vault Explorer license, the plugin will communicate with the Vault Explorer API. These requests will only send the license key you enter and a device ID generated by the plugin.
When you access the grid view, Vault Explorer will make requests to the URL's that you specify to display cover images. You may disable this behavior in the settings.

When you access the grid view and have configured an image URL property in the settings, Vault Explorer will request the specified URLs to display cover images on corresponding grid cards.
Besides cover image fetching, Vault Explorer does not make any network requests.

Vault Explorer does not include any client-side telemetry.

Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "vault-explorer",
"name": "Vault Explorer",
"version": "1.35.1",
"version": "1.36.0",
"minAppVersion": "1.4.13",
"description": "Explore your vault in visual format",
"author": "DecafDev",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-vault-explorer",
"version": "1.35.1",
"version": "1.36.0",
"description": "Explore your vault in visual format",
"main": "main.js",
"scripts": {
Expand Down Expand Up @@ -36,6 +36,7 @@
"typescript": "4.7.4"
},
"dependencies": {
"crypto": "^1.0.1",
"idb": "^8.0.0",
"js-logger": "^1.6.1",
"lodash": "^4.17.21",
Expand Down
2 changes: 1 addition & 1 deletion src/event/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export enum PluginEvent {
FEED_CONTENT_SETTING_CHANGE = "feed-content-setting-change",
COVER_IMAGE_SOURCE_SETTING_CHANGE = "cover-image-source-setting-change",
PROPERTY_SETTING_CHANGE = "property-setting-change",
DEVICE_REGISTRATION_CHANGE = "device-registration-change",
LICENSE_KEY_VALIDATION_CHANGE = "license-key-validation-change",
CLOCK_UPDATES_SETTING_CHANGE = "clock-updates-setting-change",
FILTER_TOGGLE_SETTING_CHANGE = "filter-toggle-setting-change",
SCROLL_BUTTONS_SETTING_CHANGE = "scroll-buttons-setting-change",
Expand Down
24 changes: 19 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import { preformMigrations } from "./migrations";
import Logger from "js-logger";
import { formatMessageForLogger, stringToLogLevel } from "./logger";
import { moveFocus } from "./focus-utils";
import { loadDeviceId } from "./svelte/shared/services/device-id-utils";
import License from "./svelte/shared/services/license";
import { PluginEvent } from "./event/types";
import { isVersionLessThan } from "./utils";
import License from "./svelte/shared/services/license";

export default class VaultExplorerPlugin extends Plugin {
settings: VaultExplorerPluginSettings = DEFAULT_SETTINGS;
Expand All @@ -27,6 +27,8 @@ export default class VaultExplorerPlugin extends Plugin {
await this.loadSettings();
this.setupLogger();

await License.getInstance().loadStoredKey();

this.registerView(
VAULT_EXPLORER_VIEW,
(leaf) => new VaultExplorerView(leaf, this)
Expand Down Expand Up @@ -54,9 +56,6 @@ export default class VaultExplorerPlugin extends Plugin {
this.app.workspace.onLayoutReady(() => {
this.layoutReady = true;
});

await loadDeviceId();
await License.getInstance().verifyLicense();
}

private registerEvents() {
Expand Down Expand Up @@ -174,6 +173,21 @@ export default class VaultExplorerPlugin extends Plugin {
if (loadedVersion !== null) {
const newData = preformMigrations(loadedVersion, loadedData);
currentData = newData;
if (isVersionLessThan(loadedVersion, "1.36.0")) {
console.log("Cleaning up old data");
const LOCAL_STORAGE_DEVICE_REGISTERED =
"vault-explorer-device-registration";
localStorage.removeItem(LOCAL_STORAGE_DEVICE_REGISTERED);

//Clean up the old device id from the versioning system
const LOCAL_STORAGE_ID = "vault-explorer-id";
localStorage.removeItem(LOCAL_STORAGE_ID);

//Clean up the old device id from the versioning system
const LOCAL_STORAGE_LICENSE_KEY =
"vault-explorer-license-key";
localStorage.removeItem(LOCAL_STORAGE_LICENSE_KEY);
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/svelte/app/components/feed-view.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import License from "src/svelte/shared/services/license";
import FeedCard from "./feed-card.svelte";
export let isDeviceRegistered = false;
export let hasValidLicenseKey = false;
export let data: FileRenderData[] = [];
export let startIndex;
export let pageLength;
let filteredItems: FileRenderData[] = [];
License.getInstance()
.getIsDeviceRegisteredStore()
.subscribe((isRegistered) => {
isDeviceRegistered = isRegistered;
.getHasValidKeyStore()
.subscribe((hasValidKey) => {
hasValidLicenseKey = hasValidKey;
});
$: {
Expand All @@ -31,13 +31,13 @@
</script>

<div class="vault-explorer-feed-view">
{#if !isDeviceRegistered}
{#if !hasValidLicenseKey}
<div>
<PremiumMessage />
<PremiumLink />
</div>
{/if}
{#if isDeviceRegistered}
{#if hasValidLicenseKey}
{#each filteredItems as fileRenderData (fileRenderData.id)}
<FeedCard
displayName={fileRenderData.displayName}
Expand Down
12 changes: 6 additions & 6 deletions src/svelte/custom-filter-app/components/content-filter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import PremiumMessage from "src/svelte/shared/components/premium-message.svelte";
const dispatch = createEventDispatcher();
let isDeviceRegistered = false;
let hasValidLicenseKey = false;
License.getInstance()
.getIsDeviceRegisteredStore()
.subscribe((isRegistered) => {
isDeviceRegistered = isRegistered;
.getHasValidKeyStore()
.subscribe((hasValidKey) => {
hasValidLicenseKey = hasValidKey;
});
function handleValueChange(e: Event) {
Expand Down Expand Up @@ -54,15 +54,15 @@
{#if condition !== ContentFilterCondition.IS_EMPTY && condition !== ContentFilterCondition.IS_NOT_EMPTY}
<input
type="text"
disabled={!isDeviceRegistered}
disabled={!hasValidLicenseKey}
placeholder="value"
{value}
on:input={handleValueChange}
/>
{/if}
</svelte:fragment>
<svelte:fragment slot="after-toggle">
{#if type === FilterRuleType.CONTENT && !isDeviceRegistered}
{#if type === FilterRuleType.CONTENT && !hasValidLicenseKey}
<div>
<PremiumMessage />
<PremiumLink />
Expand Down
10 changes: 5 additions & 5 deletions src/svelte/custom-filter-app/components/filter-rule.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
export let condition: FilterCondition;
export let isEnabled: boolean;
let isDeviceRegistered = false;
let hasValidLicenseKey = false;
const dispatch = createEventDispatcher();
License.getInstance()
.getIsDeviceRegisteredStore()
.subscribe((isRegistered) => {
isDeviceRegistered = isRegistered;
.getHasValidKeyStore()
.subscribe((hasValidKey) => {
hasValidLicenseKey = hasValidKey;
});
function handleActionsClick(e: CustomEvent) {
Expand Down Expand Up @@ -142,7 +142,7 @@
</select>
<slot name="before-condition"></slot>
<select
disabled={type === FilterRuleType.CONTENT && !isDeviceRegistered}
disabled={type === FilterRuleType.CONTENT && !hasValidLicenseKey}
value={condition}
on:change={handleConditionChange}
>
Expand Down
90 changes: 43 additions & 47 deletions src/svelte/license-key-app/index.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from "svelte";
import License, { LICENSE_KEY_LENGTH } from "../shared/services/license";
import License from "../shared/services/license";
import EventManager from "src/event/event-manager";
import PremiumLink from "../shared/components/premium-link.svelte";
import { PluginEvent } from "src/event/types";
Expand All @@ -10,71 +10,63 @@
text: string;
}
let isDeviceRegistered = false;
let hasValidLicenseKey = false;
let message: Message | null = null;
const LICENSE_KEY_SIZE = 148;
onMount(() => {
const registered = License.getInstance().getIsDeviceRegistered();
if (registered) {
const hasValidKey = License.getInstance().getHasValidKey();
if (hasValidKey) {
message = {
type: "success",
text: "This device is registered with a license key.",
text: "Premium features are enabled.",
};
}
isDeviceRegistered = registered;
hasValidLicenseKey = hasValidKey;
});
async function handleInputChange(e: Event) {
const value = (e.target as HTMLInputElement).value;
if (value.length === LICENSE_KEY_LENGTH) {
message = {
type: "info",
text: "Registering device...",
};
if (value.length < LICENSE_KEY_SIZE) return;
const result = await License.getInstance().registerDevice(value);
const responseMessage = License.getInstance().getResponseMessage();
if (result) {
isDeviceRegistered = true;
message = {
type: "success",
text: responseMessage,
};
EventManager.getInstance().emit(
PluginEvent.DEVICE_REGISTRATION_CHANGE,
true,
);
} else {
message = {
type: "failure",
text: responseMessage,
};
}
} else {
message = null;
}
}
message = {
type: "info",
text: "Validating key...",
};
const result = await License.getInstance().addKey(value);
async function handleButtonClick() {
const result = await License.getInstance().unregisterDevice();
if (result) {
isDeviceRegistered = false;
message = null;
hasValidLicenseKey = true;
message = {
type: "success",
text: "Premium features are enabled.",
};
EventManager.getInstance().emit(
PluginEvent.DEVICE_REGISTRATION_CHANGE,
false,
PluginEvent.LICENSE_KEY_VALIDATION_CHANGE,
true,
);
} else {
const responseMessage = License.getInstance().getResponseMessage();
hasValidLicenseKey = false;
message = {
type: "failure",
text: responseMessage,
text: "Invalid key.",
};
}
}
function handleRemoveButtonClick() {
License.getInstance().removeKey();
hasValidLicenseKey = false;
message = null;
EventManager.getInstance().emit(
PluginEvent.LICENSE_KEY_VALIDATION_CHANGE,
false,
);
}
function getMessageClassName(message: Message | null) {
let className = "vault-explorer-setting-message";
if (message !== null) {
Expand Down Expand Up @@ -107,12 +99,16 @@
{/if}
</div>
<div class="setting-item-control">
{#if isDeviceRegistered === false}
<input type="text" maxlength="8" on:input={handleInputChange} />
{#if hasValidLicenseKey === false}
<input
type="text"
maxlength={LICENSE_KEY_SIZE}
on:input={handleInputChange}
/>
{/if}
{#if isDeviceRegistered === true}
<button class="mod-destructive" on:click={handleButtonClick}
>Unregister device</button
{#if hasValidLicenseKey === true}
<button class="mod-destructive" on:click={handleRemoveButtonClick}
>Remove key</button
>
{/if}
</div>
Expand Down
35 changes: 0 additions & 35 deletions src/svelte/shared/services/device-id-utils.ts

This file was deleted.

Loading

0 comments on commit e6f2e22

Please sign in to comment.