mirror of
https://github.com/anyproto/anytype-ts.git
synced 2025-06-08 05:57:02 +09:00
JS-1130: storage path
This commit is contained in:
parent
fb3b4be119
commit
31cfe3fb73
13 changed files with 67 additions and 91 deletions
40
electron.js
40
electron.js
|
@ -9,10 +9,6 @@ const protocol = 'anytype';
|
|||
const remote = require('@electron/remote/main');
|
||||
const binPath = fixPathForAsarUnpack(path.join(__dirname, 'dist', `anytypeHelper${is.windows ? '.exe' : ''}`));
|
||||
|
||||
if (is.development) {
|
||||
app.setPath('userData', path.join(app.getPath('userData'), '_dev'));
|
||||
};
|
||||
|
||||
// Fix notifications app name
|
||||
if (is.windows) {
|
||||
app.setAppUserModelId(app.name);
|
||||
|
@ -26,9 +22,6 @@ const WindowManager = require('./electron/js/window.js');
|
|||
const Server = require('./electron/js/server.js');
|
||||
const Util = require('./electron/js/util.js');
|
||||
const Cors = require('./electron/json/cors.json');
|
||||
|
||||
const userPath = Util.userPath();
|
||||
const logPath = Util.logPath();
|
||||
const csp = [];
|
||||
|
||||
for (let i in Cors) {
|
||||
|
@ -72,19 +65,32 @@ if (app.isPackaged && !app.requestSingleInstanceLock()) {
|
|||
};
|
||||
|
||||
remote.initialize();
|
||||
storage.setDataPath(userPath);
|
||||
Util.setAppPath(path.join(__dirname));
|
||||
Util.mkDir(logPath);
|
||||
|
||||
if (process.env.ANYTYPE_USE_SIDE_SERVER) {
|
||||
// use the grpc server started from the outside
|
||||
Server.setAddress(process.env.ANYTYPE_USE_SIDE_SERVER);
|
||||
waitLibraryPromise = Promise.resolve();
|
||||
} else {
|
||||
waitLibraryPromise = Server.start(binPath, userPath);
|
||||
};
|
||||
|
||||
function waitForLibraryAndCreateWindows () {
|
||||
let userDataPath = ConfigManager.config.userDataPath || app.getPath('userData');
|
||||
|
||||
console.log('userDataPath1', userDataPath);
|
||||
|
||||
if (is.development) {
|
||||
userDataPath = path.join(userDataPath, '_dev');
|
||||
};
|
||||
|
||||
console.log('userDataPath2', userDataPath);
|
||||
|
||||
app.setPath('userData', userDataPath);
|
||||
storage.setDataPath(userDataPath);
|
||||
|
||||
if (process.env.ANYTYPE_USE_SIDE_SERVER) {
|
||||
// use the grpc server started from the outside
|
||||
Server.setAddress(process.env.ANYTYPE_USE_SIDE_SERVER);
|
||||
waitLibraryPromise = Promise.resolve();
|
||||
} else {
|
||||
waitLibraryPromise = Server.start(binPath, userDataPath);
|
||||
};
|
||||
|
||||
Util.mkDir(Util.logPath());
|
||||
|
||||
waitLibraryPromise.then(() => {
|
||||
global.serverAddress = Server.getAddress();
|
||||
createWindow();
|
||||
|
|
|
@ -209,6 +209,11 @@ class Api {
|
|||
};
|
||||
};
|
||||
|
||||
setUserDataPath (win, p) {
|
||||
this.setConfig(win, { userDataPath: p });
|
||||
app.setPath('userData', p);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
module.exports = new Api();
|
|
@ -357,7 +357,6 @@
|
|||
|
||||
"pageAuthDeletedAccountDeletionTitle": "This account is planned for deletion in %s",
|
||||
|
||||
"pageAuthOnboardAccountDataLocation": "Account Data Location",
|
||||
"pageAuthOnboardPersonalSpace": "Personal Space",
|
||||
"pageAuthOnboardMoreInfo": "More info",
|
||||
|
||||
|
@ -714,6 +713,7 @@
|
|||
|
||||
"popupSettingsOnboardingModeTitle": "Network",
|
||||
"popupSettingsOnboardingNetworkTitle": "Self-hosted Configuration",
|
||||
"popupSettingsOnboardingStoragePath": "Data path",
|
||||
|
||||
"networkMode0Title": "Anytype",
|
||||
"networkMode0Text": "Back up to the network managed by Anytype",
|
||||
|
|
|
@ -201,14 +201,7 @@ html.bodyAuthDeleted {
|
|||
.frame { display: flex; flex-direction: column; align-items: center; }
|
||||
.title { @include text-header3; color: var(--color-text-primary); }
|
||||
.label { @include text-paragraph; color: var(--color-text-secondary); }
|
||||
|
||||
.bottom { position: fixed; bottom: 24px; left: 0; right: 0; display: flex; flex-direction: row; justify-content: center; align-items: center; gap: 0px 6px; opacity: 0.6; }
|
||||
.bottom {
|
||||
.icon { background-image: url('~img/icon/footer/gear0.svg'); }
|
||||
}
|
||||
.bottom:hover {
|
||||
.icon { background-image: url('~img/icon/footer/gear1.svg'); }
|
||||
}
|
||||
}
|
||||
|
||||
.pageAuthOnboard, .pageAuthLogin {
|
||||
|
@ -229,13 +222,6 @@ html.bodyAuthDeleted {
|
|||
.label { width: 415px; }
|
||||
.button { min-width: 192px; width: auto; }
|
||||
|
||||
.icon.gear { background-image: url('~img/icon/footer/gear0.svg'); height: 20px; width: 20px; }
|
||||
|
||||
#accountPath { display: flex; align-items: center; flex-direction: row; gap: 0px 6px; }
|
||||
#accountPath:hover {
|
||||
.icon.gear { background-image: url('~img/icon/footer/gear1.svg'); }
|
||||
}
|
||||
|
||||
.tooltipLink { color: var(--color-text-primary); }
|
||||
.tooltipLink:hover { text-decoration: underline; }
|
||||
|
||||
|
|
|
@ -317,7 +317,6 @@ class App extends React.Component<object, State> {
|
|||
commonStore.themeSet(config.theme);
|
||||
commonStore.languagesSet(languages);
|
||||
|
||||
authStore.walletPathSet(dataPath);
|
||||
authStore.accountPathSet(dataPath);
|
||||
|
||||
analytics.init();
|
||||
|
|
|
@ -33,11 +33,11 @@ const PageAccountSelect = observer(class PageAccountSelect extends React.Compone
|
|||
};
|
||||
|
||||
componentDidMount () {
|
||||
const { walletPath, phrase } = authStore;
|
||||
const { accountPath, phrase } = authStore;
|
||||
|
||||
authStore.accountListClear();
|
||||
|
||||
C.WalletRecover(walletPath, phrase, () => {
|
||||
C.WalletRecover(accountPath, phrase, () => {
|
||||
UtilData.createSession(() => {
|
||||
C.AccountRecover((message) => {
|
||||
if (message.error.code) {
|
||||
|
|
|
@ -103,7 +103,7 @@ const PageAuthLogin = observer(class PageAuthLogin extends React.Component<I.Pag
|
|||
return;
|
||||
};
|
||||
|
||||
const { walletPath } = authStore;
|
||||
const { accountPath } = authStore;
|
||||
const phrase = this.refPhrase.getValue();
|
||||
const length = phrase.split(' ').length;
|
||||
|
||||
|
@ -113,7 +113,7 @@ const PageAuthLogin = observer(class PageAuthLogin extends React.Component<I.Pag
|
|||
|
||||
this.refSubmit?.setLoading(true);
|
||||
|
||||
C.WalletRecover(walletPath, phrase, (message: any) => {
|
||||
C.WalletRecover(accountPath, phrase, (message: any) => {
|
||||
if (this.setError({ ...message.error, description: translate('pageAuthLoginInvalidPhrase')})) {
|
||||
return;
|
||||
};
|
||||
|
@ -128,10 +128,10 @@ const PageAuthLogin = observer(class PageAuthLogin extends React.Component<I.Pag
|
|||
};
|
||||
|
||||
select () {
|
||||
const { account, walletPath, networkConfig } = authStore;
|
||||
const { account, accountPath, networkConfig } = authStore;
|
||||
const { mode, path } = networkConfig;
|
||||
|
||||
C.AccountSelect(account.id, walletPath, mode, path, (message: any) => {
|
||||
C.AccountSelect(account.id, accountPath, mode, path, (message: any) => {
|
||||
if (this.setError(message.error) || !message.account) {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -106,15 +106,6 @@ const PageAuthOnboard = observer(class PageAuthOnboard extends React.Component<I
|
|||
if (!phraseVisible) {
|
||||
more = <div className="moreInfo animation">{translate('authOnboardMoreInfo')}</div>;
|
||||
};
|
||||
|
||||
if (config.experimental) {
|
||||
footer = (
|
||||
<div id="accountPath" className="animation small bottom" onClick={this.onAccountPath}>
|
||||
<Icon className="gear" />
|
||||
{translate('pageAuthOnboardAccountDataLocation')}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
@ -272,10 +263,10 @@ const PageAuthOnboard = observer(class PageAuthOnboard extends React.Component<I
|
|||
accountCreate (callBack?: () => void) {
|
||||
this.refNext.setLoading(true);
|
||||
|
||||
const { name, walletPath, networkConfig } = authStore;
|
||||
const { name, accountPath, networkConfig } = authStore;
|
||||
const { mode, path } = networkConfig;
|
||||
|
||||
C.WalletCreate(walletPath, (message) => {
|
||||
C.WalletCreate(accountPath, (message) => {
|
||||
if (message.error.code) {
|
||||
this.setError(message.error.description);
|
||||
return;
|
||||
|
|
|
@ -92,7 +92,7 @@ const PageAuthSetup = observer(class PageAuthSetup extends React.Component<I.Pag
|
|||
|
||||
componentDidMount () {
|
||||
const { match } = this.props;
|
||||
const { account, walletPath } = authStore;
|
||||
const { account, accountPath } = authStore;
|
||||
|
||||
switch (match?.params?.id) {
|
||||
case 'init': {
|
||||
|
@ -101,7 +101,7 @@ const PageAuthSetup = observer(class PageAuthSetup extends React.Component<I.Pag
|
|||
};
|
||||
|
||||
case 'select': {
|
||||
this.select(account.id, walletPath, true);
|
||||
this.select(account.id, accountPath, true);
|
||||
break;
|
||||
};
|
||||
|
||||
|
@ -117,14 +117,14 @@ const PageAuthSetup = observer(class PageAuthSetup extends React.Component<I.Pag
|
|||
};
|
||||
|
||||
init () {
|
||||
const { walletPath, phrase } = authStore;
|
||||
const { accountPath, phrase } = authStore;
|
||||
const accountId = Storage.get('accountId');
|
||||
|
||||
if (!phrase) {
|
||||
return;
|
||||
};
|
||||
|
||||
C.WalletRecover(walletPath, phrase, (message: any) => {
|
||||
C.WalletRecover(accountPath, phrase, (message: any) => {
|
||||
if (this.setError(message.error)) {
|
||||
return;
|
||||
};
|
||||
|
@ -136,7 +136,7 @@ const PageAuthSetup = observer(class PageAuthSetup extends React.Component<I.Pag
|
|||
|
||||
if (accountId) {
|
||||
authStore.phraseSet(phrase);
|
||||
this.select(accountId, walletPath, false);
|
||||
this.select(accountId, accountPath, false);
|
||||
} else {
|
||||
UtilRouter.go('/auth/account-select', { replace: true });
|
||||
};
|
||||
|
@ -144,12 +144,12 @@ const PageAuthSetup = observer(class PageAuthSetup extends React.Component<I.Pag
|
|||
});
|
||||
};
|
||||
|
||||
select (accountId: string, walletPath: string, animate: boolean) {
|
||||
select (accountId: string, accountPath: string, animate: boolean) {
|
||||
const { networkConfig } = authStore;
|
||||
const { mode, path } = networkConfig;
|
||||
const spaceId = Storage.get('spaceId');
|
||||
|
||||
C.AccountSelect(accountId, walletPath, mode, path, (message: any) => {
|
||||
C.AccountSelect(accountId, accountPath, mode, path, (message: any) => {
|
||||
if (this.setError(message.error) || !message.account) {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -21,10 +21,7 @@ const PopupSettingsPageDataManagement = observer(class PopupSettingsPageStorageI
|
|||
render () {
|
||||
const { onPage } = this.props;
|
||||
const { localUsage } = commonStore.spaceStorage;
|
||||
const { walletPath, accountPath } = authStore;
|
||||
const { config } = commonStore;
|
||||
const localStorage = { name: translate('popupSettingsDataLocalFiles'), iconEmoji: ':desktop_computer:' };
|
||||
const canMove = config.experimental;
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
|
@ -45,19 +42,11 @@ const PopupSettingsPageDataManagement = observer(class PopupSettingsPageStorageI
|
|||
<Button color="blank" className="c28" text={translate('popupSettingsDataManagementOffloadFiles')} onClick={this.onOffload} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{canMove ? (
|
||||
<div id="row-location" className="item accountLocation" onClick={this.onLocationMove}>
|
||||
<Label text={translate('popupSettingsAccountMoveTitle')} />
|
||||
<Label className="locationLabel" text={walletPath == accountPath ? 'Default' : 'Custom'} />
|
||||
</div>
|
||||
) : ''}
|
||||
</div>
|
||||
|
||||
<Title className="sub" text={translate('popupSettingsDataManagementDeleteTitle')} />
|
||||
<Label className="description" text={translate('popupSettingsDataManagementDeleteText')} />
|
||||
<Button className="c36" onClick={() => { onPage('delete'); }} color="red" text={translate('popupSettingsDataManagementDeleteButton')} />
|
||||
|
||||
</React.Fragment>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -15,11 +15,13 @@ const PopupSettingsOnboarding = observer(class PopupSettingsOnboarding extends R
|
|||
this.onUpload = this.onUpload.bind(this);
|
||||
this.onSave = this.onSave.bind(this);
|
||||
this.onPathClick = this.onPathClick.bind(this);
|
||||
this.onChangeStorage = this.onChangeStorage.bind(this);
|
||||
};
|
||||
|
||||
render () {
|
||||
const { mode, path } = this.config;
|
||||
const { interfaceLang } = commonStore;
|
||||
const userPath = window.Electron.userPath;
|
||||
const interfaceLanguages = UtilMenu.getInterfaceLanguages();
|
||||
const networkModes: any[] = ([
|
||||
{ id: I.NetworkMode.Default },
|
||||
|
@ -72,13 +74,21 @@ const PopupSettingsOnboarding = observer(class PopupSettingsOnboarding extends R
|
|||
</div>
|
||||
{mode == I.NetworkMode.Custom ? (
|
||||
<div className="item">
|
||||
<div onClick={this.onPathClick}>
|
||||
<div onClick={() => this.onPathClick(path)}>
|
||||
<Label text={translate('popupSettingsOnboardingNetworkTitle')} />
|
||||
{path ? <Label className="small" text={UtilCommon.shorten(path, 32)} /> : ''}
|
||||
</div>
|
||||
<Button className="c28" text={translate('commonUpload')} onClick={this.onUpload} />
|
||||
</div>
|
||||
) : ''}
|
||||
|
||||
<div className="item">
|
||||
<div onClick={() => this.onPathClick(userPath)}>
|
||||
<Label text={translate('popupSettingsOnboardingStoragePath')} />
|
||||
<Label className="small" text={UtilCommon.shorten(userPath, 32)} />
|
||||
</div>
|
||||
<Button className="c28" text={translate('commonChange')} onClick={this.onChangeStorage} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="buttons">
|
||||
|
@ -119,14 +129,16 @@ const PopupSettingsOnboarding = observer(class PopupSettingsOnboarding extends R
|
|||
this.props.close();
|
||||
};
|
||||
|
||||
onPathClick () {
|
||||
const { path } = this.config;
|
||||
|
||||
if (path) {
|
||||
Renderer.send('pathOpen', window.Electron.dirname(path));
|
||||
};
|
||||
onPathClick (path: string) {
|
||||
Renderer.send('pathOpen', window.Electron.dirname(path));
|
||||
};
|
||||
|
||||
|
||||
onChangeStorage () {
|
||||
Action.openDir({}, (paths: string[]) => {
|
||||
Renderer.send('setUserDataPath', paths[0]);
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
export default PopupSettingsOnboarding;
|
||||
|
|
|
@ -341,11 +341,11 @@ class Action {
|
|||
};
|
||||
|
||||
restoreFromBackup (onError: (error: { code: number, description: string }) => boolean) {
|
||||
const { walletPath, networkConfig } = authStore;
|
||||
const { accountPath, networkConfig } = authStore;
|
||||
const { mode, path } = networkConfig;
|
||||
|
||||
this.openFile([ 'zip' ], paths => {
|
||||
C.AccountRecoverFromLegacyExport(paths[0], walletPath, UtilCommon.rand(1, Constant.iconCnt), (message: any) => {
|
||||
C.AccountRecoverFromLegacyExport(paths[0], accountPath, UtilCommon.rand(1, Constant.iconCnt), (message: any) => {
|
||||
if (onError(message.error)) {
|
||||
return;
|
||||
};
|
||||
|
@ -357,7 +357,7 @@ class Action {
|
|||
return;
|
||||
};
|
||||
|
||||
C.AccountSelect(accountId, walletPath, mode, path, (message: any) => {
|
||||
C.AccountSelect(accountId, accountPath, mode, path, (message: any) => {
|
||||
if (onError(message.error) || !message.account) {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -10,7 +10,6 @@ interface NetworkConfig {
|
|||
|
||||
class AuthStore {
|
||||
|
||||
public walletPathValue = '';
|
||||
public accountPathValue = '';
|
||||
public accountItem: I.Account = null;
|
||||
public accountList: I.Account[] = [];
|
||||
|
@ -21,18 +20,15 @@ class AuthStore {
|
|||
|
||||
constructor () {
|
||||
makeObservable(this, {
|
||||
walletPathValue: observable,
|
||||
accountPathValue: observable,
|
||||
accountItem: observable,
|
||||
accountList: observable,
|
||||
name: observable,
|
||||
phrase: observable,
|
||||
threadMap: observable,
|
||||
walletPath: computed,
|
||||
accountPath: computed,
|
||||
accounts: computed,
|
||||
account: computed,
|
||||
walletPathSet: action,
|
||||
accountPathSet: action,
|
||||
phraseSet: action,
|
||||
nameSet: action,
|
||||
|
@ -53,10 +49,6 @@ class AuthStore {
|
|||
return this.accountItem;
|
||||
};
|
||||
|
||||
get walletPath (): string {
|
||||
return String(this.walletPathValue || '');
|
||||
};
|
||||
|
||||
get accountPath (): string {
|
||||
return String(this.accountPathValue || '');
|
||||
};
|
||||
|
@ -74,10 +66,6 @@ class AuthStore {
|
|||
};
|
||||
};
|
||||
|
||||
walletPathSet (v: string) {
|
||||
this.walletPathValue = v;
|
||||
};
|
||||
|
||||
accountPathSet (v: string) {
|
||||
this.accountPathValue = v;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue