Skip to content

Commit

Permalink
core: build for apple silicon (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlienard authored Aug 16, 2023
1 parent 367de30 commit 1beae5d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 19 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-20.04, windows-latest]
runs-on: ${{ matrix.platform }}
include:
- os: macos-latest
target: aarch64-apple-darwin
- os: macos-latest
target: x86_64-apple-darwin
- os: ubuntu-20.04
- os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install Tauri dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-20.04'
if: matrix.os == 'ubuntu-20.04'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev
Expand All @@ -34,6 +40,8 @@ jobs:
uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'
- if: matrix.target
run: rustup target add ${{ matrix.target }}
- uses: pnpm/action-setup@v2.2.4
with:
version: 8
Expand All @@ -59,3 +67,4 @@ jobs:
releaseBody: 'See the assets to download and install this version.'
releaseDraft: true
prerelease: false
args: ${{ matrix.target && format('--target {0}', matrix.target) }}
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"updater": {
"active": true,
"endpoints": ["https://gitlight.app/version/{{target}}/{{current_version}}"],
"endpoints": ["https://gitlight.app/version/{{target}}/{{current_version}}?arch={{arch}}"],
"dialog": true,
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDFFN0Y4QzExRTAxMkYyRTEKUldUaDhoTGdFWXgvSGdnNWVFSlQ2Qy9iakRld240cVExdy9xWkdWNmMyQlpDZWZFT0pwSU1xNG0K",
"windows": {
Expand Down
20 changes: 13 additions & 7 deletions src/lib/components/landing/DownloadButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
import { LinuxIcon, MacosIcon, WindowsIcon } from '~/lib/icons';
import type { GithubRelease } from '~/lib/types';
type OS = 'mac' | 'win' | 'linux';
type OS = 'appleSilicon' | 'macIntel' | 'windows' | 'linux';
export let show = true;
export let position: 'center' | 'bottom' = 'center';
let open = false;
let releases: Record<OS, string> = { mac: '', win: '', linux: '' };
let releases: Record<OS, string> = { appleSilicon: '', macIntel: '', windows: '', linux: '' };
onMount(async () => {
const response = await fetch('https://api.github.com/repos/colinlienard/gitlight/releases');
const data = (await response.json()) as GithubRelease[];
const { assets } = data[0];
releases = {
mac: assets.find(({ name }) => name.endsWith('.dmg'))?.browser_download_url as string,
win: assets.find(({ name }) => name.endsWith('.msi'))?.browser_download_url as string,
appleSilicon: assets.find(({ name }) => name.endsWith('aarch64.dmg'))
?.browser_download_url as string,
macIntel: assets.find(({ name }) => name.endsWith('x64.dmg'))?.browser_download_url as string,
windows: assets.find(({ name }) => name.endsWith('.msi'))?.browser_download_url as string,
linux: assets.find(({ name }) => name.endsWith('.AppImage'))?.browser_download_url as string
};
});
Expand All @@ -44,11 +46,15 @@
<slot />
{#if show && open}
<div class="tooltip {position}" transition:fade={{ duration: 150, easing: sineInOut }}>
<Button on:click={handleDownload('mac')}>
<Button on:click={handleDownload('appleSilicon')}>
<MacosIcon />
Download for Mac
Download for Apple Silicon
</Button>
<Button on:click={handleDownload('win')}>
<Button on:click={handleDownload('macIntel')}>
<MacosIcon />
Download for Mac Intel
</Button>
<Button on:click={handleDownload('windows')}>
<WindowsIcon />
Download for Windows
</Button>
Expand Down
20 changes: 19 additions & 1 deletion src/lib/components/settings/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@
import { GithubIcon } from '~/lib/icons';
export let updateAvailable: string | false;
export let checkUpdate: () => Promise<boolean>;
let loading = false;
let cannotUpdate = false;
async function update() {
loading = true;
await emit('tauri://update');
}
async function check() {
loading = true;
const canUpdate = await checkUpdate();
if (canUpdate) {
await emit('tauri://update');
} else {
cannotUpdate = true;
loading = false;
}
}
</script>

<div class="card">
Expand All @@ -20,6 +33,11 @@
<Button on:click={update} {loading}>Install it now</Button>
{:else}
<p>GitLight v{getAppVersion()}</p>
{#if cannotUpdate}
<Button secondary disabled>No update available</Button>
{:else}
<Button secondary on:click={check} {loading}>Check for update</Button>
{/if}
{/if}
</div>
<Button secondary href="https://github.com/colinlienard/gitlight" external>
Expand All @@ -33,7 +51,7 @@
display: flex;
width: 100%;
height: 10rem;
height: 12rem;
flex-direction: column;
align-items: center;
justify-content: center;
Expand Down
14 changes: 9 additions & 5 deletions src/lib/components/settings/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,27 @@
name: 'App',
strong: !!updateAvailable,
component: App,
props: { updateAvailable }
props: { updateAvailable, checkUpdate }
}
] as Tabs;
const githubUser = $page.data.session?.githubUser;
const gitlabUser = $page.data.session?.gitlabUser;
// Check if an update is available every 30 min
const interval = setInterval(async () => {
if (!window.__TAURI__) return;
const interval = setInterval(checkUpdate, 1800000);
async function checkUpdate() {
if (!window.__TAURI__) return false;
const release = await fetchGithub<GithubRelease>('repos/colinlienard/gitlight/releases/latest');
const latest = release.tag_name.split('v')[1];
if (latest !== getAppVersion()) {
const canUpdate = latest !== getAppVersion();
if (canUpdate) {
updateAvailable = latest;
}
}, 1800000);
return canUpdate;
}
function handleKeyDown(event: KeyboardEvent) {
if (!browser) return;
Expand Down
10 changes: 8 additions & 2 deletions src/routes/version/[target]/[version]/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import type { GithubRelease } from '~/lib/types/github-types.js';

type Target = 'linux' | 'windows' | 'darwin';

type MacosArch = 'aarch64' | 'x86_64' | undefined;

const targetExtensions: Record<Target, string> = {
linux: '.AppImage.tar.gz',
windows: '.msi.zip',
darwin: '.app.tar.gz'
};

export async function GET({ params }) {
export async function GET({ params, url }) {
try {
const target = params.target as Target;
const { version } = params;
const arch = url.searchParams.get('arch') as MacosArch;

// Get latest release from Github
const response = await fetch('https://api.github.com/repos/colinlienard/gitlight/releases');
Expand All @@ -21,7 +24,10 @@ export async function GET({ params }) {

if (version === latestVersion) throw new Error();

const extension = targetExtensions[target];
let extension = targetExtensions[target];
if (target === 'darwin') {
extension = arch === 'aarch64' ? 'aarch64.app.tar.gz' : 'x64.app.tar.gz';
}

if (!extension) throw new Error();

Expand Down

1 comment on commit 1beae5d

@vercel
Copy link

@vercel vercel bot commented on 1beae5d Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.