Skip to content

Commit

Permalink
feat: add new version notification
Browse files Browse the repository at this point in the history
Signed-off-by: Martichou <[email protected]>
  • Loading branch information
Martichou committed Jul 7, 2024
1 parent 4f4caf5 commit c3be553
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/common/vue_lib/src/h/ParamsHelper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface TauriVM {
downloadPath: string | undefined;
hostname: string | undefined;
settingsOpen: boolean;
new_version: string | null;
enable: () => Promise<void>;
disable: () => Promise<void>;
invoke: (cmd: string, args?: InvokeArgs) => Promise<unknown>
Expand Down
18 changes: 18 additions & 0 deletions app/common/vue_lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,22 @@ export async function setDownloadPath(vm: TauriVM, dest: string) {

export async function getDownloadPath(vm: TauriVM) {
vm.downloadPath = await vm.store.get(downloadPathKey) ?? undefined;
}

export async function getLatestVersion(vm: TauriVM, gt: (a: string, b: string) => boolean) {
try {
const response = await fetch('https://api.github.com/repos/martichou/rquickshare/releases/latest');
if (!response.ok) {
throw new Error(`Error: ${response.status} ${response.statusText}`);
}
const data = await response.json();
const new_version = data.tag_name.substring(1);
console.log(`Latest version: ${vm.version} vs ${new_version}`);

if (vm.version && gt(new_version, vm.version)) {
vm.new_version = new_version;
}
} catch (err) {
console.error(err);
}
}
2 changes: 2 additions & 0 deletions app/legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@martichou/core_lib": "link:../../core_lib",
"@tauri-apps/api": "1.5.6",
"semver": "^7.6.2",
"tauri-plugin-autostart-api": "github:tauri-apps/tauri-plugin-autostart#v1",
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store#v1",
"vue": "3.4.27",
Expand All @@ -29,6 +30,7 @@
"@tailwindcss/typography": "^0.5.13",
"@tauri-apps/cli": "1.5.14",
"@types/node": "^20.14.2",
"@types/semver": "^7.5.8",
"@vitejs/plugin-vue": "^5.0.5",
"@vue/devtools": "^7.3.4",
"@vue/eslint-config-typescript": "13.0.0",
Expand Down
11 changes: 11 additions & 0 deletions app/legacy/pnpm-lock.yaml

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

30 changes: 24 additions & 6 deletions app/legacy/src/components/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,21 @@
</h2>
</div>
<div class="flex justify-center items-center gap-4">
<p class="text-sm">
v{{ version }}
</p>
<div
class="flex items-center gap-2 text-sm transition duration-150 ease-in-out"
:class="{'btn active:scale-95': new_version}"
@click="new_version && invoke('open_url', { message: 'https://github.com/Martichou/rquickshare/releases/latest' })">
<span v-if="new_version">Update available</span>
<p>
v{{ version }}
</p>
<p v-if="new_version" class="text-lg">
🡒
</p>
<p v-if="new_version">
v{{ new_version }}
</p>
</div>
<div class="btn px-3 rounded-xl active:scale-95 transition duration-150 ease-in-out" @click="settingsOpen = true">
<svg
xmlns="http://www.w3.org/2000/svg" height="24"
Expand Down Expand Up @@ -330,6 +342,7 @@
</template>

<script lang="ts">
import { gt } from 'semver'
import { ref, nextTick } from 'vue'
import { UnlistenFn, listen } from '@tauri-apps/api/event'
import { Store } from 'tauri-plugin-store-api';
Expand All @@ -347,7 +360,7 @@ import { Visibility } from '@martichou/core_lib/bindings/Visibility';
import { opt, ToDelete, stateToDisplay, autostartKey, DisplayedItem, _displayedItems, setAutoStart,
applyAutoStart, setRealClose, getRealclose, setVisibility, getVisibility, invertVisibility, clearSending,
removeRequest, sendInfo, sendCmd, blured, getProgress, setDownloadPath, getDownloadPath } from 'vue_lib';
removeRequest, sendInfo, sendCmd, blured, getProgress, setDownloadPath, getDownloadPath, getLatestVersion } from 'vue_lib';
export default {
name: "HomePage",
Expand Down Expand Up @@ -377,7 +390,8 @@ export default {
blured,
getProgress,
setDownloadPath,
getDownloadPath
getDownloadPath,
getLatestVersion
};
},
Expand All @@ -404,7 +418,9 @@ export default {
hostname: ref<string>(),
settingsOpen: ref<boolean>(false)
settingsOpen: ref<boolean>(false),
new_version: opt<string>(),
};
},
Expand Down Expand Up @@ -505,6 +521,8 @@ export default {
}
})
);
await this.getLatestVersion(this, gt);
});
},
Expand Down
5 changes: 5 additions & 0 deletions app/legacy/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export default defineConfig({
minify: !process.env.TAURI_DEBUG ? 'esbuild' : false,
sourcemap: !!process.env.TAURI_DEBUG,
emptyOutDir: true,
rollupOptions: {
external: [
"semver",
],
},
},
// See https://vitest.dev/config/
test: {
Expand Down
2 changes: 2 additions & 0 deletions app/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@tauri-apps/plugin-dialog": "2.0.0-beta.5",
"@tauri-apps/plugin-notification": "^2.0.0-beta.5",
"@tauri-apps/plugin-store": "^2.0.0-beta.5",
"semver": "^7.6.2",
"vue": "3.4.27",
"vue_lib": "link:../common/vue_lib"
},
Expand All @@ -32,6 +33,7 @@
"@tailwindcss/typography": "^0.5.13",
"@tauri-apps/cli": "2.0.0-beta.20",
"@types/node": "^20.14.2",
"@types/semver": "^7.5.8",
"@vitejs/plugin-vue": "^5.0.5",
"@vue/devtools": "^7.3.4",
"@vue/eslint-config-typescript": "13.0.0",
Expand Down
11 changes: 11 additions & 0 deletions app/main/pnpm-lock.yaml

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

30 changes: 24 additions & 6 deletions app/main/src/components/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,21 @@
</h2>
</div>
<div class="flex justify-center items-center gap-4">
<p class="text-sm">
v{{ version }}
</p>
<div
class="flex items-center gap-2 text-sm transition duration-150 ease-in-out"
:class="{'btn active:scale-95': new_version}"
@click="new_version && invoke('open_url', { message: 'https://github.com/Martichou/rquickshare/releases/latest' })">
<span v-if="new_version">Update available</span>
<p>
v{{ version }}
</p>
<p v-if="new_version" class="text-lg">
🡒
</p>
<p v-if="new_version">
v{{ new_version }}
</p>
</div>
<div class="btn px-3 rounded-xl active:scale-95 transition duration-150 ease-in-out" @click="settingsOpen = true">
<svg
xmlns="http://www.w3.org/2000/svg" height="24"
Expand Down Expand Up @@ -330,6 +342,7 @@
</template>

<script lang="ts">
import { gt } from 'semver'
import { ref, nextTick } from 'vue'
import { UnlistenFn, listen } from '@tauri-apps/api/event'
import { invoke } from '@tauri-apps/api/core'
Expand All @@ -347,7 +360,7 @@ import { Visibility } from '@martichou/core_lib/bindings/Visibility';
import { opt, ToDelete, stateToDisplay, autostartKey, DisplayedItem, _displayedItems, setAutoStart,
applyAutoStart, setRealClose, getRealclose, setVisibility, getVisibility, invertVisibility, clearSending,
removeRequest, sendInfo, sendCmd, blured, getProgress, setDownloadPath, getDownloadPath } from 'vue_lib';
removeRequest, sendInfo, sendCmd, blured, getProgress, setDownloadPath, getDownloadPath, getLatestVersion } from 'vue_lib';
export default {
name: "HomePage",
Expand Down Expand Up @@ -377,7 +390,8 @@ export default {
blured,
getProgress,
setDownloadPath,
getDownloadPath
getDownloadPath,
getLatestVersion
};
},
Expand All @@ -404,7 +418,9 @@ export default {
hostname: ref<string>(),
settingsOpen: ref<boolean>(false)
settingsOpen: ref<boolean>(false),
new_version: opt<string>(),
};
},
Expand Down Expand Up @@ -505,6 +521,8 @@ export default {
}
})
);
await this.getLatestVersion(this, gt);
});
},
Expand Down

0 comments on commit c3be553

Please sign in to comment.