Compare commits
4 Commits
main
...
brucemacd/
Author | SHA1 | Date | |
---|---|---|---|
|
6e08c68661 | ||
|
f15312c52b | ||
|
44c05abd22 | ||
|
a467bd3f6c |
@ -16,7 +16,10 @@ enum Step {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
const [step, setStep] = useState<Step>(Step.WELCOME)
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const stepParam = urlParams.get('step');
|
||||||
|
const initialStep = stepParam ? Number(stepParam) : Step.WELCOME;
|
||||||
|
const [step, setStep] = useState<Step>(initialStep);
|
||||||
const [commandCopied, setCommandCopied] = useState<boolean>(false)
|
const [commandCopied, setCommandCopied] = useState<boolean>(false)
|
||||||
|
|
||||||
const command = 'ollama run llama2'
|
const command = 'ollama run llama2'
|
||||||
|
@ -32,7 +32,7 @@ const logger = winston.createLogger({
|
|||||||
format: winston.format.printf(info => info.message),
|
format: winston.format.printf(info => info.message),
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('ready', () => {
|
app.on('ready', async () => {
|
||||||
const gotTheLock = app.requestSingleInstanceLock()
|
const gotTheLock = app.requestSingleInstanceLock()
|
||||||
if (!gotTheLock) {
|
if (!gotTheLock) {
|
||||||
app.exit(0)
|
app.exit(0)
|
||||||
@ -54,10 +54,10 @@ app.on('ready', () => {
|
|||||||
|
|
||||||
app.focus({ steal: true })
|
app.focus({ steal: true })
|
||||||
|
|
||||||
init()
|
await init()
|
||||||
})
|
})
|
||||||
|
|
||||||
function firstRunWindow() {
|
function firstRunWindow(isInstalled: boolean) {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
welcomeWindow = new BrowserWindow({
|
welcomeWindow = new BrowserWindow({
|
||||||
width: 400,
|
width: 400,
|
||||||
@ -75,7 +75,11 @@ function firstRunWindow() {
|
|||||||
|
|
||||||
require('@electron/remote/main').enable(welcomeWindow.webContents)
|
require('@electron/remote/main').enable(welcomeWindow.webContents)
|
||||||
|
|
||||||
welcomeWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY)
|
let url = MAIN_WINDOW_WEBPACK_ENTRY
|
||||||
|
if (isInstalled) {
|
||||||
|
url += '?step=2' // set the window to the finish screen
|
||||||
|
}
|
||||||
|
welcomeWindow.loadURL(url);
|
||||||
welcomeWindow.on('ready-to-show', () => welcomeWindow.show())
|
welcomeWindow.on('ready-to-show', () => welcomeWindow.show())
|
||||||
welcomeWindow.on('closed', () => {
|
welcomeWindow.on('closed', () => {
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
@ -207,7 +211,7 @@ async function checkUpdate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
async function init() {
|
||||||
if (app.isPackaged) {
|
if (app.isPackaged) {
|
||||||
checkUpdate()
|
checkUpdate()
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
@ -217,9 +221,9 @@ function init() {
|
|||||||
|
|
||||||
updateTray()
|
updateTray()
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
const isInstalled = await installed();
|
||||||
if (app.isPackaged) {
|
|
||||||
if (!app.isInApplicationsFolder()) {
|
if (process.platform === 'darwin' && app.isPackaged && !app.isInApplicationsFolder() && !isInstalled) {
|
||||||
const chosen = dialog.showMessageBoxSync({
|
const chosen = dialog.showMessageBoxSync({
|
||||||
type: 'question',
|
type: 'question',
|
||||||
buttons: ['Move to Applications', 'Do Not Move'],
|
buttons: ['Move to Applications', 'Do Not Move'],
|
||||||
@ -249,12 +253,10 @@ function init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
server()
|
server()
|
||||||
|
|
||||||
if (store.get('first-time-run') && installed()) {
|
if (store.get('first-time-run') && isInstalled) {
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
app.dock.hide()
|
app.dock.hide()
|
||||||
}
|
}
|
||||||
@ -265,7 +267,7 @@ function init() {
|
|||||||
|
|
||||||
// This is the first run or the CLI is no longer installed
|
// This is the first run or the CLI is no longer installed
|
||||||
app.setLoginItemSettings({ openAtLogin: true })
|
app.setLoginItemSettings({ openAtLogin: true })
|
||||||
firstRunWindow()
|
firstRunWindow(isInstalled)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quit when all windows are closed, except on macOS. There, it's common
|
// Quit when all windows are closed, except on macOS. There, it's common
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import * as fs from 'fs'
|
import { exec as cbExec, spawn } from 'child_process'
|
||||||
import { exec as cbExec } from 'child_process'
|
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
|
|
||||||
@ -8,8 +7,28 @@ const ollama = app.isPackaged ? path.join(process.resourcesPath, 'ollama') : pat
|
|||||||
const exec = promisify(cbExec)
|
const exec = promisify(cbExec)
|
||||||
const symlinkPath = '/usr/local/bin/ollama'
|
const symlinkPath = '/usr/local/bin/ollama'
|
||||||
|
|
||||||
export function installed() {
|
export async function installed() {
|
||||||
return fs.existsSync(symlinkPath) && fs.readlinkSync(symlinkPath) === ollama
|
const shells = ['/bin/zsh', '/bin/bash', '/usr/local/bin/fish'];
|
||||||
|
const checks = shells.map(shell =>
|
||||||
|
new Promise(resolve => {
|
||||||
|
const proc = spawn(shell, ['-l', '-c', `which ollama`]);
|
||||||
|
|
||||||
|
proc.on('error', () => {
|
||||||
|
resolve(false); // if the shell isn't found, this will resolve false here
|
||||||
|
});
|
||||||
|
|
||||||
|
proc.on('close', code => {
|
||||||
|
if (code === 0) {
|
||||||
|
resolve(true); // ollama found, resolve true immediately
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const results = await Promise.allSettled(checks)
|
||||||
|
return results.some(result => result.status === 'fulfilled' && result.value === true)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function install() {
|
export async function install() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user