1
1
// import fse from 'fs-extra';
2
2
import path from 'path' ;
3
+ import { requestUrl } from 'obsidian' ;
3
4
import { app , BrowserWindow , BrowserWindowConstructorOptions , dialog , MessageBoxOptions , screen , shell } from 'electron' ;
4
5
import { machineId } from 'node-machine-id' ;
5
6
import os from 'os' ;
6
7
import { createHash } from 'crypto' ;
7
8
import { v4 } from 'uuid' ;
8
9
import { AppHostServerUrl } from './remoteForS3' ;
9
10
import { loadGA } from './ga' ;
11
+ import type InvioPlugin from './main' ;
12
+ import { DEFAULT_DIR , DEFAULT_FILE_URL } from './settings' ;
13
+ import { mkdirpInVault } from './misc'
10
14
11
15
const logger = console ;
12
16
logger . info = console . log ;
@@ -78,7 +82,41 @@ const gotoAuth = (url?: string) => {
78
82
const gotoMainSite = ( ) => {
79
83
( window as any ) . electron . remote . shell . openExternal ( AppHostServerUrl ) ;
80
84
}
81
-
85
+
86
+ const mockLocaleFile = async ( plugin :InvioPlugin ) => {
87
+ let defaultFolder = DEFAULT_DIR
88
+ const existed = await plugin . app . vault . adapter . exists ( defaultFolder )
89
+ if ( existed ) {
90
+ defaultFolder += `_${ Math . random ( ) . toFixed ( 4 ) . slice ( 2 ) } `
91
+ }
92
+ plugin . app . vault . adapter . mkdir ( defaultFolder )
93
+ . then ( ( ) => {
94
+ plugin . settings . localWatchDir = defaultFolder
95
+ return plugin . saveSettings ( )
96
+ } )
97
+ . then ( ( ) => {
98
+ plugin . ga . trace ( 'boot_project' , {
99
+ dirname : plugin . settings . localWatchDir
100
+ } ) ;
101
+ plugin . switchWorkingDir ( plugin . settings . localWatchDir ) ;
102
+ } )
103
+ . then ( async ( ) => {
104
+ // Add a new file
105
+ const arrayBuffer = await requestUrl ( {
106
+ url : DEFAULT_FILE_URL
107
+ } ) . then ( resp => resp . arrayBuffer )
108
+ return plugin . app . vault . adapter . writeBinary ( `${ defaultFolder } /Introduction.md` , arrayBuffer )
109
+ } )
110
+ . then ( async ( ) => {
111
+ const created = await plugin . app . vault . adapter . exists ( `${ defaultFolder } /Introduction.md` ) ;
112
+ if ( created ) {
113
+ let parentNode : any = document . querySelector ( `[data-path="${ defaultFolder } "]` ) ;
114
+ parentNode ?. click ( ) ;
115
+ let node : any = document . querySelector ( `[data-path="${ defaultFolder } /Introduction.md"]` ) ;
116
+ node ?. click ( ) ;
117
+ }
118
+ } )
119
+ }
82
120
const Utils = {
83
121
md5Hash,
84
122
getAppPath,
@@ -89,6 +127,7 @@ const Utils = {
89
127
showNotification,
90
128
gotoAuth,
91
129
gotoMainSite,
130
+ mockLocaleFile,
92
131
// getTracert
93
132
} ;
94
133
0 commit comments