- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
read out header-includes from PanWriterUserData/{document-type}.yaml
Showing
8 changed files
with
84 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { readFile } from 'fs/promises' | ||
import * as jsYaml from 'js-yaml' | ||
import { app } from 'electron' | ||
import { basename, sep } from 'path' | ||
import { Meta } from '../src/appState/AppState' | ||
|
||
export const dataDir = [app.getPath('appData'), 'PanWriterUserData', ''].join(sep) | ||
|
||
/** | ||
* reads the right default yaml file | ||
* make sure this function is safe to expose in `preload.ts` | ||
*/ | ||
export const readDataDirFile = async (fileName: string): Promise<[Meta | undefined, string]> => { | ||
try { | ||
// make sure only PanWriterUserData directory can be accessed | ||
fileName = dataDir + basename(fileName) | ||
|
||
const str = await readFile(fileName, 'utf8') | ||
const yaml = jsYaml.safeLoad(str) | ||
return [ | ||
typeof yaml === 'object' ? (yaml as Meta) : {}, | ||
fileName | ||
] | ||
} catch(e) { | ||
console.warn("Error loading or parsing YAML file." + e.message) | ||
return [ undefined, fileName ] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters