Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/content/prefs/notero-pref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum NoteroPref {
pageTitleFormat = 'pageTitleFormat',
syncNotes = 'syncNotes',
syncOnModifyItems = 'syncOnModifyItems',
urlSchema = 'urlSchema',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to prefix the pref name with notion so that we know which URLs we're talking about.

Also, the correct term is scheme rather than schema, so we'll want to update that everywhere.

Suggested change
urlSchema = 'urlSchema',
notionUrlScheme = 'notionUrlScheme',

}

export enum PageTitleFormat {
Expand All @@ -19,6 +20,11 @@ export enum PageTitleFormat {
itemTitle = 'itemTitle',
}

export enum UrlSchema {
notion = 'notion',
https = 'https',
}

export const PAGE_TITLE_FORMAT_L10N_IDS: Record<
PageTitleFormat,
FluentMessageId
Expand All @@ -42,6 +48,7 @@ type NoteroPrefValue = Partial<{
[NoteroPref.pageTitleFormat]: PageTitleFormat;
[NoteroPref.syncNotes]: boolean;
[NoteroPref.syncOnModifyItems]: boolean;
[NoteroPref.urlSchema]: UrlSchema;
}>;

function buildFullPrefName(pref: NoteroPref): string {
Expand All @@ -56,6 +63,12 @@ function getStringPref(value: Zotero.Prefs.Value): string | undefined {
return typeof value === 'string' && value ? value : undefined;
}

function getUrlSchemaPref(value: Zotero.Prefs.Value): UrlSchema | undefined {
return Object.values(UrlSchema).includes(value as UrlSchema)
? (value as UrlSchema)
: undefined;
}

function isPageTitleFormat(
value: Zotero.Prefs.Value,
): value is PageTitleFormat {
Expand All @@ -82,13 +95,17 @@ function convertRawPrefValue<P extends NoteroPref>(
(pref === NoteroPref.pageTitleFormat && getPageTitleFormatPref(value)) ||
undefined;

const urlSchemaPref =
(pref === NoteroPref.urlSchema && getUrlSchemaPref(value)) || undefined;

return {
[NoteroPref.collectionSyncConfigs]: stringPref,
[NoteroPref.notionDatabaseID]: stringPref,
[NoteroPref.notionToken]: stringPref,
[NoteroPref.pageTitleFormat]: pageTitleFormatPref,
[NoteroPref.syncNotes]: booleanPref,
[NoteroPref.syncOnModifyItems]: booleanPref,
[NoteroPref.urlSchema]: urlSchemaPref,
}[pref];
}

Expand Down
21 changes: 20 additions & 1 deletion src/content/prefs/preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
logger,
} from '../utils';

import { PAGE_TITLE_FORMAT_L10N_IDS, PageTitleFormat } from './notero-pref';
import {
PAGE_TITLE_FORMAT_L10N_IDS,
PageTitleFormat,
UrlSchema,
} from './notero-pref';
import { SyncConfigsTable } from './sync-configs-table';

type ReactDOMClient = typeof ReactDOM & { createRoot: typeof createRoot };
Expand Down Expand Up @@ -57,6 +61,7 @@ class Preferences {
private notionError!: XUL.LabelElement;
private notionWorkspaceLabel!: XUL.LabelElement;
private pageTitleFormatMenu!: XUL.MenuListElement;
private urlSchemaMenu!: XUL.MenuListElement;

public async init(): Promise<void> {
await Zotero.uiReadyPromise;
Expand All @@ -79,6 +84,7 @@ class Preferences {
this.notionDatabaseMenu = getXULElementById('notero-notionDatabase')!;
this.notionError = getXULElementById('notero-notionError')!;
this.pageTitleFormatMenu = getXULElementById('notero-pageTitleFormat')!;
this.urlSchemaMenu = getXULElementById('notero-urlSchema')!;
/* eslint-enable @typescript-eslint/no-non-null-assertion */

window.addEventListener('unload', () => {
Expand All @@ -87,6 +93,7 @@ class Preferences {

await this.initPageTitleFormatMenu();
await this.initSyncConfigsTable();
this.initUrlSchemaMenu();

// Don't block window from loading while waiting for network responses
setTimeout(() => {
Expand All @@ -106,6 +113,18 @@ class Preferences {
);
}

private initUrlSchemaMenu(): void {
const menuItems = Object.values(UrlSchema).map<MenuItem>((schema) => ({
disabled: false,
label: `${schema}://`,
value: schema,
}));

setMenuItems(this.urlSchemaMenu, menuItems);
this.urlSchemaMenu.disabled = false;
this.urlSchemaMenu.value = UrlSchema.notion; // Set default value to Notion schema
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line doesn't appear to be working for me.

CleanShot 2025-04-27 at 16 04 56@2x

I think we'll instead want to set the default in src/prefs.js.

}

private async initPageTitleFormatMenu(): Promise<void> {
const isBetterBibTeXActive = await this.isBetterBibTeXActive();

Expand Down
21 changes: 21 additions & 0 deletions src/content/prefs/preferences.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@
</hbox>
</groupbox>

<groupbox class="notero-groupbox">
<label>
<html:h2 data-l10n-id="notero-preferences-links-groupbox-heading" />
</label>
<label data-l10n-id="notero-preferences-links-groupbox-description" />
<separator class="thin" />
<hbox align="center">
<label
control="notero-urlSchema"
data-l10n-id="notero-preferences-links-url-schema"
/>
<menulist
id="notero-urlSchema"
native="true"
preference="extensions.notero.urlSchema"
>
<menupopup />
</menulist>
</hbox>
</groupbox>

<groupbox class="notero-groupbox">
<label>
<html:h2 data-l10n-id="notero-preferences-sync-groupbox-heading" />
Expand Down
9 changes: 7 additions & 2 deletions src/content/sync/sync-regular-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
saveNotionTag,
} from '../data/item-data';
import { LocalizableError } from '../errors';
import { getNoteroPref, NoteroPref, UrlSchema } from '../prefs/notero-pref';
import { logger } from '../utils';

import type { DatabaseRequestProperties } from './notion-types';
Expand All @@ -28,8 +29,12 @@ export async function syncRegularItem(
await saveNotionTag(item);

if (isFullPage(response)) {
const appURL = convertWebURLToAppURL(response.url);
await saveNotionLinkAttachment(item, appURL);
// Decide link schema based on user preference
const notionURL =
getNoteroPref(NoteroPref.urlSchema) === UrlSchema.notion
? convertWebURLToAppURL(response.url)
: response.url;
await saveNotionLinkAttachment(item, notionURL);
} else {
throw new LocalizableError(
'Failed to create Notion link attachment',
Expand Down
5 changes: 5 additions & 0 deletions src/locale/en-US/notero.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ notero-preferences-properties-groupbox-heading = Property Preferences
notero-preferences-properties-groupbox-description = Customize how item properties sync to Notion.
notero-preferences-page-title-format = Notion Page Title:

## Link preferences
notero-preferences-links-groupbox-heading = Link Preferences
notero-preferences-links-groupbox-description = Define if links are saved as notion:// or https:// links. Note that notion:// links are only accessible if the desktop app is installed.
notero-preferences-links-url-schema = URL Schema:

## Page title format options

notero-page-title-format-item-author-date-citation =
Expand Down