Skip to content

Commit

Permalink
Add preference to deactivate file watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreSi committed Oct 12, 2023
1 parent 820e022 commit fd9b89a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
4 changes: 4 additions & 0 deletions newIDE/app/src/MainFrame/Preferences/PreferencesContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export type PreferencesValues = {|
newProjectsDefaultFolder: string,
newProjectsDefaultStorageProviderName: string,
useShortcutToClosePreviewWindow: boolean,
watchProjectFolderFilesForLocalProjects: boolean,
editorStateByProject: { [string]: { editorTabs: EditorTabsPersistedState } },
|};

Expand Down Expand Up @@ -292,6 +293,7 @@ export type Preferences = {|
|}) => ?InAppTutorialUserProgress,
setNewProjectsDefaultFolder: (newProjectsDefaultFolder: string) => void,
setUseShortcutToClosePreviewWindow: (enabled: boolean) => void,
setWatchProjectFolderFilesForLocalProjects: (enabled: boolean) => void,
getEditorStateForProject: (
projectId: string
) => ?{| editorTabs: EditorTabsPersistedState |},
Expand Down Expand Up @@ -343,6 +345,7 @@ export const initialPreferences = {
newProjectsDefaultFolder: app ? findDefaultFolder(app) : '',
newProjectsDefaultStorageProviderName: 'Cloud',
useShortcutToClosePreviewWindow: true,
watchProjectFolderFilesForLocalProjects: true,
editorStateByProject: {},
},
setLanguage: () => {},
Expand Down Expand Up @@ -401,6 +404,7 @@ export const initialPreferences = {
setNewProjectsDefaultFolder: () => {},
setNewProjectsDefaultStorageProviderName: () => {},
setUseShortcutToClosePreviewWindow: () => {},
setWatchProjectFolderFilesForLocalProjects: () => {},
getEditorStateForProject: projectId => {},
setEditorStateForProject: (projectId, editorState) => {},
};
Expand Down
17 changes: 17 additions & 0 deletions newIDE/app/src/MainFrame/Preferences/PreferencesDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const PreferencesDialog = ({ i18n, onClose }: Props) => {
setUse3DEditor,
setNewProjectsDefaultFolder,
setUseShortcutToClosePreviewWindow,
setWatchProjectFolderFilesForLocalProjects,
} = React.useContext(PreferencesContext);

const initialUse3DEditor = React.useRef<boolean>(values.use3DEditor);
Expand Down Expand Up @@ -340,6 +341,22 @@ const PreferencesDialog = ({ i18n, onClose }: Props) => {
</Trans>
}
/>
{!!electron && (
<Toggle
onToggle={(e, check) =>
setWatchProjectFolderFilesForLocalProjects(check)
}
toggled={values.watchProjectFolderFilesForLocalProjects}
labelPosition="right"
label={
<Trans>
Watch the project folder for file changes in order to refresh
the resources used in the editor (images, 3D models, fonts,
etc.)
</Trans>
}
/>
)}
<Toggle
onToggle={(e, check) => setUse3DEditor(check)}
toggled={values.use3DEditor}
Expand Down
15 changes: 15 additions & 0 deletions newIDE/app/src/MainFrame/Preferences/PreferencesProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ export default class PreferencesProvider extends React.Component<Props, State> {
setUseShortcutToClosePreviewWindow: this._setUseShortcutToClosePreviewWindow.bind(
this
),
setWatchProjectFolderFilesForLocalProjects: this._setWatchProjectFolderFilesForLocalProjects.bind(
this
),
getEditorStateForProject: this._getEditorStateForProject.bind(this),
setEditorStateForProject: this._setEditorStateForProject.bind(this),
};
Expand Down Expand Up @@ -820,6 +823,18 @@ export default class PreferencesProvider extends React.Component<Props, State> {
);
}

_setWatchProjectFolderFilesForLocalProjects(enable: boolean) {
this.setState(
state => ({
values: {
...state.values,
watchProjectFolderFilesForLocalProjects: enable,
},
}),
() => this._persistValuesToLocalStorage(this.state)
);
}

_getEditorStateForProject(projectId: string) {
return this.state.values.editorStateByProject[projectId];
}
Expand Down
27 changes: 25 additions & 2 deletions newIDE/app/src/MainFrame/ResourcesWatcher.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
// @flow
import * as React from 'react';
import ResourcesLoader from '../ResourcesLoader';