Skip to content

Commit

Permalink
add clear tmp & output
Browse files Browse the repository at this point in the history
lint
  • Loading branch information
xiao-e-yun committed Sep 25, 2021
1 parent 7575a72 commit e7a188d
Show file tree
Hide file tree
Showing 19 changed files with 578 additions and 419 deletions.
25 changes: 25 additions & 0 deletions launcher/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions launcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ edition = '2018'
target-dir = "dist"

[dependencies]
serde_json = "1.0.68"
serde = "1.0.130"
notify-rust = "4"

[target.'cfg(windows)'.build-dependencies]
Expand Down
43 changes: 34 additions & 9 deletions launcher/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,62 @@
#![cfg_attr(not(debug_assertions),windows_subsystem = "windows")]
use std::process::Command;
use std::os::windows::process::CommandExt;
use std::path::Path;
use serde::{Deserialize, Serialize};
use notify_rust::Notification;
use std::path::Path;
use serde_json;

#[derive(Serialize, Deserialize)]
struct Config {
clear_tmp: Option<bool>,
clear_output: Option<bool>,
}

fn main() {
// //是否缺少檔案
if !Path::new("core.exe").is_file() {
// core not found
Notification::new()
.summary("找不到 core.exe")
.body("相同目錄缺少檔案\"core.exe\"")
.show().unwrap();
.summary("找不到 core.exe")
.body("相同目錄缺少檔案\"core.exe\"")
.show().unwrap();
panic!("core.exe not found");
}



// //是否缺少檔案,缺少的話創建新的
let config = "config.json";
if !Path::new(&config).is_file() {
let config_path = Path::new(&config);
if !config_path.is_file() {
println!("create {}", &config);
std::fs::write(config, "{}").unwrap();
};


// //是否缺少檔案,缺少的話創建新的
let tmp = "tmp";
if !Path::new(&tmp).is_dir() {
let tmp_path = Path::new(&tmp);
if !tmp_path.is_dir() {
println!("create {}", &tmp);
std::fs::create_dir(tmp).unwrap();
};

//運行軟體
if cfg!(target_os = "windows") {
const CREATE_NO_WINDOW: u32 = 0x08000000;
let mut open_core = Command::new("core.exe");
let log = open_core.arg("run").creation_flags(CREATE_NO_WINDOW).output().expect("can't open core");
println!("{}", String::from_utf8_lossy(&log.stdout));
}

//如果設定有,刪除暫存檔
let config_json = std::fs::read_to_string(config_path).expect("can't read config");
let config:Config = serde_json::from_str(&config_json[..]).expect("can't parse config");
if config.clear_tmp == Some(true) && tmp_path.is_dir(){
std::fs::remove_dir_all(tmp_path).unwrap();
}

//如果設定有,刪除輸出檔
let output_path = Path::new("output");
if config.clear_output == Some(true) && output_path.is_dir(){
std::fs::remove_dir_all(output_path).unwrap();
}
}
2 changes: 1 addition & 1 deletion tools/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const fs = $fs.promises;
const promise = []
promise.push(
exec("tsc -p " + "./server/tsconfig.json").then($done),
exec(`npx vue-cli-service build --mode production --dest ../build/www --target app --modern --fix`,{cwd:"./view"}).then($done),
exec(`npm run lint && npx vue-cli-service build --mode production --dest ../build/www --target app --modern --fix`,{cwd:"./view"}).then($done),
fs.readdir("./lib").then((files)=>{
files.map(file => {
return fs.copyFile("./lib/" + file, "./build/lib/" + file)
Expand Down
4 changes: 3 additions & 1 deletion types/config/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default interface Config {
thread_count: number;
thread_count: number
clear_output:boolean
clear_tmp:boolean
}
4 changes: 2 additions & 2 deletions view/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = {
ecmaVersion: 2020,
},
rules: {
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-console": "off",
"no-debugger": "off",
"@typescript-eslint/no-this-alias": ["off"],
},
};
10 changes: 5 additions & 5 deletions view/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ export default defineComponent({
SidebarTemplate: Sidebar,
LoggerTemplate: Logger,
},
setup(){
const loading = toRef(useStore().state, "loading")
setup() {
const loading = toRef(useStore().state, "loading");
return {
loading
loading,
};
},
})
});
</script>

<style lang="scss">
Expand Down Expand Up @@ -152,4 +152,4 @@ body {
opacity: 1;
}
}
</style>
</style>
110 changes: 56 additions & 54 deletions view/src/components/choose_files.vue
Original file line number Diff line number Diff line change
@@ -1,82 +1,84 @@
<template>
<div
@click="this.$refs.input.click"
@drop="drag_file"
@dragenter="drop_inout"
@dragleave="drop_inout"
@dragenter.prevent
@dragover.prevent
class="drop_here"
:class="{ dropping: dragenter !== 0 }"
>
<h1>選擇圖片</h1>
<input
type="file"
@change="file_change"
multiple="multiple"
accept=".gif,.jpg,.png"
ref="input"
/>
</div>
<div
@click="this.$refs.input.click"
@drop="drag_file"
@dragenter="drop_inout"
@dragleave="drop_inout"
@dragenter.prevent
@dragover.prevent
class="drop_here"
:class="{ dropping: dragenter !== 0 }"
>
<h1>選擇圖片</h1>
<input
type="file"
@change="file_change"
multiple="multiple"
accept=".gif,.jpg,.png"
ref="input"
/>
</div>
</template>

<script lang="ts">
import { mixin } from '@/store'
import { defineComponent } from 'vue'
import { mixin } from "@/store";
import { defineComponent } from "vue";
export default defineComponent({
mixins: [mixin],
methods:{
methods: {
//拖入檔案
drag_file(e:DragEvent){
e.stopPropagation()
e.preventDefault()
this.dragenter = 0
const files = (e.dataTransfer as DataTransfer).files
if(files.length > 0) this.upload(files)
else this.log("無檔案檔案","無法讀取到丟入的檔案")
drag_file(e: DragEvent) {
e.stopPropagation();
e.preventDefault();
this.dragenter = 0;
const files = (e.dataTransfer as DataTransfer).files;
if (files.length > 0) this.upload(files);
else this.log("無檔案檔案", "無法讀取到丟入的檔案");
},
//拖曳檔案中
drop_inout(e:DragEvent){
if(e.type == "dragenter") this.dragenter++
else this.dragenter--
drop_inout(e: DragEvent) {
if (e.type == "dragenter") this.dragenter++;
else this.dragenter--;
},
file_change(e:InputEvent){
const input = e.target as HTMLInputElement
this.upload(input.files as FileList)
input.value = ""
file_change(e: InputEvent) {
const input = e.target as HTMLInputElement;
this.upload(input.files as FileList);
input.value = "";
},
//通知父層
upload(files:FileList){
this.$emit("files",files)
upload(files: FileList) {
this.$emit("files", files);
},
},
data(){return{
dragenter:0,
}}
})
data() {
return {
dragenter: 0,
};
},
});
</script>

<style lang="scss" scoped>
@import "../app.scss";
.drop_here{
width:100%;
background-color:$side-3;
transition: background-color 0.3s ease,color 0.3s ease;
.drop_here {
width: 100%;
background-color: $side-3;
transition: background-color 0.3s ease, color 0.3s ease;
position: relative;
cursor: pointer;
&>h1{
text-align:center;
& > h1 {
text-align: center;
}
&>input{
& > input {
display: none;
}
&:hover{
background-color:$side-2;
&:hover {
background-color: $side-2;
}
&.dropping{
background-color:$main;
&.dropping {
background-color: $main;
color: $bg;
}
}
</style>
</style>
35 changes: 17 additions & 18 deletions view/src/components/logger.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
<template>
<div id="logger">
<transition-group name="fade" mode="out-in">
<div v-for="(log,index) in logger" :key="index">
<button @click="logger.splice(index, 1)"></button>
<h2 v-html="log.title"></h2>
<p v-html="log.content"></p>
</div>
</transition-group>
</div>
<div id="logger">
<transition-group name="fade" mode="out-in">
<div v-for="(log, index) in logger" :key="index">
<button @click="logger.splice(index, 1)"></button>
<h2 v-html="log.title"></h2>
<p v-html="log.content"></p>
</div>
</transition-group>
</div>
</template>

<script lang="ts">
import { useStore } from "../store";
import { defineComponent, toRef} from "vue";
import { defineComponent, toRef } from "vue";
export default defineComponent({
setup(){
return {
logger: toRef(useStore().state,"logger")
}
}
})
setup() {
return {
logger: toRef(useStore().state, "logger"),
};
},
});
</script>

<style lang="scss">
@import "../app.scss";
</style>
</style>
Loading

0 comments on commit e7a188d

Please sign in to comment.