Skip to content

Commit 1c2fb09

Browse files
committed
feat(update): Add auto updater.
1 parent ceb0a65 commit 1c2fb09

File tree

10 files changed

+473
-18
lines changed

10 files changed

+473
-18
lines changed

src/components/PendingStatsView.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,13 @@ export const PendingStatsViewComponent = (props: { plugin: InvioPlugin }) => {
2121

2222
const toRemoteTouched = getToRemoteFileList();
2323
console.log('toRemoteTouched - ', toRemoteTouched)
24-
const selectedKeys = [];
25-
if (!(toLocalTouched.length > 0) && !(toRemoteTouched.length > 0)) {
26-
return <>
27-
<h4 className={styles['header']}><Logo className={styles['icon']} />Changed Files</h4>
28-
<div className={styles['emptyReport']}>
29-
<ScrollText className={styles['icon']} />
30-
<span>No file changed</span>
31-
</div>
32-
</>
33-
}
3424

35-
const treeToLocalData: DataNode[] = toLocalTouched.map((item: any) => {
25+
const treeToLocalData: DataNode[] = toLocalTouched?.map((item: any) => {
3626
item.title = item.key
3727
item.key = item.key
3828
return item;
3929
})
40-
const treeToRemoteData: DataNode[] = toRemoteTouched.map((item: any) => {
30+
const treeToRemoteData: DataNode[] = toRemoteTouched?.map((item: any) => {
4131
item.title = item.key
4232
item.key = item.key
4333
return item;
@@ -49,7 +39,7 @@ export const PendingStatsViewComponent = (props: { plugin: InvioPlugin }) => {
4939
props.plugin.viewFileDiff(key, type === 'ToLocal' ? 'RemoteToLocal' : 'LocalToRemote')
5040
setTimeout(() => {
5141
selectedKeys = []
52-
}, 3000)
42+
}, 300)
5343
};
5444

5545
const onToLocalSelect: TreeProps['onSelect'] = (selectedKeys: any, info: any) => {
@@ -80,7 +70,20 @@ export const PendingStatsViewComponent = (props: { plugin: InvioPlugin }) => {
8070
const modal = new CheckSettingsModal(props.plugin.app, props.plugin);
8171
modal.open();
8272
}
83-
73+
if (!(toLocalTouched.length > 0) && !(toRemoteTouched.length > 0)) {
74+
return <>
75+
<h4 className={styles['header']}>
76+
<Logo className={styles['icon']} />
77+
Touched Files Status
78+
<Cog className={styles['settings']} onClick={openSettings} />
79+
</h4>
80+
81+
<div className={styles['emptyReport']}>
82+
<ScrollText className={styles['icon']} />
83+
<span>No file changed</span>
84+
</div>
85+
</>
86+
}
8487
return (
8588
<>
8689
<h4 className={styles['header']}>

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const GITHUB_PATH = 'frontend-engineering/Invio'

src/langs/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
"modal_project_slug_err": "The slug can only contain letters and numbers, with a length of 6 to 12 characters.",
125125
"modal_project_slug_case_err": "Invio project slug is case-insensitive, it can only contain lower case characters.",
126126

127+
"settings_update_title": "New version detected",
128+
"settings_update_desc": "Latest version: {{updateVersion}}, Current version: {{currentVersion}}",
129+
"settings_update_btn": "Update",
127130
"settings_basic": "Basic Settings",
128131
"settings_domain": "Domain",
129132
"settings_domain_desc": "The option to point a domain to your S3 (or other COS) is optional, but recommended for previewing and generating a website that is SEO-friendly. \n Like https://search.google.com",

src/langs/zh_cn.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
"modal_project_slug_err": "slug只能包含字母和数字,长度6~12位",
124124
"modal_project_slug_case_err": "Invio project slug 大小写不敏感,不允许包含大写字母",
125125

126+
"settings_update_title": "检测到新版本",
127+
"settings_update_desc": "最新版本: {{updateVersion}}, 当前版本: {{currentVersion}}",
128+
"settings_update_btn": "升级",
126129
"settings_basic": "基本设置",
127130
"settings_domain": "域名",
128131
"settings_domain_desc": "(可选)绑定的指向S3(或其他COS)的域名,主要用于预览和部署网页时SEO相关配置的自动注入。\n例如:https://search.google.com",

src/langs/zh_tw.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
"modal_project_slug_err": "slug只能包含字母和数字,长度6~12位",
124124
"modal_project_slug_case_err": "Invio project slug 大小写不敏感,不允许包含大写字母",
125125

126+
"settings_update_title": "检测到新版本",
127+
"settings_update_desc": "最新版本: {{updateVersion}}, 当前版本: {{currentVersion}}",
128+
"settings_update_btn": "升级",
126129
"settings_basic": "基本設定",
127130
"settings_domain": "域名",
128131
"settings_domain_desc": "(可选)绑定的指向S3(或其他COS)的域名,主要用于预览和部署网页时SEO相关配置的自动注入。\n例如:https://search.google.com",

src/main.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import { syncWithRemoteProject, switchProject } from './hosting';
5959
import Utils from './utils';
6060
import { Analytics4, loadGA } from './ga';
6161
import { TDiffType, openDiffModal } from './diff/index';
62+
import AutoUpdater from './updater'
6263

6364
const { iconNameSyncWait, iconNameSyncPending, iconNameSyncRunning, iconNameLogs, iconNameSyncLogo } = UsingIconNames;
6465
const Menu_Tab = ` `;
@@ -89,6 +90,7 @@ export default class InvioPlugin extends Plugin {
8990
recentSyncedFiles: any;
9091
ga: Analytics4;
9192
syncRunAbort: boolean | ((params: any) => void);
93+
updater: AutoUpdater;
9294

9395
isUnderWatch(file: TAbstractFile) {
9496
const rootDir = this.settings.localWatchDir;
@@ -871,12 +873,12 @@ export default class InvioPlugin extends Plugin {
871873
const touched = [ ...(toRemoteFiles || []), ...(toLocalFiles || []) ]
872874
await StatsView.activateStatsView(this);
873875
const view = StatsView.getStatsView(this, 'PendingStats');
874-
view.setStatsType('PendingStats')
876+
view?.setStatsType('PendingStats')
875877
const fileMap: Record<string, FileOrFolderMixedState> = {};
876878
touched.forEach(item => {
877879
fileMap[item.key] = item;
878880
})
879-
view.init(fileMap)
881+
view?.init(fileMap)
880882
}
881883

882884
async onload() {
@@ -947,7 +949,8 @@ export default class InvioPlugin extends Plugin {
947949

948950
// must AFTER preparing DB
949951
this.enableAutoClearSyncPlanHist();
950-
952+
this.updater = new AutoUpdater(this);
953+
951954
this.app.workspace.onLayoutReady(() => {
952955
log.debug('layout ready...');
953956
// Add custom icon for root dir
@@ -974,6 +977,13 @@ export default class InvioPlugin extends Plugin {
974977
}, 300);
975978
// TODO: Change file icons to show sync status, like sync done, sync failed, pending to sync, etc.
976979
})
980+
981+
setTimeout(async () => {
982+
this.updater.autoUpdate((info) => {
983+
log.info('update info: ', info);
984+
// TODO: Setup update alert
985+
})
986+
}, 60 * 1000)
977987
this.syncRunAbort = false;
978988
this.syncStatus = "idle";
979989

src/settings.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const getDEFAULT_SETTINGS = (): InvioPluginSettings => {
9898
// vaultRandomID: "", // deprecated
9999
autoRunEveryMilliseconds: -1,
100100
initRunAfterMilliseconds: -1,
101-
autoCheckEveryMilliseconds: 1000 * 60,
101+
autoCheckEveryMilliseconds: 1000 * 60 * 5,
102102
initCheckAfterMilliseconds: 1000 * 10,
103103
agreeToUploadExtraMetadata: false,
104104
concurrency: 5,
@@ -469,6 +469,27 @@ export class InvioSettingTab extends PluginSettingTab {
469469

470470
containerEl.createEl("h1", { text: "Invio" });
471471

472+
const updateDiv = containerEl.createEl("div");
473+
this.plugin.updater.update(true).then(updateInfo => {
474+
if ((typeof updateInfo !== 'boolean') && updateInfo?.updateVersion) {
475+
const desc = t('settings_update_desc', updateInfo);
476+
new Setting(updateDiv)
477+
.setName(t('settings_update_title'))
478+
.setDesc(desc)
479+
.addButton((button) => {
480+
button.setButtonText(t('settings_update_btn'));
481+
button.onClick(() => {
482+
this.plugin.updater.update()
483+
this.hide();
484+
});
485+
})
486+
} else {
487+
new Setting(updateDiv)
488+
.setName('update')
489+
.setDesc('latest version')
490+
}
491+
})
492+
472493
// const dirChooserDiv = containerEl.createDiv();
473494
// dirChooserDiv.createEl("h2", { text: t("settings_chooseservice") });
474495
const dirDiv = containerEl.createEl("div");

0 commit comments

Comments
 (0)