Add archive save component & shutdown hendel #45

Merged
MrKBear merged 5 commits from dev-mrkbear into master 2022-04-24 14:13:17 +08:00
2 changed files with 26 additions and 0 deletions
Showing only changes of commit 87ed157340 - Show all commits

View File

@ -126,6 +126,30 @@ class HeaderWindowsAction extends Component<IMixinElectronProps> {
@useStatusWithEvent("fileSave", "fileChange", "fileLoad") @useStatusWithEvent("fileSave", "fileChange", "fileLoad")
class HeaderBar extends Component<IHeaderBarProps & IMixinStatusProps & IMixinSettingProps> { class HeaderBar extends Component<IHeaderBarProps & IMixinStatusProps & IMixinSettingProps> {
private showCloseMessage = (e: BeforeUnloadEvent) => {
if (!this.props.status?.archive.isSaved) {
const message = I18N(this.props, "ZH_CH");
(e || window.event).returnValue = message; // 兼容 Gecko + IE
return message; // 兼容 Gecko + Webkit, Safari, Chrome
}
}
public componentDidMount() {
if (this.props.setting?.platform === Platform.web) {
// 阻止页面关闭
window.addEventListener("beforeunload", this.showCloseMessage);
}
}
public componentWillUnmount() {
if (this.props.setting?.platform === Platform.web) {
// 阻止页面关闭
window.removeEventListener("beforeunload", this.showCloseMessage);
}
}
public render(): ReactNode { public render(): ReactNode {
const { status, setting } = this.props; const { status, setting } = this.props;

View File

@ -172,6 +172,8 @@ class Status extends Emitter<IStatusEvent> {
this.emit("fileChange"); this.emit("fileChange");
} }
} }
// 设置文件修改状态
this.on("objectChange", handelFileChange); this.on("objectChange", handelFileChange);
this.on("behaviorChange", handelFileChange); this.on("behaviorChange", handelFileChange);
this.on("labelChange", handelFileChange); this.on("labelChange", handelFileChange);