From fbfacb5e44cd9e17365e28819e5164e1254c8ec9 Mon Sep 17 00:00:00 2001 From: Noah Klayman Date: Mon, 30 Dec 2019 01:27:47 -0800 Subject: [PATCH 1/2] fix(tauri.js): eslint errors (#250) --- cli/tauri.js/src/api/build.ts | 2 +- cli/tauri.js/src/api/dev.ts | 2 +- cli/tauri.js/src/api/info.ts | 124 +++++++++++++++------ cli/tauri.js/src/api/init.ts | 19 ++-- cli/tauri.js/src/helpers/copy-templates.ts | 2 +- 5 files changed, 102 insertions(+), 47 deletions(-) diff --git a/cli/tauri.js/src/api/build.ts b/cli/tauri.js/src/api/build.ts index c045c5bc6..40e692304 100644 --- a/cli/tauri.js/src/api/build.ts +++ b/cli/tauri.js/src/api/build.ts @@ -1,7 +1,7 @@ import { TauriConfig } from 'types' import merge from 'webpack-merge' -const getTauriConfig = require('../helpers/tauri-config') import Runner from '../runner' +const getTauriConfig = require('../helpers/tauri-config') module.exports = async (config: TauriConfig): Promise => { const tauri = new Runner() diff --git a/cli/tauri.js/src/api/dev.ts b/cli/tauri.js/src/api/dev.ts index 307bf2089..0cc2fe196 100644 --- a/cli/tauri.js/src/api/dev.ts +++ b/cli/tauri.js/src/api/dev.ts @@ -1,7 +1,7 @@ import { TauriConfig } from 'types' import merge from 'webpack-merge' -const getTauriConfig = require('../helpers/tauri-config') import Runner from '../runner' +const getTauriConfig = require('../helpers/tauri-config') module.exports = async (config: TauriConfig): Promise => { const tauri = new Runner() diff --git a/cli/tauri.js/src/api/info.ts b/cli/tauri.js/src/api/info.ts index 9f624059f..f6204ad4e 100644 --- a/cli/tauri.js/src/api/info.ts +++ b/cli/tauri.js/src/api/info.ts @@ -1,14 +1,16 @@ -import { TauriConfig } from './../types/config'; -const os = require('os') -const spawn = require('cross-spawn').sync -const chalk = require('chalk') -const path = require('path') -const fs = require('fs') +import toml from '@tauri-apps/toml' +import chalk from 'chalk' +import { sync as spawn } from 'cross-spawn' +import fs from 'fs' +import os from 'os' +import path from 'path' +import { appDir, tauriDir } from '../helpers/app-paths' +import { TauriConfig } from './../types/config' interface DirInfo { path: string name: string - type?: 'folder'|'file' + type?: 'folder' | 'file' children?: DirInfo[] } @@ -21,9 +23,9 @@ function dirTree(filename: string): DirInfo { if (stats.isDirectory()) { info.type = 'folder' - info.children = fs.readdirSync(filename).map(function (child: string) { + info.children = fs.readdirSync(filename).map(function(child: string) { return dirTree(filename + '/' + child) - }); + }) } else { info.type = 'file' } @@ -31,16 +33,21 @@ function dirTree(filename: string): DirInfo { return info } -function getVersion (command: string, args: string[] = [], formatter?: (output: string) => string) { +function getVersion( + command: string, + args: string[] = [], + formatter?: (output: string) => string +): string { try { const child = spawn(command, [...args, '--version']) if (child.status === 0) { const output = String(child.output[1]) - return chalk.green(formatter === undefined ? output : formatter(output)).replace('\n', '') + return chalk + .green(formatter === undefined ? output : formatter(output)) + .replace('\n', '') } return chalk.red('Not installed') - } - catch (err) { + } catch (err) { return chalk.red('Not installed') } } @@ -51,21 +58,24 @@ interface Info { value?: string } -function printInfo (info: Info) { - console.log(`${info.section ? '\n' : ''}${info.key}${info.value === undefined ? '' : ' - ' + info.value}`) +function printInfo(info: Info): void { + console.log( + `${info.section ? '\n' : ''}${info.key}${ + info.value === undefined ? '' : ' - ' + info.value + }` + ) } -function printAppInfo(tauriDir: string) { +function printAppInfo(tauriDir: string): void { printInfo({ key: 'App', section: true }) try { - const toml = require('@tauri-apps/toml') const tomlPath = path.join(tauriDir, 'Cargo.toml') const tomlFile = fs.readFileSync(tomlPath) // @ts-ignore const tomlContents = toml.parse(tomlFile) - const tauriVersion = () => { + const tauriVersion = (): string => { const tauri = tomlContents.dependencies.tauri if (tauri) { if (tauri.version) { @@ -73,57 +83,97 @@ function printAppInfo(tauriDir: string) { } if (tauri.path) { try { - const tauriTomlPath = path.resolve(tauriDir, tauri.path, 'Cargo.toml') + const tauriTomlPath = path.resolve( + tauriDir, + tauri.path, + 'Cargo.toml' + ) const tauriTomlFile = fs.readFileSync(tauriTomlPath) // @ts-ignore const tauriTomlContents = toml.parse(tauriTomlFile) - return chalk.green(`${tauriTomlContents.package.version} (from source)`) - } catch (_) { } + return chalk.green( + `${tauriTomlContents.package.version} (from source)` + ) + } catch (_) {} } } return chalk.red('unknown') } - printInfo({ key: ' tauri', value: tauriVersion() }) - } - catch (_) { } + } catch (_) {} try { const tauriMode = (config: TauriConfig): string => { if (config.tauri.embeddedServer) { - return chalk.green(config.tauri.embeddedServer.active ? 'embedded-server' : 'no-server') + return chalk.green( + config.tauri.embeddedServer.active ? 'embedded-server' : 'no-server' + ) } return chalk.red('unset') } const configPath = path.join(tauriDir, 'tauri.conf.json') const config = __non_webpack_require__(configPath) as TauriConfig printInfo({ key: ' mode', value: tauriMode(config) }) - printInfo({ key: ' build-type', value: config.tauri.bundle && config.tauri.bundle.active ? 'bundle' : 'build' }) - printInfo({ key: ' CSP', value: config.tauri.security ? config.tauri.security.csp : 'unset' }) - printInfo({ key: ' Windows', value: config.tauri.edge && config.tauri.edge.active ? 'Edge' : 'MSHTML' }) - printInfo({ key: ' distDir', value: config.build ? chalk.green(config.build.distDir) : chalk.red('unset') }) - printInfo({ key: ' devPath', value: config.build ? chalk.green(config.build.devPath) : chalk.red('unset') }) - } catch (_) { } + printInfo({ + key: ' build-type', + value: + config.tauri.bundle && config.tauri.bundle.active ? 'bundle' : 'build' + }) + printInfo({ + key: ' CSP', + value: config.tauri.security ? config.tauri.security.csp : 'unset' + }) + printInfo({ + key: ' Windows', + value: config.tauri.edge && config.tauri.edge.active ? 'Edge' : 'MSHTML' + }) + printInfo({ + key: ' distDir', + value: config.build + ? chalk.green(config.build.distDir) + : chalk.red('unset') + }) + printInfo({ + key: ' devPath', + value: config.build + ? chalk.green(config.build.devPath) + : chalk.red('unset') + }) + } catch (_) {} } module.exports = () => { - printInfo({ key: 'Operating System', value: chalk.green(`${os.type()}(${os.release()}) - ${os.platform()}/${os.arch()}`), section: true }) + printInfo({ + key: 'Operating System', + value: chalk.green( + `${os.type()}(${os.release()}) - ${os.platform()}/${os.arch()}` + ), + section: true + }) printInfo({ key: 'Node.js environment', section: true }) printInfo({ key: ' Node.js', value: chalk.green(process.version.slice(1)) }) - printInfo({ key: ' tauri.js', value: chalk.green(require('../../package.json').version) }) + printInfo({ + key: ' tauri.js', + value: chalk.green(require('../../package.json').version) + }) printInfo({ key: 'Rust environment', section: true }) - printInfo({ key: ' rustc', value: getVersion('rustc', [], output => output.split(' ')[1]) }) - printInfo({ key: ' cargo', value: getVersion('cargo', [], output => output.split(' ')[1]) }) + printInfo({ + key: ' rustc', + value: getVersion('rustc', [], output => output.split(' ')[1]) + }) + printInfo({ + key: ' cargo', + value: getVersion('cargo', [], output => output.split(' ')[1]) + }) printInfo({ key: ' tauri-cli', value: getVersion('cargo', ['tauri-cli']) }) printInfo({ key: 'Global packages', section: true }) printInfo({ key: ' NPM', value: getVersion('npm') }) printInfo({ key: ' yarn', value: getVersion('yarn') }) printInfo({ key: 'App directory structure', section: true }) - const { appDir, tauriDir } = require('../helpers/app-paths') const tree = dirTree(appDir) - for (const artifact of (tree.children || [])) { + for (const artifact of tree.children || []) { if (artifact.type === 'folder') { console.log(`/${artifact.name}`) } diff --git a/cli/tauri.js/src/api/init.ts b/cli/tauri.js/src/api/init.ts index 4d7b24272..bbef7d416 100644 --- a/cli/tauri.js/src/api/init.ts +++ b/cli/tauri.js/src/api/init.ts @@ -1,16 +1,21 @@ -import { inject } from '../template' import { TauriConfig } from 'types' +import { inject } from '../template' module.exports = (args: { directory: string force: false | 'conf' | 'template' | 'all' logging: boolean - tauriPath?: string, + tauriPath?: string customConfig?: Partial }): boolean => { - return inject(args.directory, 'all', { - force: args.force, - logging: args.logging, - tauriPath: args.tauriPath - }, args.customConfig) + return inject( + args.directory, + 'all', + { + force: args.force, + logging: args.logging, + tauriPath: args.tauriPath + }, + args.customConfig + ) } diff --git a/cli/tauri.js/src/helpers/copy-templates.ts b/cli/tauri.js/src/helpers/copy-templates.ts index 824faa20c..6da4d9e2a 100644 --- a/cli/tauri.js/src/helpers/copy-templates.ts +++ b/cli/tauri.js/src/helpers/copy-templates.ts @@ -2,7 +2,7 @@ import fglob from 'fast-glob' import fs from 'fs-extra' import { isBinaryFileSync as isBinary } from 'isbinaryfile' -import { template } from 'lodash' +import { template } from 'lodash' import { join, resolve } from 'path' const copyTemplates = ({ From ed266b48c1f8242bf285a18e505aa3f698efed4c Mon Sep 17 00:00:00 2001 From: nothingismagick Date: Mon, 30 Dec 2019 12:04:12 +0100 Subject: [PATCH 2/2] chore(templates): remove updater.rs, add build.rs (#251) --- .github/config.yml | 0 .../templates/{src-tauri/src => }/updater.rs | 0 .../create-react-app/src-tauri/src/build.rs | 12 ++++ .../create-react-app/src-tauri/src/updater.rs | 69 ------------------- .../gatsby-themed-site/src-tauri/src/build.rs | 12 ++++ examples/react/next.js/src-tauri/src/build.rs | 12 ++++ .../react/next.js/src-tauri/src/updater.rs | 69 ------------------- .../svelte/svelte-app/src-tauri/src/build.rs | 12 ++++ .../svelte-app/src-tauri/src/updater.rs | 69 ------------------- .../vanillajs/monolith/src-tauri/src/build.rs | 12 ++++ .../vue/quasar-app/src-tauri/src/build.rs | 12 ++++ .../vue/quasar-app/src-tauri/src/updater.rs | 69 ------------------- 12 files changed, 72 insertions(+), 276 deletions(-) create mode 100644 .github/config.yml rename cli/tauri.js/templates/{src-tauri/src => }/updater.rs (100%) create mode 100644 examples/react/create-react-app/src-tauri/src/build.rs delete mode 100644 examples/react/create-react-app/src-tauri/src/updater.rs create mode 100644 examples/react/gatsby-themed-site/src-tauri/src/build.rs create mode 100644 examples/react/next.js/src-tauri/src/build.rs delete mode 100644 examples/react/next.js/src-tauri/src/updater.rs create mode 100644 examples/svelte/svelte-app/src-tauri/src/build.rs delete mode 100644 examples/svelte/svelte-app/src-tauri/src/updater.rs create mode 100644 examples/vanillajs/monolith/src-tauri/src/build.rs create mode 100644 examples/vue/quasar-app/src-tauri/src/build.rs delete mode 100644 examples/vue/quasar-app/src-tauri/src/updater.rs diff --git a/.github/config.yml b/.github/config.yml new file mode 100644 index 000000000..e69de29bb diff --git a/cli/tauri.js/templates/src-tauri/src/updater.rs b/cli/tauri.js/templates/updater.rs similarity index 100% rename from cli/tauri.js/templates/src-tauri/src/updater.rs rename to cli/tauri.js/templates/updater.rs diff --git a/examples/react/create-react-app/src-tauri/src/build.rs b/examples/react/create-react-app/src-tauri/src/build.rs new file mode 100644 index 000000000..fcd568038 --- /dev/null +++ b/examples/react/create-react-app/src-tauri/src/build.rs @@ -0,0 +1,12 @@ +#[cfg(windows)] +extern crate winres; + +#[cfg(windows)] +fn main() { + let mut res = winres::WindowsResource::new(); + res.set_icon("icons/icon.ico"); + res.compile().expect("Unable to find visual studio tools"); +} + +#[cfg(not(windows))] +fn main() {} diff --git a/examples/react/create-react-app/src-tauri/src/updater.rs b/examples/react/create-react-app/src-tauri/src/updater.rs deleted file mode 100644 index a2eae3d84..000000000 --- a/examples/react/create-react-app/src-tauri/src/updater.rs +++ /dev/null @@ -1,69 +0,0 @@ -use crate::tauri::process::{ProcessExt, Signal, SystemExt}; - -fn update() -> Result<(), String> { - let target = tauri::platform::target_triple().map_err(|_| "Could not determine target")?; - let github_release = tauri::updater::github::get_latest_release("jaemk", "self_update") - .map_err(|_| "Could not fetch latest release")?; - match github_release.asset_for(&target) { - Some(github_release_asset) => { - let release = tauri::updater::Release { - version: github_release.tag.trim_start_matches('v').to_string(), - download_url: github_release_asset.download_url, - asset_name: github_release_asset.name, - }; - - let status = tauri::updater::Update::configure() - .unwrap() - .release(release) - .bin_path_in_archive("github") - .bin_name("app") - .bin_install_path(&tauri::command::command_path("app".to_string()).unwrap()) - .show_download_progress(true) - .current_version(env!("CARGO_PKG_VERSION")) - .build() - .unwrap() - .update() - .unwrap(); - - println!("found release: {}", status.version()); - - /*let tmp_dir = tauri::dir::with_temp_dir(|dir| { - let file_path = dir.path().join("my-temporary-note.pdf"); - let mut tmp_archive = std::fs::File::create(file_path).unwrap(); - tauri::http::download(&"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf".to_string(), &mut tmp_archive, true).unwrap(); - });*/ - - Ok(()) - } - None => Err(format!("Could not find release for target {}", target)), - } -} - -fn restart_app(app_command: String) -> Result<(), String> { - let mut system = tauri::process::System::new(); - let parent_process = tauri::process::get_parent_process(&mut system) - .map_err(|_| "Could not determine parent process")?; - if parent_process.name() == "app" { - parent_process.kill(Signal::Kill); - std::thread::sleep(std::time::Duration::from_secs(1)); - std::process::Command::new(app_command) - .spawn() - .map_err(|_| "Could not start app")?; - } - Ok(()) -} - -fn run_updater() -> Result<(), String> { - let app_command = tauri::command::relative_command("app".to_string()) - .map_err(|_| "Could not determine app path")?; - update()?; - restart_app(app_command)?; - Ok(()) -} - -fn main() { - match run_updater() { - Ok(_) => {} - Err(err) => panic!(err), - }; -} diff --git a/examples/react/gatsby-themed-site/src-tauri/src/build.rs b/examples/react/gatsby-themed-site/src-tauri/src/build.rs new file mode 100644 index 000000000..fcd568038 --- /dev/null +++ b/examples/react/gatsby-themed-site/src-tauri/src/build.rs @@ -0,0 +1,12 @@ +#[cfg(windows)] +extern crate winres; + +#[cfg(windows)] +fn main() { + let mut res = winres::WindowsResource::new(); + res.set_icon("icons/icon.ico"); + res.compile().expect("Unable to find visual studio tools"); +} + +#[cfg(not(windows))] +fn main() {} diff --git a/examples/react/next.js/src-tauri/src/build.rs b/examples/react/next.js/src-tauri/src/build.rs new file mode 100644 index 000000000..fcd568038 --- /dev/null +++ b/examples/react/next.js/src-tauri/src/build.rs @@ -0,0 +1,12 @@ +#[cfg(windows)] +extern crate winres; + +#[cfg(windows)] +fn main() { + let mut res = winres::WindowsResource::new(); + res.set_icon("icons/icon.ico"); + res.compile().expect("Unable to find visual studio tools"); +} + +#[cfg(not(windows))] +fn main() {} diff --git a/examples/react/next.js/src-tauri/src/updater.rs b/examples/react/next.js/src-tauri/src/updater.rs deleted file mode 100644 index a2eae3d84..000000000 --- a/examples/react/next.js/src-tauri/src/updater.rs +++ /dev/null @@ -1,69 +0,0 @@ -use crate::tauri::process::{ProcessExt, Signal, SystemExt}; - -fn update() -> Result<(), String> { - let target = tauri::platform::target_triple().map_err(|_| "Could not determine target")?; - let github_release = tauri::updater::github::get_latest_release("jaemk", "self_update") - .map_err(|_| "Could not fetch latest release")?; - match github_release.asset_for(&target) { - Some(github_release_asset) => { - let release = tauri::updater::Release { - version: github_release.tag.trim_start_matches('v').to_string(), - download_url: github_release_asset.download_url, - asset_name: github_release_asset.name, - }; - - let status = tauri::updater::Update::configure() - .unwrap() - .release(release) - .bin_path_in_archive("github") - .bin_name("app") - .bin_install_path(&tauri::command::command_path("app".to_string()).unwrap()) - .show_download_progress(true) - .current_version(env!("CARGO_PKG_VERSION")) - .build() - .unwrap() - .update() - .unwrap(); - - println!("found release: {}", status.version()); - - /*let tmp_dir = tauri::dir::with_temp_dir(|dir| { - let file_path = dir.path().join("my-temporary-note.pdf"); - let mut tmp_archive = std::fs::File::create(file_path).unwrap(); - tauri::http::download(&"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf".to_string(), &mut tmp_archive, true).unwrap(); - });*/ - - Ok(()) - } - None => Err(format!("Could not find release for target {}", target)), - } -} - -fn restart_app(app_command: String) -> Result<(), String> { - let mut system = tauri::process::System::new(); - let parent_process = tauri::process::get_parent_process(&mut system) - .map_err(|_| "Could not determine parent process")?; - if parent_process.name() == "app" { - parent_process.kill(Signal::Kill); - std::thread::sleep(std::time::Duration::from_secs(1)); - std::process::Command::new(app_command) - .spawn() - .map_err(|_| "Could not start app")?; - } - Ok(()) -} - -fn run_updater() -> Result<(), String> { - let app_command = tauri::command::relative_command("app".to_string()) - .map_err(|_| "Could not determine app path")?; - update()?; - restart_app(app_command)?; - Ok(()) -} - -fn main() { - match run_updater() { - Ok(_) => {} - Err(err) => panic!(err), - }; -} diff --git a/examples/svelte/svelte-app/src-tauri/src/build.rs b/examples/svelte/svelte-app/src-tauri/src/build.rs new file mode 100644 index 000000000..fcd568038 --- /dev/null +++ b/examples/svelte/svelte-app/src-tauri/src/build.rs @@ -0,0 +1,12 @@ +#[cfg(windows)] +extern crate winres; + +#[cfg(windows)] +fn main() { + let mut res = winres::WindowsResource::new(); + res.set_icon("icons/icon.ico"); + res.compile().expect("Unable to find visual studio tools"); +} + +#[cfg(not(windows))] +fn main() {} diff --git a/examples/svelte/svelte-app/src-tauri/src/updater.rs b/examples/svelte/svelte-app/src-tauri/src/updater.rs deleted file mode 100644 index a2eae3d84..000000000 --- a/examples/svelte/svelte-app/src-tauri/src/updater.rs +++ /dev/null @@ -1,69 +0,0 @@ -use crate::tauri::process::{ProcessExt, Signal, SystemExt}; - -fn update() -> Result<(), String> { - let target = tauri::platform::target_triple().map_err(|_| "Could not determine target")?; - let github_release = tauri::updater::github::get_latest_release("jaemk", "self_update") - .map_err(|_| "Could not fetch latest release")?; - match github_release.asset_for(&target) { - Some(github_release_asset) => { - let release = tauri::updater::Release { - version: github_release.tag.trim_start_matches('v').to_string(), - download_url: github_release_asset.download_url, - asset_name: github_release_asset.name, - }; - - let status = tauri::updater::Update::configure() - .unwrap() - .release(release) - .bin_path_in_archive("github") - .bin_name("app") - .bin_install_path(&tauri::command::command_path("app".to_string()).unwrap()) - .show_download_progress(true) - .current_version(env!("CARGO_PKG_VERSION")) - .build() - .unwrap() - .update() - .unwrap(); - - println!("found release: {}", status.version()); - - /*let tmp_dir = tauri::dir::with_temp_dir(|dir| { - let file_path = dir.path().join("my-temporary-note.pdf"); - let mut tmp_archive = std::fs::File::create(file_path).unwrap(); - tauri::http::download(&"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf".to_string(), &mut tmp_archive, true).unwrap(); - });*/ - - Ok(()) - } - None => Err(format!("Could not find release for target {}", target)), - } -} - -fn restart_app(app_command: String) -> Result<(), String> { - let mut system = tauri::process::System::new(); - let parent_process = tauri::process::get_parent_process(&mut system) - .map_err(|_| "Could not determine parent process")?; - if parent_process.name() == "app" { - parent_process.kill(Signal::Kill); - std::thread::sleep(std::time::Duration::from_secs(1)); - std::process::Command::new(app_command) - .spawn() - .map_err(|_| "Could not start app")?; - } - Ok(()) -} - -fn run_updater() -> Result<(), String> { - let app_command = tauri::command::relative_command("app".to_string()) - .map_err(|_| "Could not determine app path")?; - update()?; - restart_app(app_command)?; - Ok(()) -} - -fn main() { - match run_updater() { - Ok(_) => {} - Err(err) => panic!(err), - }; -} diff --git a/examples/vanillajs/monolith/src-tauri/src/build.rs b/examples/vanillajs/monolith/src-tauri/src/build.rs new file mode 100644 index 000000000..fcd568038 --- /dev/null +++ b/examples/vanillajs/monolith/src-tauri/src/build.rs @@ -0,0 +1,12 @@ +#[cfg(windows)] +extern crate winres; + +#[cfg(windows)] +fn main() { + let mut res = winres::WindowsResource::new(); + res.set_icon("icons/icon.ico"); + res.compile().expect("Unable to find visual studio tools"); +} + +#[cfg(not(windows))] +fn main() {} diff --git a/examples/vue/quasar-app/src-tauri/src/build.rs b/examples/vue/quasar-app/src-tauri/src/build.rs new file mode 100644 index 000000000..fcd568038 --- /dev/null +++ b/examples/vue/quasar-app/src-tauri/src/build.rs @@ -0,0 +1,12 @@ +#[cfg(windows)] +extern crate winres; + +#[cfg(windows)] +fn main() { + let mut res = winres::WindowsResource::new(); + res.set_icon("icons/icon.ico"); + res.compile().expect("Unable to find visual studio tools"); +} + +#[cfg(not(windows))] +fn main() {} diff --git a/examples/vue/quasar-app/src-tauri/src/updater.rs b/examples/vue/quasar-app/src-tauri/src/updater.rs deleted file mode 100644 index a2eae3d84..000000000 --- a/examples/vue/quasar-app/src-tauri/src/updater.rs +++ /dev/null @@ -1,69 +0,0 @@ -use crate::tauri::process::{ProcessExt, Signal, SystemExt}; - -fn update() -> Result<(), String> { - let target = tauri::platform::target_triple().map_err(|_| "Could not determine target")?; - let github_release = tauri::updater::github::get_latest_release("jaemk", "self_update") - .map_err(|_| "Could not fetch latest release")?; - match github_release.asset_for(&target) { - Some(github_release_asset) => { - let release = tauri::updater::Release { - version: github_release.tag.trim_start_matches('v').to_string(), - download_url: github_release_asset.download_url, - asset_name: github_release_asset.name, - }; - - let status = tauri::updater::Update::configure() - .unwrap() - .release(release) - .bin_path_in_archive("github") - .bin_name("app") - .bin_install_path(&tauri::command::command_path("app".to_string()).unwrap()) - .show_download_progress(true) - .current_version(env!("CARGO_PKG_VERSION")) - .build() - .unwrap() - .update() - .unwrap(); - - println!("found release: {}", status.version()); - - /*let tmp_dir = tauri::dir::with_temp_dir(|dir| { - let file_path = dir.path().join("my-temporary-note.pdf"); - let mut tmp_archive = std::fs::File::create(file_path).unwrap(); - tauri::http::download(&"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf".to_string(), &mut tmp_archive, true).unwrap(); - });*/ - - Ok(()) - } - None => Err(format!("Could not find release for target {}", target)), - } -} - -fn restart_app(app_command: String) -> Result<(), String> { - let mut system = tauri::process::System::new(); - let parent_process = tauri::process::get_parent_process(&mut system) - .map_err(|_| "Could not determine parent process")?; - if parent_process.name() == "app" { - parent_process.kill(Signal::Kill); - std::thread::sleep(std::time::Duration::from_secs(1)); - std::process::Command::new(app_command) - .spawn() - .map_err(|_| "Could not start app")?; - } - Ok(()) -} - -fn run_updater() -> Result<(), String> { - let app_command = tauri::command::relative_command("app".to_string()) - .map_err(|_| "Could not determine app path")?; - update()?; - restart_app(app_command)?; - Ok(()) -} - -fn main() { - match run_updater() { - Ok(_) => {} - Err(err) => panic!(err), - }; -}