Skip to content

Commit

Permalink
[v1.7.0-pre7] Merge pull request #216 from bridge-core/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
solvedDev authored Jun 15, 2020
2 parents 8195e21 + 39d00de commit 0cc4e98
Show file tree
Hide file tree
Showing 421 changed files with 3,488 additions and 593 deletions.
13 changes: 9 additions & 4 deletions app/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
:style="{
background: $vuetify.theme.themes[theme_variant].background,
fontSize: $store.state.Settings.ui_font_size || '14px',
fontFamily: $store.state.Settings.ui_font_family || 'Roboto, sans-serif',
fontFamily:
$store.state.Settings.ui_font_family || 'Roboto, sans-serif',
}"
>
<Toolbar />
<SidebarNavigation />

<v-content :style="`padding-bottom: 32px;`">
<v-main :style="`padding-bottom: 32px;`">
<v-row style="height: 100%;" no-gutters>
<v-col v-if="isSidebarOpen" cols="2">
<SidebarMain />
Expand All @@ -33,12 +34,16 @@
<EditorShellTabSystem />
<EditorShellContentManager />
</v-col>
<v-col @click="setSplitScreen(true)" v-if="has_split_screen" :cols="5 + 1 * !isSidebarOpen">
<v-col
@click="setSplitScreen(true)"
v-if="has_split_screen"
:cols="5 + 1 * !isSidebarOpen"
>
<EditorShellTabSystem :split_screen="true" />
<EditorShellContentManager :split_screen="true" />
</v-col>
</v-row>
</v-content>
</v-main>

<WindowFactoryMain />
<ContextMenuMain />
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/src/FileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export default class FileSystem {
else this.openDir(file_path, is_immutable)
}
static async openFile(file_path: string, is_immutable = false) {
if (TabSystem.isOpen(file_path, true)) return
if (TabSystem.isOpen(file_path, true))
return Store.commit('removeLoadingWindow', { id: 'open-file' })

let file: Buffer
try {
Expand Down
7 changes: 6 additions & 1 deletion app/renderer/src/TabSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ class TabSystem {
//Closing tab
internalCloseId(id: number, project = this.project) {
//Remove same folder display
const { file_path, file_name } = this.projects[this.project][id]
const { file_path, file_name, content } = this.projects[this.project][
id
]
for (let i = 0; i < this.projects[this.project].length; i++) {
if (id === i) continue
const {
Expand All @@ -214,6 +216,9 @@ class TabSystem {
}
}

//Dipose JSONTree
if (content instanceof JSONTree) content.dispose()

const [removed] = this.projects[project].splice(id, 1)
//Dispose monaco model
editor.getModel(Uri.file(removed.file_path))?.dispose()
Expand Down
9 changes: 4 additions & 5 deletions app/renderer/src/UI/Editor/JsonEditor/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@
</div>
<v-divider v-if="first && !is_immutable"></v-divider>
<v-layout class="controls" v-if="first && !is_immutable">
<template
v-if="
<template v-if="
$store.state.Settings.bridge_predictions &&
isKnownFileType()
"
>
">
<predicting-input
:render_object="render_object"
:tab_id="tab_id"
Expand Down Expand Up @@ -240,7 +238,8 @@ export default {
if (this.first && !this.compiled) {
let tree = InternalJSON.Format.toTree(
this.object,
this.current_file_path
this.current_file_path,
!this.is_immutable
)
TabSystem.setTabCompiled(true)
Expand Down
12 changes: 10 additions & 2 deletions app/renderer/src/UI/Editor/TabSystem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
>
<v-tab
v-for="(file, i) in open_files"
:key="`${selected_project}-${i}-${unsaved.join()}`"
:key="`${selected_project}-${i}-${unsaved.join()}-${file.content.isLoadingMetaData}`"
:ripple="!isSelected(i)"
:class="`tab ${isSelected(i) ? 'selected' : ''}`"
:style="
Expand All @@ -34,8 +34,16 @@
>
<v-icon small>mdi-book-open-page-variant</v-icon>
</v-btn>

<v-tooltip v-if="file.content.isLoadingMetaData" color="tooltip" right>
<template v-slot:activator="{ on }">
<v-progress-circular v-on="on" indeterminate :size="14" :width="2" color="primary" />
</template>
<span>Validating file...</span>
</v-tooltip>

<v-icon
v-if="getIcon(file.file_path)"
v-else-if="getIcon(file.file_path)"
:color="isSelected(i) ? 'primary' : undefined"
small
>{{ getIcon(file.file_path) }}</v-icon>
Expand Down
9 changes: 0 additions & 9 deletions app/renderer/src/UI/Toolbar/Menu/MenuList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,3 @@ export default {
},
}
</script>

<style>
/**
"tile" prop isn't working on v-menu -> manually tweak menu to not have border radius
*/
.v-menu__content {
border-radius: 0;
}
</style>
36 changes: 20 additions & 16 deletions app/renderer/src/Utilities/JsonFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,55 @@ import fs from 'fs'
import cJSON from 'comment-json'
import FileType from '../editor/FileType'

export function readJSON(path: string): Promise<any> {
export function readJSON(filePath: string): Promise<any> {
return new Promise((resolve, reject) => {
fs.readFile(path, (err, data) => {
fs.readFile(filePath, (err, buffer) => {
if (err) return reject(err)
try {
resolve(cJSON.parse(data.toString('utf-8'), undefined, true))
resolve(cJSON.parse(buffer.toString('utf-8'), undefined, true))
} catch (e) {
reject(e)
}
})
})
}
export function writeJSON(
path: string,
filePath: string,
data: any,
beautify = false,
file_version?: number
fileVersion?: number
) {
let to_save: any
if (file_version === undefined) {
to_save = JSON.stringify(data, null, beautify ? '\t' : undefined)
let toSave: string
if (fileVersion === undefined) {
toSave = JSON.stringify(data, null, beautify ? '\t' : undefined)
} else {
to_save = `${FileType.getCommentChar(
path
)}bridge-file-version: #${file_version}\n${JSON.stringify(
toSave = `${FileType.getCommentChar(
filePath
)}bridge-file-version: #${fileVersion}\n${JSON.stringify(
data,
null,
beautify ? '\t' : undefined
)}`
}

return new Promise((resolve, reject) => {
fs.writeFile(path, to_save, err => {
fs.writeFile(filePath, toSave, err => {
if (err) reject(err)
else resolve()
})
})
}

export function readJSONSync(path: string) {
return cJSON.parse(fs.readFileSync(path).toString('utf-8'), undefined, true)
export function readJSONSync(filePath: string) {
return cJSON.parse(
fs.readFileSync(filePath).toString('utf-8'),
undefined,
true
)
}
export function writeJSONSync(path: string, data: any, beautify = false) {
export function writeJSONSync(filePath: string, data: any, beautify = false) {
fs.writeFileSync(
path,
filePath,
JSON.stringify(data, null, beautify ? '\t' : undefined)
)
}
4 changes: 2 additions & 2 deletions app/renderer/src/editor/Json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export class Format {
return private_toJSON(tree, build_arrays, default_build_arrays)
}

static toTree(obj: any, file_path = '') {
static toTree(obj: any, file_path = '', validateFile = true) {
let tree = new JSONTree('global').buildFromObject(obj)
tree.loadMeta(file_path, true)
if (validateFile) tree.loadMeta(file_path, true)
return tree
}
}
Expand Down
28 changes: 25 additions & 3 deletions app/renderer/src/editor/JsonTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import { ENV } from './ScriptRunner/Validation/ENV'
import { runValidationFile } from './ScriptRunner/Validation/runFile'
import { canBeMinified, getCacheData } from './JSONTree/cacheUtils'
import { trigger } from '../AppCycle/EventSystem'
import EventBus from '../EventBus'

declare const requestIdleCallback: (func: () => void) => void

declare const requestIdleCallback: (func: () => void) => number
declare const cancelIdleCallback: (id: number) => void
let PROVIDER: Provider

export class TreeIterator {
Expand Down Expand Up @@ -91,6 +92,7 @@ export default class JSONTree {
is_active = true //Whether to output the tree to the final JSON file upon saving
uuid: string
meta: any
cancelCallbacks = new Set<number>()
on = {
change: new Map<JSONTree, () => void>(),
destroy: new Map<JSONTree, () => void>(),
Expand Down Expand Up @@ -192,7 +194,19 @@ export default class JSONTree {
}
return false
}
get isLoadingMetaData() {
if (this.cancelCallbacks.size > 0) return true

for (const c of this.children) {
if (c.isLoadingMetaData) return true
}
return false
}

dispose() {
this.cancelCallbacks.forEach(id => cancelIdleCallback(id))
this.children.forEach(c => c.dispose())
}
updateUUID() {
this.uuid = uuidv4()

Expand Down Expand Up @@ -464,7 +478,15 @@ export default class JSONTree {

this.addMeta(PROVIDER.getMeta(this.path, file_path, this), file_path)

if (deep) this.children.forEach(c => c.loadMeta(file_path, true))
if (deep)
this.children.forEach(c => {
const id = requestIdleCallback(() => {
c.loadMeta(file_path, true)
this.cancelCallbacks.delete(id)
EventBus.trigger('updateTabUI')
})
this.cancelCallbacks.add(id)
})
this.updateUUID()
}
/**
Expand Down
29 changes: 17 additions & 12 deletions app/renderer/src/plugins/PluginLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
set as setDisposables,
} from './Disposables'
import { executeScript } from './scripts/execute'
import { createEnv, createLimitedEnv } from './scripts/require'

let PLUGIN_FOLDERS: string[]
let PLUGIN_DATA: any[] = []
Expand Down Expand Up @@ -350,25 +351,29 @@ export default class PluginLoader {
if (fileContent === undefined) return

const promises: Promise<unknown>[] = []

try {
run(
await run(
fileContent,
{
register: (c: any) =>
promises.push(ComponentRegistry.register(c)),
report: (info: string) =>
new InformationWindow('Information', info, false),
},
[
createLimitedEnv(),
{
register: (c: any) =>
promises.push(ComponentRegistry.register(c)),
report: (info: string) =>
new InformationWindow('Information', info, false),
},
],
{
executionContext: 'file',
envName: 'require, Bridge',
async: true,
}
)
} catch (e) {
new InformationWindow(
'ERROR',
`Error while loading custom component:\n${e.message}`
)
} catch (err) {
createErrorNotification(err)
}

await Promise.all(promises)
}

Expand Down
2 changes: 1 addition & 1 deletion app/renderer/src/plugins/scripts/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function executeScript(
uiStore: TUIStore,
disposables: IDisposable[]
) {
return await run(code, createEnv(uiStore, disposables), {
return await run(code, createEnv(disposables, uiStore), {
executionContext: 'file',
envName: 'require',
async: true,
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/src/plugins/scripts/modules/ui.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { IModuleConfig } from '../types'

export const UIModule = ({ uiStore }: IModuleConfig) => uiStore.UI
export const UIModule = ({ uiStore }: IModuleConfig) => uiStore?.UI
26 changes: 24 additions & 2 deletions app/renderer/src/plugins/scripts/require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,32 @@ const BuiltInModules = new Map<string, (config: IModuleConfig) => unknown>([
['@bridge/utils', UtilsModule],
['@bridge/file-importer', ImportFileModule],
])
//For usage inside of custom commands, components etc.
const LimitedModules = new Map<string, (config: IModuleConfig) => unknown>([
['@bridge/notification', NotificationModule],
['@bridge/fs', FSModule],
['@bridge/path', PathModule],
['@bridge/env', ENVModule],
['@bridge/utils', UtilsModule],
])

export function createEnv(uiStore: TUIStore, disposables: IDisposable[]) {
function createGenericEnv(
disposables: IDisposable[] = [],
uiStore?: TUIStore,
modules = BuiltInModules
) {
return async (importName: string) => {
const module = BuiltInModules.get(importName)
const module = modules.get(importName)
if (module) return module({ uiStore, disposables })
}
}

export function createEnv(disposables: IDisposable[] = [], uiStore?: TUIStore) {
return createGenericEnv(disposables, uiStore)
}
export function createLimitedEnv(
disposables: IDisposable[] = [],
uiStore?: TUIStore
) {
return createGenericEnv(disposables, uiStore, LimitedModules)
}
2 changes: 1 addition & 1 deletion app/renderer/src/plugins/scripts/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { IDisposable } from '../../Types/disposable'
import { TUIStore } from '../UI/store'

export interface IModuleConfig {
uiStore: TUIStore
uiStore?: TUIStore
disposables: IDisposable[]
}
4 changes: 2 additions & 2 deletions app/renderer/store/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ function setup() {

//Upgrade old settings files
if (DATA.id === undefined) save({ id: uuid() })
if (DATA.text_auto_completions === undefined)
save({ text_auto_completions: true })
if (DATA.run_error_detection === undefined)
save({ run_error_detection: true })
if (DATA.load_packs_from_worlds === undefined)
save({ load_packs_from_worlds: true })
if (DATA.text_auto_completions !== undefined)
save({ text_auto_completions: undefined })
}
function save(settings: { [s: string]: any }) {
if (DATA) DATA = Object.assign(DATA, settings)
Expand Down
Loading

0 comments on commit 0cc4e98

Please sign in to comment.