-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Desktop: Install default plugins on first-app-start #6585
Changes from 7 commits
bd677c4
eb67977
302b380
d8d86f2
75d2601
4491cf0
84c02c9
8d61611
3c14807
191c8a5
32c003b
3536393
4aa26bc
78c2ac7
46007c5
ebde62b
4d05817
360de71
25820d3
b80c487
228aa96
aa3a5fa
343c4de
b68fd07
fbc1793
d1db3ec
53ddafb
4cc80d1
90dfd0d
a4fcf8e
6ef7c3d
5f6671d
d90dee1
263d33b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,12 +60,26 @@ class ConfigScreenComponent extends React.Component<any, any> { | |
this.setState({ settings: this.props.settings }); | ||
} | ||
|
||
updatePluginsStates(value: any) { | ||
const key = 'plugins.states'; | ||
const md = Setting.settingMetadata(key); | ||
shared.updateSettingValue(this, key, value); | ||
|
||
if (md.autoSave) { | ||
shared.scheduleSaveSettings(this); | ||
} | ||
} | ||
|
||
CalebJohn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
componentDidMount() { | ||
if (this.props.defaultSection) { | ||
this.setState({ selectedSectionName: this.props.defaultSection }, () => { | ||
this.switchSection(this.props.defaultSection); | ||
}); | ||
} | ||
if (!Setting.value('updatedDefaultPluginsInstallStates')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't it mean the plugin settings will be set only once? How about when we add a new default plugin? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now checking in |
||
this.updatePluginsStates(Setting.value('defaultPlugins')); | ||
Setting.setValue('updatedDefaultPluginsInstallStates', true); | ||
} | ||
} | ||
|
||
private async handleSettingButton(key: string) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Setting from '@joplin/lib/models/Setting'; | ||
import shim from '@joplin/lib/shim'; | ||
import PluginService, { defaultPluginSetting, PluginSettings } from '@joplin/lib/services/plugins/PluginService'; | ||
import path = require('path'); | ||
import { filename } from '@joplin/lib/path-utils'; | ||
import produce from 'immer'; | ||
|
||
export default async function installDefaultPlugins(pluginSettings: PluginSettings, service: PluginService): Promise<PluginSettings> { | ||
if (Setting.value('firstStart')) { | ||
const defaultPlugins = await shim.fsDriver().readDirStats(path.join(__dirname, '..', 'app-desktop/build/defaultPlugins/')); | ||
for (const plugin of defaultPlugins) { | ||
const defaultPluginPath: string = path.join(__dirname, '..', `app-desktop/build/defaultPlugins/${plugin.path}`); | ||
await service.installPlugin(defaultPluginPath, false); | ||
|
||
pluginSettings = produce(pluginSettings, (draft: PluginSettings) => { | ||
draft[filename(plugin.path)] = defaultPluginSetting(); | ||
}); | ||
} | ||
Setting.setValue('defaultPlugins', service.serializePluginSettings(pluginSettings)); | ||
return pluginSettings; | ||
} else { return pluginSettings; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's just me but generally I try to reduce indentation as much as possible, as it makes it easier to follow the logic. In this case, you could have an early exit at the top ( |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1504,6 +1504,22 @@ class Setting extends BaseModel { | |
storage: SettingStorage.Database, | ||
}, | ||
|
||
updatedDefaultPluginsInstallStates: { | ||
value: false, | ||
type: SettingItemType.Bool, | ||
public: false, | ||
appTypes: [AppType.Desktop], | ||
storage: SettingStorage.File, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this won't cause a dependency loop. Please correct me if I am wrong. |
||
|
||
defaultPlugins: { | ||
value: {}, | ||
type: SettingItemType.Object, | ||
public: true, | ||
appTypes: [AppType.Desktop], | ||
storage: SettingStorage.Database, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why this is a dynamic settings? Feels like it should just be a constant since it doesn't change for a given version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, It won't change for a given version. Are you suggesting I put it in some There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd just put a defaultPlugins.ts file in lib/services/plugins. That way it can be easily included anywhere. Putting it in Setting.ts could cause dependency loops since this file is already included in many places. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, I was thinking of making this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's a constant, just make it constant? Anything else I don't know |
||
|
||
lastSettingDefaultMigration: { | ||
value: -1, | ||
type: SettingItemType.Int, | ||
|
@@ -1516,6 +1532,13 @@ class Setting extends BaseModel { | |
public: false, | ||
}, | ||
|
||
// isFirstAppStart: { | ||
// value: true, | ||
// type: SettingItemType.Bool, | ||
// storage: SettingStorage.File, | ||
// public: false, | ||
// }, | ||
|
||
// 'featureFlag.syncAccurateTimestamps': { | ||
// value: false, | ||
// type: SettingItemType.Bool, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a descriptive parameter name
value
should benewPluginStates
. And please add typing.