Skip to content

Commit

Permalink
V1.4.6 (#56)
Browse files Browse the repository at this point in the history
- Moves the Update Plugin button to the middle of the screen on iphone since it's inaccessible
- Fixes new version detection for the few plugins that do not use full semantic version numbers (ex: version 2.7 instead of 2.7.0)
  • Loading branch information
swar8080 authored Mar 17, 2023
1 parent 45b3fdc commit 1fe66e5
Show file tree
Hide file tree
Showing 28 changed files with 80 additions and 69 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ OBSIDIAN_APP_RELEASE_POLLING_SECONDS=1800
OBSIDIAN_APP_INSTALLED_VERSION_POLLING_SECONDS=30
OBSIDIAN_APP_SIMULATE_UPDATE_PLUGINS=false
OBSIDIAN_APP_HIDE_THIS_PLUGINS_UPDATES=false
OBSIDIAN_APP_THIS_PLUGIN_ID=obsidian-plugin-update-tracker
OBSIDIAN_APP_THIS_PLUGIN_ID=obsidian-plugin-update-tracker
OBSIDIAN_APP_ACTION_BAR_LOCATION_MIDDLE=false
2 changes: 1 addition & 1 deletion backend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ OPUC_RELEASES_CACHE_LENGTH_SECONDS_MULTIPLIER=1800
OPUC_PLUGIN_CACHE_LENGTH_DIVISOR=50
OPUC_RELEASES_FETCHED_PER_PLUGIN=10
OPUC_MAX_RELEASE_NOTE_LENGTH=15000
OPUC_MAX_MANIFESTS_TO_FETCH_PER_PLUGIN=8
OPUC_MAX_MANIFESTS_TO_FETCH_PER_PLUGIN=9
OPUC_GITHUB_API_TIMEOUT_MS=5000
OPUC_IGNORE_RELEASES_FOR_THIS_PLUGIN=false

Expand Down
2 changes: 1 addition & 1 deletion backend/get-releases-lambda/src/ReleaseRepository/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PluginFileAssetIds } from '../../../../shared-types';
import { PluginFileAssetIds } from '../../../../oput-common';

export interface ReleaseRepository {
//Sorted from most to least recent
Expand Down
2 changes: 1 addition & 1 deletion backend/get-releases-lambda/src/get-releases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
InstalledPluginVersion,
NewPluginVersionRequest,
PluginReleases,
} from '../../../shared-types';
} from '../../../oput-common';
import { GetReleases, GetReleasesConfiguration } from './get-releases';
import { PluginRecord, PluginRepository } from './PluginRepository';
import { ApiReleases, ReleaseApi } from './ReleaseApi';
Expand Down
5 changes: 3 additions & 2 deletions backend/get-releases-lambda/src/get-releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
InstalledPluginVersion,
ReleaseVersion,
PluginFileAssetIds,
} from '../../../shared-types';
} from '../../../oput-common';
import {
ReleaseApi,
ApiReleaseResponse,
Expand All @@ -14,7 +14,8 @@ import {
} from './ReleaseApi';
import { PluginRepository, PluginRecord } from './PluginRepository';
import { ReleaseRepository, PluginReleasesRecord, MasterManifestInfo } from './ReleaseRepository';
import { isEmpty, groupById, semverCompare, debug } from './util';
import { isEmpty, groupById, debug } from './util';
import { semverCompare } from '../../../oput-common/semverCompare';

const THIS_PLUGIN_ID = 'obsidian-plugin-update-tracker';

Expand Down
2 changes: 1 addition & 1 deletion backend/get-releases-lambda/src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
import { NewPluginVersionRequest } from '../../../shared-types';
import { NewPluginVersionRequest } from '../../../oput-common';
import { CloudWatchMetricLogger } from './MetricLogger';
import { DynamoDBReleaseRepository } from './ReleaseRepository/DynamoDBReleaseRepository';
import { GetReleases, GetReleasesConfiguration } from './get-releases';
Expand Down
35 changes: 0 additions & 35 deletions backend/get-releases-lambda/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const FUZZY_SEMVER_PATTERN = /^(\d+)\.(\d+)\.(\d+).*/;
const DEBUG_LOGS_ENABLED = process.env['OPUC_DEBUG_LOGS_ENABLED'] === 'true';

export function isEmpty(collection: any[] | null | undefined) {
Expand All @@ -25,40 +24,6 @@ export function partition<T>(items: T[], chunkSize: number): T[][] {
return partitions;
}

export function semverCompare(version1: string | null, version2: string | null): number {
if (version1 == version2) {
return 0;
} else if (version1 == null) {
return -1;
} else if (version2 == null) {
return 1;
}

const v1Match = version1.match(FUZZY_SEMVER_PATTERN);
const v2Match = version2.match(FUZZY_SEMVER_PATTERN);
if (!v1Match && !v2Match) {
return 0;
} else if (!v1Match) {
return -1;
} else if (!v2Match) {
return 1;
}

let versionPartIndex = 1;
while (versionPartIndex <= 3) {
const v1Part = parseInt(v1Match[versionPartIndex]);
const v2Part = parseInt(v2Match[versionPartIndex]);

if (v1Part !== v2Part) {
return v1Part - v2Part;
}

versionPartIndex++;
}

return 0;
}

export function debug(...args: any[]) {
if (DEBUG_LOGS_ENABLED) {
console.debug(...args);
Expand Down
15 changes: 13 additions & 2 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,29 @@ if you want to view the source, please visit the github repository of this plugi

const prod = (process.argv[2] === 'production');

console.log('using .env')
dotenv.config({path: '.env'})

const mainEnvFile = prod ? '.env.prod' : '.env.dev'
console.log(`using ${mainEnvFile}`)
dotenv.config({
path: prod ? '.env.prod' : '.env.dev'
path: mainEnvFile
})

if (prod && existsSync('.env.local.prod')) {
console.log('using .env.local.prod')
dotenv.config({path: '.env.local.prod', override: true})
}
else if (existsSync('.env.local.dev')) {
else if (!prod && existsSync('.env.local.dev')) {
console.log('using .env.local.dev')
dotenv.config({path: '.env.local.dev', override: true})
}

for (const key in process.env) {
if (key.startsWith('OBSIDIAN_APP')) {
console.log(key, '=', process.env[key])
}
}

const define = [
'OBSIDIAN_APP_UPDATE_CHECKER_URL',
Expand All @@ -37,6 +47,7 @@ const define = [
'OBSIDIAN_APP_THIS_PLUGIN_ID',
'OBSIDIAN_APP_SHOW_STATUS_BAR_ICON_ALL_PLATFORMS',
'OBSIDIAN_APP_SHOW_RIBBON_ICON_ALL_PLATFORMS',
'OBSIDIAN_APP_ACTION_BAR_LOCATION_MIDDLE',
].reduce((prev, current) => {
prev[`process.env.${current}`] = JSON.stringify(process.env[current])
return prev
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
testEnvironment: 'node',
roots: ['src/', 'backend/get-releases-lambda/'],
roots: ['src/', 'oput-common/', 'backend/get-releases-lambda/'],
testMatch: ['**/*.test.ts', '**/*.test.js'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
Expand Down
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-plugin-update-tracker",
"name": "Plugin Update Tracker",
"version": "1.4.5",
"version": "1.4.6",
"minAppVersion": "0.15.0",
"description": "Know when installed plugins have updates and evaluate the risk of upgrading",
"author": "Obsidian",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const FUZZY_SEMVER_PATTERN = /^(\d+)\.(\d+)\.(\d+).*/;
const FUZZY_SEMVER_PATTERN = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?.*/;

export function semverCompare(version1: string | null, version2: string | null): number {
if (version1 == version2) {
Expand All @@ -21,8 +21,8 @@ export function semverCompare(version1: string | null, version2: string | null):

let versionPartIndex = 1;
while (versionPartIndex <= 3) {
const v1Part = parseInt(v1Match[versionPartIndex]);
const v2Part = parseInt(v2Match[versionPartIndex]);
const v1Part = parseInt(v1Match[versionPartIndex] || '0');
const v2Part = parseInt(v2Match[versionPartIndex] || '0');

if (v1Part !== v2Part) {
return v1Part - v2Part;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-plugin-update-tracker",
"version": "1.4.5",
"version": "1.4.6",
"description": "Know when installed plugins have updates and evaluate the risk of upgrading",
"main": "main.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/DismissedPluginVersions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { PluginManifest } from 'obsidian';
import * as React from 'react';
import styled from 'styled-components';
import { semverCompare } from '../../oput-common/semverCompare';
import { PluginDismissedVersions, PluginSettings } from '../domain/pluginSettings';
import { groupById } from '../domain/util/groupById';
import { semverCompare } from '../domain/util/semverCompare';
import { useAppDispatch, useAppSelector } from '../state';
import { unDismissPluginVersion } from '../state/actionProducers/undismissPluginVersion';

Expand Down
2 changes: 2 additions & 0 deletions src/components/PluginUpdateList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const MixOfPlugins: Story = () => {
<PluginUpdateList
plugins={[PLUGIN_VIEW_MODEL_BASE, noReleaseNotes, plugin3, plugin4]}
{...PLUGIN_UPDATE_LIST_BASE}
actionBarLocation="bottom"
/>
);
};
Expand Down Expand Up @@ -111,6 +112,7 @@ export const MarkdownParsingAndEnrichment: Story = () => {
pluginWithNotes('Contains emoji', 'fix: 🐛'),
]}
{...PLUGIN_UPDATE_LIST_BASE}
actionBarLocation="bottom"
/>
);
};
Expand Down
14 changes: 11 additions & 3 deletions src/components/PluginUpdateList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ interface PluginUpdateListProps {
titleEl: HTMLElement | undefined;
persistPluginSettings: (settings: PluginSettings) => Promise<void>;
closeObsidianTab: () => void;
actionBarLocation: ActionBarLocation;
}

type ActionBarLocation = 'bottom' | 'middle';

const PluginUpdateListConnected: React.FC<PluginUpdateListProps> = ({
titleEl,
persistPluginSettings,
closeObsidianTab,
actionBarLocation,
}) => {
const allPluginReleases: InstalledPluginReleases[] = usePluginReleaseFilter();
const isLoadingReleases = useAppSelector((state) => state.releases.isLoadingReleases);
Expand Down Expand Up @@ -134,6 +138,7 @@ const PluginUpdateListConnected: React.FC<PluginUpdateListProps> = ({
selectedPluginCount={selectedPluginCount}
selectedPluginIds={selectedPluginsById}
isUpdatingDismissedVersions={isUpdatingDismissedVersions}
actionBarLocation={actionBarLocation}
handleToggleSelection={handleToggleSelection}
handleToggleSelectAll={handleToggleSelectAll}
handleInstall={handleClickInstall}
Expand All @@ -147,6 +152,7 @@ export const PluginUpdateList: React.FC<{
isInitiallyExpanded?: boolean;
selectedPluginIds: string[];
selectedPluginCount: number;
actionBarLocation: ActionBarLocation;
handleToggleSelection: (pluginId: string, selected: boolean) => any;
handleToggleSelectAll: (selectAll: boolean) => void;
handleInstall: () => Promise<any>;
Expand All @@ -157,6 +163,7 @@ export const PluginUpdateList: React.FC<{
isInitiallyExpanded,
selectedPluginIds,
selectedPluginCount,
actionBarLocation,
handleToggleSelection,
handleToggleSelectAll,
handleInstall,
Expand Down Expand Up @@ -256,12 +263,13 @@ export const PluginUpdateList: React.FC<{
</DivPluginUpdateListContainer>

{selectedPluginCount > 0 && (
<ActionBarContainer>
<ActionBarContainer isLocationBottom={actionBarLocation === 'bottom'}>
<SelectedPluginActionBar
numberOfPluginsSelected={selectedPluginCount}
isDisabled={isDisabled}
onClickInstall={handleClickInstall}
onClickDismissVersions={handleClickDismissPluginVersions}
hasBottomBorder={actionBarLocation === 'middle'}
/>
</ActionBarContainer>
)}
Expand Down Expand Up @@ -574,9 +582,9 @@ const DivReleaeseName = styled.div`
text-decoration: underline;
`;

const ActionBarContainer = styled.div`
const ActionBarContainer = styled.div<{ isLocationBottom: boolean }>`
position: fixed;
bottom: 0;
bottom: ${({ isLocationBottom }) => (isLocationBottom ? '0' : '50%')};
left: 50%;
transform: translateX(-50%);
Expand Down
11 changes: 11 additions & 0 deletions src/components/PluginUpdateManager.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Platform } from 'obsidian';
import * as React from 'react';
import { PluginSettings } from '../domain/pluginSettings';
import { useAppSelector } from '../state';
Expand All @@ -10,6 +11,9 @@ interface PluginUpdateManagerProps {
closeObsidianTab: () => void;
}

const ACTION_BAR_LOCATION_MIDDLE =
process.env['OBSIDIAN_APP_ACTION_BAR_LOCATION_MIDDLE'] === 'true';

const PluginUpdateManager: React.FC<PluginUpdateManagerProps> = ({
titleEl,
persistPluginSettings,
Expand All @@ -19,6 +23,12 @@ const PluginUpdateManager: React.FC<PluginUpdateManagerProps> = ({
(state) => state.obsidian.isUpdatingPlugins || !state.obsidian.isUpdateResultAcknowledged
);

//Action bar is cut-off on iphone https://github.com/swar8080/obsidian-plugin-update-tracker/issues/49
//@ts-ignore
const isPhone = Platform.isPhone;
const isIPhone = Platform.isIosApp && isPhone;
const actionBarLocation = isIPhone || ACTION_BAR_LOCATION_MIDDLE ? 'middle' : 'bottom';

if (showUpdateProgressTracker) {
return <PluginUpdateProgressTracker titleEl={titleEl} />;
} else {
Expand All @@ -27,6 +37,7 @@ const PluginUpdateManager: React.FC<PluginUpdateManagerProps> = ({
titleEl={titleEl}
persistPluginSettings={persistPluginSettings}
closeObsidianTab={closeObsidianTab}
actionBarLocation={actionBarLocation}
/>
);
}
Expand Down
12 changes: 8 additions & 4 deletions src/components/SelectedPluginActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface SelectedPluginActionBarProps {
isDisabled: boolean;
onClickInstall: () => Promise<any>;
onClickDismissVersions: () => Promise<any>;
hasBottomBorder: boolean;
}

const LOADING_ANIMATION_SEQUENCE_MS = 1200;
Expand Down Expand Up @@ -38,6 +39,7 @@ const SelectedPluginActionBar: React.FC<SelectedPluginActionBarProps> = ({
onClickInstall,
onClickDismissVersions,
isDisabled,
hasBottomBorder,
}) => {
const [loadingAnimationState, setLoadingAnimationState] = React.useState<LoadingAnimationState>(
{
Expand Down Expand Up @@ -98,7 +100,7 @@ const SelectedPluginActionBar: React.FC<SelectedPluginActionBarProps> = ({
const actionButtonPaddingBottomPx = statusBarHeight + 3;

return (
<DivSelectedPluginActionBarContainer>
<DivSelectedPluginActionBarContainer hasBottomBorder={hasBottomBorder}>
<DivHeaderContainer>
{!loadingAnimationState.isInProgress && <H4HeaderText>{headerText}</H4HeaderText>}
{loadingAnimationState.isInProgress && (
Expand Down Expand Up @@ -141,7 +143,9 @@ type LoadingAnimationState = {

type AnimationIcons = 'loading' | 'success' | 'error';

const DivSelectedPluginActionBarContainer = styled.div`
const CONTAINER_BORDER = '3px var(--background-modifier-border) solid';

const DivSelectedPluginActionBarContainer = styled.div<{ hasBottomBorder: boolean }>`
display: flex;
flex-direction: column;
align-items: center;
Expand All @@ -155,8 +159,8 @@ const DivSelectedPluginActionBarContainer = styled.div`
background-color: var(--background-secondary);
border: 3px var(--background-modifier-border) solid;
border-bottom: none;
border: ${CONTAINER_BORDER};
border-bottom: ${({ hasBottomBorder }) => (hasBottomBorder ? CONTAINER_BORDER : 'none')};
`;

const DivHeaderContainer = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion src/domain/InstalledPluginReleases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import find from 'lodash/find';
import map from 'lodash/map';
import orderBy from 'lodash/orderBy';
import { PluginManifest } from 'obsidian';
import { PluginFileAssetIds, PluginReleases, ReleaseVersion } from 'shared-types';
import { PluginFileAssetIds, PluginReleases, ReleaseVersion } from 'oput-common';
export default class InstalledPluginReleases {
private plugin: PluginManifest;
private releases: PluginReleases | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/domain/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { request, requestUrl } from 'obsidian';
import { NewPluginVersionRequest, PluginReleases } from 'shared-types';
import { NewPluginVersionRequest, PluginReleases } from 'oput-common';

type ReleaseApi = (request: NewPluginVersionRequest) => Promise<PluginReleases[]>;

Expand Down
2 changes: 1 addition & 1 deletion src/domain/pluginFilter.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dayjs from 'dayjs';
import { PluginManifest } from 'obsidian';
import { PluginReleases, ReleaseVersion } from '../../shared-types';
import { PluginReleases, ReleaseVersion } from '../../oput-common';
import InstalledPluginReleases from './InstalledPluginReleases';
import pluginFilter, { PluginFilters } from './pluginFilter';
import { DismissedPluginVersion, PluginSettings } from './pluginSettings';
Expand Down
Loading

0 comments on commit 1fe66e5

Please sign in to comment.