mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
confirm before install, unpack tar first steps
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
9284611e7e
commit
5093262d54
@ -51,15 +51,12 @@
|
|||||||
align-self: flex-start;
|
align-self: flex-start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.SearchInput {
|
.InstallingExtensionNotification {
|
||||||
margin-top: $margin / 2;
|
.Button {
|
||||||
margin-bottom: $margin * 2;
|
background-color: unset;
|
||||||
max-width: none;
|
border: 1px solid currentColor;
|
||||||
|
box-shadow: none !important;
|
||||||
> label {
|
|
||||||
padding: $padding $padding * 2;
|
|
||||||
border-radius: $radius;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import "./extensions.scss";
|
import "./extensions.scss";
|
||||||
import { remote, shell } from "electron";
|
import { app, remote, shell } from "electron";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import tar from "tar";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { computed, observable } from "mobx";
|
import { computed, observable } from "mobx";
|
||||||
@ -9,7 +10,7 @@ import { t, Trans } from "@lingui/macro";
|
|||||||
import { _i18n } from "../../i18n";
|
import { _i18n } from "../../i18n";
|
||||||
import { Button } from "../button";
|
import { Button } from "../button";
|
||||||
import { WizardLayout } from "../layout/wizard-layout";
|
import { WizardLayout } from "../layout/wizard-layout";
|
||||||
import { DropFileInput, Input, InputValidators } from "../input";
|
import { DropFileInput, Input, InputValidators, SearchInput } from "../input";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { PageLayout } from "../layout/page-layout";
|
import { PageLayout } from "../layout/page-layout";
|
||||||
import { Clipboard } from "../clipboard";
|
import { Clipboard } from "../clipboard";
|
||||||
@ -76,7 +77,7 @@ export class Extensions extends React.Component {
|
|||||||
if (tarballUrl) {
|
if (tarballUrl) {
|
||||||
try {
|
try {
|
||||||
const { promise: filePromise } = downloadFile({ url: tarballUrl });
|
const { promise: filePromise } = downloadFile({ url: tarballUrl });
|
||||||
this.installExtensionFromFile([await filePromise]);
|
this.requestInstall([await filePromise]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Notifications.error(`Installing extension from ${tarballUrl} has failed: ${String(err)}`);
|
Notifications.error(`Installing extension from ${tarballUrl} has failed: ${String(err)}`);
|
||||||
}
|
}
|
||||||
@ -84,24 +85,49 @@ export class Extensions extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
installFromSelectFileDialog = async (filePaths: string[]) => {
|
installFromSelectFileDialog = async (filePaths: string[]) => {
|
||||||
logger.info('Install from select dialog', { filePaths });
|
logger.info('Install from file-select dialog', { files: filePaths });
|
||||||
const files: File[] = await Promise.all(
|
const files: File[] = await Promise.all(
|
||||||
filePaths.map(filePath => {
|
filePaths.map(filePath => {
|
||||||
const fileName = path.basename(filePath);
|
const fileName = path.basename(filePath);
|
||||||
return fse.readFile(filePath).then(buffer => new File([buffer], fileName));
|
return fse.readFile(filePath).then(buffer => new File([buffer], fileName));
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
return this.installExtensionFromFile(files);
|
return this.requestInstall(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
installOnDrop = (files: File[]) => {
|
installOnDrop = (files: File[]) => {
|
||||||
logger.info('Install from D&D', { files });
|
logger.info('Install from D&D', { files: files.map(file => file.path) });
|
||||||
return this.installExtensionFromFile(files);
|
return this.requestInstall(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
async installExtensionFromFile(files: File[]) {
|
async installExtension(tarball: File, cleanUp?: () => void) {
|
||||||
console.log(`Install files:`, files);
|
logger.info(`Installing extension ${tarball.name} to ${this.extensionsPath}`);
|
||||||
|
const tempDir = path.join(app.getPath("temp"), "extensions");
|
||||||
|
await fse.ensureDir(tempDir);
|
||||||
|
const unpack = () => {
|
||||||
|
tar.extract({
|
||||||
|
cwd: tempDir,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (cleanUp) {
|
||||||
|
cleanUp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: show name and description from unpacked archive
|
||||||
|
async requestInstall(files: File[]) {
|
||||||
|
files.forEach((ext: File) => {
|
||||||
|
const removeNotification = Notifications.info(
|
||||||
|
<div className="InstallingExtensionNotification flex gaps">
|
||||||
|
<p>Install extension <em>{ext.name}</em>?</p>
|
||||||
|
<Button
|
||||||
|
label="Confirm"
|
||||||
|
onClick={() => this.installExtension(ext, removeNotification)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
renderInfo() {
|
renderInfo() {
|
||||||
@ -140,11 +166,11 @@ export class Extensions extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
primary
|
primary
|
||||||
label="Select local extensions"
|
label="Select extensions to install"
|
||||||
onClick={this.selectLocalExtensionsDialog}
|
onClick={this.selectLocalExtensionsDialog}
|
||||||
/>
|
/>
|
||||||
<p className="hint">
|
<p className="hint">
|
||||||
<Trans><b>Pro-Tip 1</b>: you can download NPM-package to local folder with</Trans>
|
<Trans><b>Pro-Tip 1</b>: you can download tarball from NPM via</Trans>
|
||||||
<Clipboard showNotification>
|
<Clipboard showNotification>
|
||||||
<code>npm pack %package-name</code>
|
<code>npm pack %package-name</code>
|
||||||
</Clipboard>
|
</Clipboard>
|
||||||
@ -202,10 +228,7 @@ export class Extensions extends React.Component {
|
|||||||
<PageLayout showOnTop className="Extensions" header={<h2>Extensions</h2>}>
|
<PageLayout showOnTop className="Extensions" header={<h2>Extensions</h2>}>
|
||||||
<DropFileInput onDropFiles={this.installOnDrop}>
|
<DropFileInput onDropFiles={this.installOnDrop}>
|
||||||
<WizardLayout infoPanel={this.renderInfo()}>
|
<WizardLayout infoPanel={this.renderInfo()}>
|
||||||
<Input
|
<SearchInput
|
||||||
autoFocus
|
|
||||||
theme="round-black"
|
|
||||||
className="SearchInput"
|
|
||||||
placeholder={_i18n._(t`Search extensions`)}
|
placeholder={_i18n._(t`Search extensions`)}
|
||||||
value={this.search}
|
value={this.search}
|
||||||
onChange={(value) => this.search = value}
|
onChange={(value) => this.search = value}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { action, observable } from "mobx";
|
import { action, observable } from "mobx";
|
||||||
import { autobind } from "../../utils";
|
import { autobind } from "../../utils";
|
||||||
import isObject from "lodash/isObject";
|
|
||||||
import uniqueId from "lodash/uniqueId";
|
import uniqueId from "lodash/uniqueId";
|
||||||
import { JsonApiErrorParsed } from "../../api/json-api";
|
import { JsonApiErrorParsed } from "../../api/json-api";
|
||||||
|
|
||||||
@ -23,21 +22,25 @@ export interface Notification {
|
|||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
export class NotificationsStore {
|
export class NotificationsStore {
|
||||||
public notifications = observable<Notification>([], { deep: false });
|
public notifications = observable.array<Notification>([], { deep: false });
|
||||||
|
|
||||||
protected autoHideTimers = new Map<NotificationId, number>();
|
protected autoHideTimers = new Map<NotificationId, number>();
|
||||||
|
|
||||||
addAutoHideTimer(notification: Notification) {
|
getById(id: NotificationId): Notification | null {
|
||||||
this.removeAutoHideTimer(notification);
|
return this.notifications.find(item => item.id === id) ?? null;
|
||||||
const { id, timeout } = notification;
|
}
|
||||||
if (timeout) {
|
|
||||||
const timer = window.setTimeout(() => this.remove(id), timeout);
|
addAutoHideTimer(id: NotificationId) {
|
||||||
|
const notification = this.getById(id);
|
||||||
|
if (!notification) return;
|
||||||
|
this.removeAutoHideTimer(id);
|
||||||
|
if (notification.timeout) {
|
||||||
|
const timer = window.setTimeout(() => this.remove(id), notification.timeout);
|
||||||
this.autoHideTimers.set(id, timer);
|
this.autoHideTimers.set(id, timer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
removeAutoHideTimer(notification: Notification) {
|
removeAutoHideTimer(id: NotificationId) {
|
||||||
const { id } = notification;
|
|
||||||
if (this.autoHideTimers.has(id)) {
|
if (this.autoHideTimers.has(id)) {
|
||||||
clearTimeout(this.autoHideTimers.get(id));
|
clearTimeout(this.autoHideTimers.get(id));
|
||||||
this.autoHideTimers.delete(id);
|
this.autoHideTimers.delete(id);
|
||||||
@ -45,22 +48,24 @@ export class NotificationsStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
add(notification: Notification) {
|
add(notification: Notification): () => void {
|
||||||
if (!notification.id) {
|
const id = notification.id ?? (
|
||||||
notification.id = uniqueId("notification_");
|
notification.id = uniqueId("notification_")
|
||||||
|
);
|
||||||
|
const index = this.notifications.findIndex(item => item.id === id);
|
||||||
|
if (index > -1) {
|
||||||
|
this.notifications.splice(index, 1, notification); // update existing with same id
|
||||||
|
} else {
|
||||||
|
this.notifications.push(notification); // add new
|
||||||
}
|
}
|
||||||
const index = this.notifications.findIndex(item => item.id === notification.id);
|
this.addAutoHideTimer(id);
|
||||||
if (index > -1) this.notifications.splice(index, 1, notification);
|
return () => this.remove(id);
|
||||||
else this.notifications.push(notification);
|
|
||||||
this.addAutoHideTimer(notification);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
remove(itemOrId: NotificationId | Notification) {
|
remove(id: NotificationId) {
|
||||||
if (!isObject(itemOrId)) {
|
this.removeAutoHideTimer(id);
|
||||||
itemOrId = this.notifications.find(item => item.id === itemOrId);
|
this.notifications.remove(this.getById(id));
|
||||||
}
|
|
||||||
return this.notifications.remove(itemOrId as Notification);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { reaction } from "mobx";
|
|||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { JsonApiErrorParsed } from "../../api/json-api";
|
import { JsonApiErrorParsed } from "../../api/json-api";
|
||||||
import { cssNames, prevDefault } from "../../utils";
|
import { cssNames, prevDefault } from "../../utils";
|
||||||
import { NotificationMessage, Notification, notificationsStore, NotificationStatus } from "./notifications.store";
|
import { Notification, NotificationMessage, notificationsStore, NotificationStatus } from "./notifications.store";
|
||||||
import { Animate } from "../animate";
|
import { Animate } from "../animate";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
|
|
||||||
@ -75,16 +75,16 @@ export class Notifications extends React.Component {
|
|||||||
<Animate key={id}>
|
<Animate key={id}>
|
||||||
<div
|
<div
|
||||||
className={cssNames("notification flex align-center", status)}
|
className={cssNames("notification flex align-center", status)}
|
||||||
onMouseLeave={() => addAutoHideTimer(notification)}
|
onMouseLeave={() => addAutoHideTimer(id)}
|
||||||
onMouseEnter={() => removeAutoHideTimer(notification)}>
|
onMouseEnter={() => removeAutoHideTimer(id)}>
|
||||||
<div className="box center">
|
<div className="box center">
|
||||||
<Icon material="info_outline" />
|
<Icon material="info_outline"/>
|
||||||
</div>
|
</div>
|
||||||
<div className="message box grow">{msgText}</div>
|
<div className="message box grow">{msgText}</div>
|
||||||
<div className="box center">
|
<div className="box center">
|
||||||
<Icon
|
<Icon
|
||||||
material="close" className="close"
|
material="close" className="close"
|
||||||
onClick={prevDefault(() => remove(notification))}
|
onClick={prevDefault(() => remove(id))}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user