UNPKG

flipper-plugin

Version:

Flipper Desktop plugin SDK and components

81 lines 3.3 kB
"use strict"; /** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.suggestNewPlugin = void 0; const antd_1 = require("antd"); const React = __importStar(require("react")); const FlipperLib_1 = require("../plugin/FlipperLib"); const suggestNewPlugin = ({ newPluginGK, newPluginId, newPluginName, legacyPluginId, legacyPluginName, client, }) => { if (newPluginGK && !(0, FlipperLib_1.getFlipperLib)().GK(newPluginGK)) { return; } const lastShownTimestampKey = `${legacyPluginId}-${newPluginId}-BannerLastShownTimestamp`; let lastShownTimestampFromStorage = undefined; try { lastShownTimestampFromStorage = window.localStorage.getItem(lastShownTimestampKey); } catch (e) { } if (lastShownTimestampFromStorage) { const WithinOneDay = (timestamp) => { const Day = 1 * 24 * 60 * 60 * 1000; const DayAgo = Date.now() - Day; return timestamp > DayAgo; }; const lastShownTimestamp = Number(lastShownTimestampFromStorage); if (WithinOneDay(lastShownTimestamp)) { // The banner was shown less than 24-hours ago, don't show it again. return; } } const lastShownTimestamp = Date.now(); try { window.localStorage.setItem(lastShownTimestampKey, String(lastShownTimestamp)); } catch (e) { } const key = `open-${newPluginId}-${lastShownTimestamp}`; const btn = (React.createElement(antd_1.Button, { type: "primary", size: "small", onClick: () => { antd_1.notification.close(key); client.selectPlugin(newPluginId, undefined); } }, "Try it now!")); antd_1.notification.open({ message: `${legacyPluginName} plugin is being deprecated.`, description: `The new replacement plugin, ${newPluginName}, is available for use now. Find it on the left panel`, duration: 30, type: 'warning', btn, key, }); }; exports.suggestNewPlugin = suggestNewPlugin; //# sourceMappingURL=SuggestNewPlugin.js.map