1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-08 05:57:02 +09:00
anytype-ts/electron/js/util.js
Razor 7c7b9ad43f
Feature/Onboarding (#2)
* merge fix

* merge fix

* merge fix

* erge fix

* merge fix

* removed old header; changed logo

* added moreInfo popup

* undoing changes to auth flow

* undoing changes to auth flow

* cleaned up branch, removing unrelated changes and undoing changes that make the PR hard to understand

* removed unrelated component

* reverted styling deletions for auth pages

* refactored onboarding component

* invite label should be wider

* shortened animation DELAY time

* added animation logic

* fixed mistype

* code review: enum keys should be UpperCamelCase

* code review: remove double quotes from code, double quotes are _only_ used in JSX attributes; fixed formatting; fixed inconsistent use of ;

* code review: change strong to b

* code review: inconsistent method naming, should be consistent ()

* code review: rename to phrase

* fixed formatting

* fixed animation timing

* code review: removed unnecessary functions

* removed register page, and all references to it have now been adjusted accordingly

* removed Register path from AuthSetup Page

* removed success page

* fixed authorization after account creation

* aded background for demo purposes

* changed Phrase -> KeyPhrase to avoid CSS class namespace collision

* removed old background animation code

* fixed merge issues

* finished integration

* added notes

* fix scss formatting

* initial commit

* implemented editable keyPhrase component

* fixed wrong classname

* fixed incorrect initialization of worker (cannot be passed as prop)

* finished login flow

* fixed animation error

* JS-1425: screen markup

* JS-1425: stash

* JS-1425: debugging wip

* JS-1425: usecase screen on registration done

* updated Delete Account page

* implemented new pincheck style

* Update pinCheck.tsx

fixed styling

* fixed pie chart implementation

* JS-1425: redirect to graph after usecase selection

* JS-1784: graph wizard

* code review

* added new onboarding animation; fixed merge issue

* fixes according to design review; minor refactor to preview lib

* JS-1425: url to system relations

* code review

* code review

* code review

* refactoring

* refactoring

* JS-1636: remove homeDashboardId and cover

* JS-1920: usecase screen darkmode

* JS-1828: placeholder color

* onboarding

* refactoring

* refactoring

* refactoring

* refactoring

* refactoring

* JS-1920: code review

* JS-1926: fix

* JS-1923: phrase input

* JS-1923: phrase input

* JS-1923: phrase input

* fixes

* code review

* remove onboarding call

* small refactoring

* small refactoring

* remove unused styles

* menu button and final imgs

* migration popup hidden

* remove migration popup

* first page title should be one line

* dot indicator should be 4pxx4px, and 2px margin (this makes the dots barely visible, but what do I know)

* Click on the phrase at this state should not reveal it, only click on the button should

* margin too big

* input should be focused just as this screen appeared

* let’s remove white pulsating background

* Soul icon should not disappear and re appear, it should just move and a space icon should appear

* fixed popups

* fixed popups and tooltips

* fixed tooltip not appearing

* MenuAccountPath restored

* revert tooltip change

* MenuAccountPath restored

* fixed jumping question mark

* fixed tooltip padding

* restored text select on keyPhrase

* update hovers

* color fixes

* refactored implementation of Phrase jumped around when visibility is toggled. the solution of setting css width based on number of characters in a word string doesn't work, characters are not all the same number of pixels. this solution maintains the same length for both visible and invisible states; additionally, the component is not compatible with longer phrases, leading to wrap-around. this is fixed

* added overflow for phrase component

* fixed changing top margin for Frame, because it doesnt align from step to step

* JS-1932: fix

* refactored Phrase; added support for placeholder

* fixed phrase jumping

* clear naming

* fixed animation step misalignment

* fixed back button; fixed step in animation

* fixing backwards button

* added fade in for the canvas element; added animation for the header and footer on the index page; changed the order of animation on index page by moving around jsx

* refactoring; adding error handling

* added types to refs

* refactored animation to have fine control over the order and delay duration for every stage; rewrote it to be declarative and easy to read; fixed vanishing title on soul creating stage

* fixed title spacing too tight on Soul Creating/Space Creating; Fixed all timing issues with animation mentioned in linear comments

* removed transition common property because it interferes with animation library

* fixed more info hover state; fixed animation of soul creating and space creating icons

* added fade in overlay to use case selection screen

* added fade in overlay to use case selection screen

* changed error handling in js-onboard-animation to fail safely

* fixed fade in overlay; fixed timing on animation

* fixed timing; button width should not vary, it’s 192 px wide

* fixed timing; added comments for all the durations to make it easy to change in the future

* phrase should have a cursor pointer when it blurred, cursor text appear when the words are visible and selectable

* phrase should have a cursor pointer when it blurred, cursor text appear when the words are visible and selectable

* phrase should not have a hover, only inputs have

* refactoring

* onboarding optimisations

* refactoring

* JS-2026: fix

* fixed merge

* fixed key phrase component paste behaviour

* made enter key work for the login screen

* hide phrase by default on login

* added animation to backbutton; disable click events and pointer events during animation stages to prevent interaction with UI while animation is in progress and elements arent visible yet

* fixed icon size; fix label and title colors; fixed border radius on space icon; fixed spacing on space and soul icons

* fixed blur being cutoff on the phrase

* fixed input padding

* JS-2061: remove migration popup

* fixed styles according to figma

* fixed screen resize styles

* changes design review

* fixed space animation

* slowed down last step of animation

* fix formatting

* fix formatting

* JS-2150: change auth flow

* uncomment animation

* JS-2223: remove invite code + merge

* remove registration

* fixes

* fixes

* JS-2247: fix

* JS-2250: fix

* JS-2255: fix

* fixes

* fixes

* fixes

* fixes

* fixes

* fixes

* Update usecase.scss

* fixes

* JS-2299: login fix

* preloader bg color

* phrase fixes

* usecase rubber resize

* JS-2029: usecase selection resize

* JS-2029: usecase selection resize

* dark mode

* fix navigation

* fix navigation

---------

Co-authored-by: Dragos Rotaru <dragos@rotaru.co>
Co-authored-by: Dragos Rotaru <7482137+DragosRotaru@users.noreply.github.com>
Co-authored-by: Mike Mhlv <mhlv@anytype.io>
2023-06-19 18:10:36 +02:00

210 lines
No EOL
5 KiB
JavaScript

const { app, shell, nativeTheme } = require('electron');
const { is } = require('electron-util');
const log = require('electron-log');
const path = require('path');
const fs = require('fs');
const sanitize = require('sanitize-filename');
const protocol = 'anytype';
const userPath = app.getPath('userData');
const ConfigManager = require('./config.js');
log.transports.rendererConsole.level = 'error';
class Util {
appPath = '';
setAppPath (value) {
this.appPath = value;
};
mkDir (value) {
if (value) {
try { fs.mkdirSync(value); } catch (e) {};
};
};
log (method, text) {
if (!log[method]) {
method = 'info';
};
log[method](text);
console.log(text);
};
dateForFile() {
return new Date().toISOString().replace(/:/g, '_').replace(/\..+/, '');
};
// MacOs 12.2 (M1): always returns false regardless current color theme
isDarkTheme () {
return nativeTheme.shouldUseDarkColors || nativeTheme.shouldUseHighContrastColors || nativeTheme.shouldUseInvertedColorScheme;
};
getRouteFromUrl (url) {
return url.replace(`${protocol}://`, '/');
};
getTheme () {
const theme = (undefined !== ConfigManager.config.theme) ? ConfigManager.config.theme : 'dark';
switch (theme) {
default:
return theme;
case 'system':
return this.isDarkTheme() ? 'dark' : '';
};
};
getBgColor (theme) {
let bg = {
'': '#fff',
dark: '#060606',
};
return bg[theme];
};
electronPath () {
return path.join(this.appPath, 'electron');
};
imagePath () {
return path.join(this.electronPath(), 'img');
};
dataPath () {
const { channel } = ConfigManager.config;
const dataPath = [];
if (process.env.DATA_PATH) {
this.mkDir(process.env.DATA_PATH);
dataPath.push(process.env.DATA_PATH);
} else {
dataPath.push(userPath);
if (is.development) {
dataPath.push('dev');
} else
if ([ 'alpha', 'beta' ].includes(channel)) {
dataPath.push(channel);
};
dataPath.push('data');
};
return path.join.apply(null, dataPath);
};
send () {
const args = [ ...arguments ];
const win = args[0];
if (win && win.webContents) {
args.shift();
win.webContents.send.apply(win.webContents, args);
};
};
printHtml (win, exportPath, name, options) {
const fn = `${name.replace(/\.html$/, '')}_files`;
const filesPath = path.join(exportPath, fn);
const exportName = path.join(exportPath, this.fileName(name));
try { fs.mkdirSync(filesPath); } catch (e) {};
win.webContents.savePage(exportName, 'HTMLComplete').then(() => {
let content = fs.readFileSync(exportName, 'utf8');
// Replace files loaded by url and copy them in page folder
try {
content = content.replace(/"(file:\/\/[^"]+)"/g, function (s, p, o) {
let a = p.split('app.asar/dist/');
let name = a[1].split('/');
name = name[name.length - 1];
let src = p.replace('file://', '').replace(/\?.*/, '').replace(/\/app.asar\//g, '/app.asar.unpacked/');
let dst = path.join(filesPath, name).replace(/\?.*/, '');
fs.copyFileSync(src, dst);
return `"./${fn}/${name}"`;
});
} catch (e) {
this.log('info', e);
};
content = content.replace(/<script[^>]+><\/script>/g, '');
try {
const css = [ 'export' ];
const js = [ 'export', 'jquery' ];
const ap = app.getAppPath();
let replaceJs = '';
let replaceCss = '';
let replaceMeta = `
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
`;
js.forEach(it => {
fs.copyFileSync(`${ap}/dist/js/${it}.js`, path.join(filesPath, it + '.js'));
replaceJs += `<script src="./${fn}/${it}.js" type="text/javascript"></script>`;
});
css.forEach(it => {
fs.copyFileSync(`${ap}/dist/css/${it}.css`, path.join(filesPath, it + '.css'));
replaceCss += `<link rel="stylesheet" href="./${fn}/${it}.css" type="text/css" />`;
});
content = content.replace('<!-- %REPLACE-JS% -->', replaceJs);
content = content.replace('</head>', replaceCss + '</head>');
content = content.replace('<head>', '<head>' + replaceMeta);
} catch (e) {
this.log('info', e);
};
fs.writeFileSync(exportName, content);
try {
fs.unlinkSync(path.join(filesPath, 'main.js'));
fs.unlinkSync(path.join(filesPath, 'run.js'));
} catch (e) {
this.log('info', e);
};
shell.openPath(exportPath).catch(err => {
this.log('info', err);
});
this.send(win, 'commandGlobal', 'saveAsHTMLSuccess');
}).catch(err => {
this.send(win, 'commandGlobal', 'saveAsHTMLSuccess');
this.log('info', err);
});
};
printPdf (win, exportPath, name, options) {
win.webContents.printToPDF(options).then(data => {
fs.writeFile(path.join(exportPath, this.fileName(name)), data, (error) => {
if (error) throw error;
shell.openPath(exportPath).catch(err => {
this.log('info', err);
});
this.send(win, 'commandGlobal', 'saveAsHTMLSuccess');
});
}).catch(err => {
this.send(win, 'commandGlobal', 'saveAsHTMLSuccess');
this.log('info', err);
});
};
fileName (name) {
return sanitize(String(name || 'untitled').trim());
};
};
module.exports = new Util();