Skip to content

Commit

Permalink
1.0.5 Mobile fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TfTHacker committed Dec 6, 2023
1 parent 89b9403 commit 1df644b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.0.5

## Fixes

- Resolved an issue on mobile devices reporting "Invalid URL" for custom sites defined in settings.
- Added a notice in settings for custom sites that some sites won't work on Obsidian Mobile, even though they work on Destkop

# 1.0.4

## New
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "helpmate",
"name": "HelpMate",
"version": "1.0.4",
"version": "1.0.5",
"minAppVersion": "1.4.16",
"description": "Integrating help systems into the Obsidian UI.",
"author": "TfTHacker",
Expand All @@ -10,5 +10,5 @@
"isDesktopOnly": false,
"fundingUrl": {
"Support my work": "https://tfthacker.com/sponsor"
}
}
}
6 changes: 3 additions & 3 deletions src/UI/browsers/IFrameBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ const IFrameBrowser = ({
const [iframeUrl, setIframeUrl] = useState<string>(urlAddress || '');

const updateUrl = (url: string) => {
let newUrl = url;
if (!(url.startsWith('http://') || url.startsWith('https://'))) {
let newUrl = url.trim();
if (!newUrl.startsWith('http://') && !newUrl.startsWith('https://')) {
newUrl = `https://${url}`;
}
if (isValidUrl(newUrl)) {
setInputUrl(newUrl);
setIframeUrl(newUrl);
} else {
new Notice('Invalid URL');
new Notice('Invalid URL ' + newUrl);
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/UI/browsers/WebViewBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ const WebViewBrowser = ({

const navigateTo = () => {
debug && api.log('WebViewBrowser: navigateTo', url);
if (!(url.startsWith('http://') || url.startsWith('https://'))) {
const newUrl = `https://${url}`;
if (!url.trim().startsWith('http://') && !url.trim().startsWith('https://')) {
const newUrl = `https://${url.trim()}`;
if (isValidUrl(newUrl)) setUrl(newUrl);
}
if (isValidUrl(url)) webviewRef.current?.loadURL(url);
else new Notice('Invalid URL');
if (isValidUrl(url.trim())) webviewRef.current?.loadURL(url.trim());
else new Notice('Invalid URL ' + url);
};

const handleKeyPress = (event: KeyboardEvent) => {
Expand Down
5 changes: 3 additions & 2 deletions src/UI/settingsTab/SettingsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ export class HelpMateSettingTab extends PluginSettingTab {

containerEl
.createEl('div', {
text: `Add custom help resources to be displayed in HelpMate. Input a list of URLs, one per line.
using the following format: "Title | URL". Title is the name of the resources, and URL is the the website. For example: `,
text: `Add custom help resources to be displayed in HelpMate. Please note some sites will not
work on mobile devices, due to some characteristics of Obsidian Mobile even though they work on Obsidian Desktop. Input a list of URLs,
one per line using the following format: "Title | URL". Title is the name of the resources, and URL is the the website. For example: `,
})
.addClass('setting-item-description');

Expand Down
17 changes: 6 additions & 11 deletions src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ export interface HelpForPlugin {
}

export const isValidUrl = (url: string): boolean => {
// validate protocol, then domain name OR ip (v4) address, then port and path, then query string
const urlPattern = new RegExp(
'^(https?:\\/\\/)?' +
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
'((\\d{1,3}\\.){3}\\d{1,3}))' +
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
'(\\?[;&a-z\\d%_.~+=-]*)?' +
'(\\#[-a-z\\d_]*)?$',
'i'
);
return !!urlPattern.test(url.trim());
try {
new URL(url.trim());
return true;
} catch (error) {
return false;
}
};

export const getPluginHelpList = (plugin: HelpMatePlugin): HelpForPlugin[] => {
Expand Down

0 comments on commit 1df644b

Please sign in to comment.