Skip to content

Commit

Permalink
Minor patch
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Sep 29, 2021
1 parent 4df992f commit 61eb782
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 115 deletions.
4 changes: 3 additions & 1 deletion CHANGE_LOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# 0.12.1
# 0.13.0

## What’s Changed

- [feature, experimental] Add `script` to quicklook for further interactions.
- [fix, refactoring] Change clipboard history store from redux to custom storage. This improve slightly arvis performance, fix possible json parsing bug.
- [fix] Fix some markdown renderer bugs
- [fix] Fix asyncQuicklookPromises issue
- [optimization] Performance slightly up

# 0.12.0

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "arvis",
"productName": "Arvis",
"version": "0.12.1",
"description": "Cross-platform launcher that help you run, edit, create any workflow simple",
"version": "0.13.0",
"description": "Extendable cross-platform launcher that aims to help you run, edit, create any workflow simply",
"homepage": "https://jopemachine.github.io/arvis.com/",
"scripts": {
"build": "concurrently \"yarn build:main\" \"yarn build:renderer\"",
Expand Down Expand Up @@ -236,7 +236,7 @@
"@types/webpack-env": "^1.15.2",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"arvis-core": "^0.16.3",
"arvis-core": "^0.17.1",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.1.0",
"babel-loader": "^8.2.2",
Expand Down Expand Up @@ -326,14 +326,14 @@
"got": "11.8.2",
"history": "^5.0.1",
"is-admin": "^3.0.0",
"is-promise": "^4.0.0",
"is-url": "^1.2.4",
"istextorbinary": "^5.14.0",
"jsoneditor": "^9.5.6",
"jsoneditor-react": "^3.1.1",
"open": "^8.2.1",
"p-any": "^4.0.0",
"p-cancelable": "2.1.1",
"p-debounce": "2.1.0",
"pascal-case": "^3.1.2",
"path-exists": "^4.0.0",
"plist": "^3.0.4",
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/changeLogModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type IProps = {
setOpened: (opened: boolean) => void;
};

const API =
const arvisChangeLogAPI =
'https://raw.githubusercontent.com/jopemachine/arvis/master/CHANGE_LOG.md';

const ChangeLogModal = (props: IProps) => {
Expand All @@ -18,7 +18,7 @@ const ChangeLogModal = (props: IProps) => {
const toggle = () => setOpened(!opened);

useEffect(() => {
got.get(API).then((response) => setContent(response.body));
got.get(arvisChangeLogAPI).then((response) => setContent(response.body));
}, []);

return (
Expand Down
98 changes: 58 additions & 40 deletions src/app/components/quicklook/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-eval */
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect, useRef, useCallback } from 'react';
import { useSpring, animated } from 'react-spring';
import fse from 'fs-extra';
import isPromise from 'is-promise';
import { Core } from 'arvis-core';
import pDebounce from 'p-debounce';
import Spinner from '../searchWindowSpinner';
import { QuicklookWebview } from './quicklookWebview';
import { QuicklookText } from './quicklookText';
Expand Down Expand Up @@ -80,7 +81,7 @@ export default (props: IProps) => {
setQuicklookData,
} = props;

const { active, data, type, script } = quicklookData;
const { active, data, type, script, asyncQuicklookItemUid } = quicklookData;

const [initialRendering, setInitialRendering] = useState<boolean>(true);

Expand All @@ -97,14 +98,24 @@ export default (props: IProps) => {
handleBarOffset,
});

const getInnerContainer = async () => {
const setVisible = useCallback((visible: boolean) => {
setQuicklookData({
...quicklookData,
active: visible,
});
}, []);

const getInnerContainer = useCallback(async () => {
let targetData = data;

if (!type || !targetData) return <div>No data to display</div>;

if (isPromise(targetData)) {
if (asyncQuicklookItemUid) {
try {
targetData = await (data as Promise<string>);
targetData = await pDebounce(
Core.pluginWorkspace.requestAsyncQuicklookRender,
25
)(asyncQuicklookItemUid);
} catch (err: any) {
return <div>{err}</div>;
}
Expand All @@ -118,12 +129,7 @@ export default (props: IProps) => {
<QuicklookWebview
data={targetData as string}
visible={hovering || active}
setVisible={(visible) =>
setQuicklookData({
...quicklookData,
active: visible,
})
}
setVisible={setVisible}
/>
);

Expand Down Expand Up @@ -156,45 +162,55 @@ export default (props: IProps) => {
}

throw new Error(`Not proper quicklook data type:\n${type}`);
};
}, [active, data]);

const onMouseEnterEventHandler = () => {
const onMouseEnterEventHandler = useCallback(() => {
setHovering(true);
};
}, []);

const onMouseLeaveEventHandler = () => {
const onMouseLeaveEventHandler = useCallback(() => {
setHovering(false);
};
}, []);

const onMouseDownEventHandler = (e: React.MouseEvent<HTMLInputElement>) => {
setOnResizing(true);
onResizingRef.current = true;
if (handleBarOriginalPos === -1) {
handleBarOriginalPos = e.clientX;
}
};
const onMouseDownEventHandler = useCallback(
(e: React.MouseEvent<HTMLInputElement>) => {
setOnResizing(true);
onResizingRef.current = true;
if (handleBarOriginalPos === -1) {
handleBarOriginalPos = e.clientX;
}
},
[]
);

const onMouseUpEventHandler = (
e: React.MouseEvent<HTMLInputElement> | MouseEvent
) => {
onResizingRef.current = false;
setOnResizing(false);
};
const onMouseUpEventHandler = useCallback(
(e: React.MouseEvent<HTMLInputElement> | MouseEvent) => {
onResizingRef.current = false;
setOnResizing(false);
},
[]
);

const quicklookResizeHandler = (clientX: number) => {
setHandlerBarOffset(handleBarOriginalPos - clientX + resizedWindowOffset);
};
const quicklookResizeHandler = useCallback(
(clientX: number) => {
setHandlerBarOffset(handleBarOriginalPos - clientX + resizedWindowOffset);
},
[handleBarOriginalPos, resizedWindowOffset]
);

const onMouseMoveEventHandler = (e: MouseEvent) => {
if (!onResizingRef.current || handleBarOriginalPos === -1) return;
quicklookResizeHandler(e.clientX);
};
const onMouseMoveEventHandler = useCallback(
(e: MouseEvent) => {
if (!onResizingRef.current || handleBarOriginalPos === -1) return;
quicklookResizeHandler(e.clientX);
},
[handleBarOriginalPos]
);

const updateContent = () => {
const updateContent = useCallback(() => {
setContents(renderLoading());

getInnerContainer().then(setContents).catch(console.error);
};
}, [active, data]);

useEffect(() => {
(document.getElementById('searchWindow') as HTMLDivElement).onmousemove =
Expand All @@ -209,7 +225,7 @@ export default (props: IProps) => {

useEffect(() => {
updateContent();
}, [data]);
}, [active, data]);

useEffect(() => {
if (script) {
Expand Down Expand Up @@ -275,8 +291,10 @@ export default (props: IProps) => {
>
{contents}
<HandleBar
title="Resize quicklook's size by dragging handle bar, double click to close quicklook"
onMouseDown={onMouseDownEventHandler}
onMouseUp={onMouseUpEventHandler as (e: React.MouseEvent) => void}
onDoubleClick={() => setVisible(false)}
>
<InnerHandleBarColor />
<InnerHandleBarColor style={{ marginLeft: 2 }} />
Expand Down
49 changes: 29 additions & 20 deletions src/app/components/searchBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/ban-types */

import { ipcRenderer } from 'electron';
import React, { useEffect } from 'react';
import React, { useEffect, useCallback } from 'react';
import SearchWindowSpinner from '../searchWindowSpinner';
import { IPCRendererEnum } from '../../ipc/ipcEventEnum';
import { OuterContainer, Input, AutoSuggestion } from './components';
Expand Down Expand Up @@ -59,27 +59,36 @@ const SearchBar = (props: IProps) => {
}
}, [originalRef]);

const preventUpAndDownArrow = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
e.preventDefault();
}
// For quicklook feature, prevent adding space when quicklook shortcut is pressed
if (e.key === ' ' && e.shiftKey) {
e.preventDefault();
}
};

const preventBlur = (e: React.FocusEvent<HTMLInputElement>) => {
e.preventDefault();
originalRef && originalRef.current && originalRef.current.focus();
};
const preventUpAndDownArrow = useCallback(
(e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
e.preventDefault();
}
// For quicklook feature, prevent adding space when quicklook shortcut is pressed
if (e.key === ' ' && e.shiftKey) {
e.preventDefault();
}
},
[]
);

const rightClickHandler = (e: React.MouseEvent<HTMLInputElement>) => {
if (hasContextMenu) {
const preventBlur = useCallback(
(e: React.FocusEvent<HTMLInputElement>) => {
e.preventDefault();
ipcRenderer.send(IPCRendererEnum.popupSearchbarItemMenu, { isPinned });
}
};
originalRef && originalRef.current && originalRef.current.focus();
},
[originalRef.current]
);

const rightClickHandler = useCallback(
(e: React.MouseEvent<HTMLInputElement>) => {
if (hasContextMenu) {
e.preventDefault();
ipcRenderer.send(IPCRendererEnum.popupSearchbarItemMenu, { isPinned });
}
},
[hasContextMenu, isPinned]
);

return (
<OuterContainer
Expand Down
14 changes: 7 additions & 7 deletions src/app/containers/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function SearchWindow() {

const actionFlowManager = Core.ActionFlowManager.getInstance();

const setDebuggingOptions = () => {
const setDebuggingOptions = useCallback(() => {
actionFlowManager.printActionType = debuggingConfig.debugging_action;
actionFlowManager.printVariables = debuggingConfig.debugging_variables;
actionFlowManager.printPluginItems = debuggingConfig.debugging_plugin;
Expand All @@ -103,7 +103,7 @@ export default function SearchWindow() {
actionFlowManager.printScriptOutput = debuggingConfig.debugging_script;
actionFlowManager.printTriggerStack =
debuggingConfig.debugging_trigger_stack;
};
}, [debuggingConfig]);

useEffect(() => {
setDebuggingOptions();
Expand Down Expand Up @@ -150,11 +150,11 @@ export default function SearchWindow() {
Core.Renderer.setOnWorkEndHandler(onWorkEndHandler);
}, []);

const initializeCustomActions = () => {
const initializeCustomActions = useCallback(() => {
Core.registerCustomAction('notification', notificationActionHandler);
Core.registerCustomAction('clipboard', clipboardActionHandler);
Core.registerCustomAction('keyDispatching', keyDispatchingActionHandler);
};
}, []);

const registerAllGlobalHotkeys = () => {
const defaultHotkeyTbls = _.pickBy(
Expand Down Expand Up @@ -333,11 +333,11 @@ export default function SearchWindow() {
);
}, []);

const initializeWorkerProcesses = () => {
const initializeWorkerProcesses = useCallback(() => {
Core.setUseExecutorProcess(true);
Core.startScriptExecutor({ execa: getExecaPath() });
Core.startPluginExecutor();
};
Core.pluginWorkspace.startPluginExecutor();
}, []);

useEffect(() => {
return unloadIOHook;
Expand Down
2 changes: 0 additions & 2 deletions src/app/hooks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import useStoreSearchControl from './useStoreSearchControl';
import useSnippet from './useSnippet';
import useIoHook from './useIoHook';
import useItemList from './useItemList';
import { useReserveForceUpdate } from './useReserveForceUpdate';

export {
useAssistanceWindowControl,
Expand All @@ -20,7 +19,6 @@ export {
useItemList,
useKeyRecord,
usePressedModifier,
useReserveForceUpdate,
useSearchWindowControl,
useSnippet,
useStoreSearchControl,
Expand Down
3 changes: 2 additions & 1 deletion src/app/hooks/useAssistanceWindowControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { isWithCtrlOrCmd } from '@utils/index';
import { IPCRendererEnum } from '@ipc/ipcEventEnum';
import _ from 'lodash';
import useForceUpdate from 'use-force-update';
import pDebounce from 'p-debounce';
import useKey from '../../external/use-key-capture/src';

type IndexInfo = {
Expand Down Expand Up @@ -386,7 +387,7 @@ const useAssistanceWindowControl = ({
});

const searchByNextInput = () =>
setTimeout(
pDebounce(
() =>
handleNormalInput(
originalItemsRef.current,
Expand Down
18 changes: 0 additions & 18 deletions src/app/hooks/useReserveForceUpdate.tsx

This file was deleted.

Loading

0 comments on commit 61eb782

Please sign in to comment.