-
-
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 8 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 |
---|---|---|
|
@@ -15,6 +15,7 @@ import SyncTargetRegistry from '@joplin/lib/SyncTargetRegistry'; | |
const shared = require('@joplin/lib/components/shared/config-shared.js'); | ||
import ClipperConfigScreen from '../ClipperConfigScreen'; | ||
import restart from '../../services/restart'; | ||
import getDefaultPluginSettings from '@joplin/lib/services/plugins/defaultPlugins'; | ||
const { KeymapConfigScreen } = require('../KeymapConfig/KeymapConfigScreen'); | ||
|
||
const settingKeyToControl: any = { | ||
|
@@ -60,12 +61,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(getDefaultPluginSettings()); | ||
Setting.setValue('updatedDefaultPluginsInstallStates', true); | ||
} | ||
} | ||
|
||
private async handleSettingButton(key: string) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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'; | ||
import Setting from '@joplin/lib/models/Setting'; | ||
|
||
export default async function installDefaultPlugins(pluginSettings: PluginSettings, service: PluginService): Promise<PluginSettings> { | ||
if (!Setting.value('firstStart')) return pluginSettings; | ||
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(); | ||
}); | ||
} | ||
return pluginSettings; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1504,6 +1504,14 @@ 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. |
||
|
||
lastSettingDefaultMigration: { | ||
value: -1, | ||
type: SettingItemType.Int, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defaultPluginSetting, PluginSettings } from './PluginService'; | ||
|
||
const defaultPluginsId = ['io.github.jackgruber.backup', 'plugin.calebjohn.rich-markdown']; | ||
|
||
export default function getDefaultPluginSettings(): PluginSettings { | ||
const settings: PluginSettings = {}; | ||
defaultPluginsId.map((pluginId: string) => { | ||
settings[pluginId] = defaultPluginSetting(); | ||
}); | ||
return settings; | ||
} | ||
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 feel this function doesn't do anything useful. Also you are duplicating the list of default plugin IDs here and in the place where settings are defined. That list should only appear once in the codebase. |
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.